Class: Google::Cloud::Bigquery::StandardSql::DataType

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/bigquery/standard_sql.rb

Overview

The type of a variable, e.g., a function argument. See Routine and Argument.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
routine = dataset.create_routine "my_routine" do |r|
  r.routine_type = "SCALAR_FUNCTION"
  r.language = :SQL
  r.body = "(SELECT SUM(IF(elem.name = \"foo\",elem.val,null)) FROM UNNEST(arr) AS elem)"
  r.arguments = [
    Google::Cloud::Bigquery::Argument.new(
      name: "arr",
      argument_kind: "FIXED_TYPE",
      data_type: Google::Cloud::Bigquery::StandardSql::DataType.new(
        type_kind: "ARRAY",
        array_element_type: Google::Cloud::Bigquery::StandardSql::DataType.new(
          type_kind: "STRUCT",
          struct_type: Google::Cloud::Bigquery::StandardSql::StructType.new(
            fields: [
              Google::Cloud::Bigquery::StandardSql::Field.new(
                name: "name",
                type: Google::Cloud::Bigquery::StandardSql::DataType.new(type_kind: "STRING")
              ),
              Google::Cloud::Bigquery::StandardSql::Field.new(
                name: "val",
                type: Google::Cloud::Bigquery::StandardSql::DataType.new(type_kind: "INT64")
              )
            ]
          )
        )
      )
    )
  ]
end

See Also:

Helpers collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_kind, array_element_type, struct_type) ⇒ DataType

Creates a new, immutable StandardSql::DataType object.

Parameters:



201
202
203
204
205
206
207
208
209
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 201

def initialize **kwargs
  # Convert client object kwargs to a gapi object
  if kwargs[:array_element_type]
    kwargs[:array_element_type] = self.class.gapi_from_string_or_data_type kwargs[:array_element_type]
  end
  kwargs[:struct_type] = kwargs[:struct_type].to_gapi if kwargs[:struct_type]

  @gapi = Google::Apis::BigqueryV2::StandardSqlDataType.new(**kwargs)
end

Instance Method Details

#array?Boolean

Checks if the #type_kind of the field is ARRAY.

Returns:

  • (Boolean)

    true when ARRAY, false otherwise.



371
372
373
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 371

def array?
  type_kind == "ARRAY".freeze
end

#array_element_typeDataType?

The type of the array's elements, if #type_kind is ARRAY. See #array?. Optional.

Returns:



228
229
230
231
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 228

def array_element_type
  return if @gapi.array_element_type.nil?
  DataType.from_gapi @gapi.array_element_type
end

#boolean?Boolean

Checks if the #type_kind of the field is BOOL.

Returns:

  • (Boolean)

    true when BOOL, false otherwise.



283
284
285
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 283

def boolean?
  type_kind == "BOOL".freeze
end

#bytes?Boolean

Checks if the #type_kind of the field is BYTES.

Returns:

  • (Boolean)

    true when BYTES, false otherwise.



305
306
307
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 305

def bytes?
  type_kind == "BYTES".freeze
end

#date?Boolean

Checks if the #type_kind of the field is DATE.

Returns:

  • (Boolean)

    true when DATE, false otherwise.



316
317
318
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 316

def date?
  type_kind == "DATE".freeze
end

#datetime?Boolean

Checks if the #type_kind of the field is DATETIME.

Returns:

  • (Boolean)

    true when DATETIME, false otherwise.



327
328
329
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 327

def datetime?
  type_kind == "DATETIME".freeze
end

#float?Boolean

Checks if the #type_kind of the field is FLOAT64.

Returns:

  • (Boolean)

    true when FLOAT64, false otherwise.



261
262
263
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 261

def float?
  type_kind == "FLOAT64".freeze
end

#geography?Boolean

Checks if the #type_kind of the field is GEOGRAPHY.

Returns:

  • (Boolean)

    true when GEOGRAPHY, false otherwise.



338
339
340
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 338

def geography?
  type_kind == "GEOGRAPHY".freeze
end

#int?Boolean

Checks if the #type_kind of the field is INT64.

Returns:

  • (Boolean)

    true when INT64, false otherwise.



250
251
252
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 250

def int?
  type_kind == "INT64".freeze
end

#numeric?Boolean

Checks if the #type_kind of the field is NUMERIC.

Returns:

  • (Boolean)

    true when NUMERIC, false otherwise.



272
273
274
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 272

def numeric?
  type_kind == "NUMERIC".freeze
end

#string?Boolean

Checks if the #type_kind of the field is STRING.

Returns:

  • (Boolean)

    true when STRING, false otherwise.



294
295
296
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 294

def string?
  type_kind == "STRING".freeze
end

#struct?Boolean

Checks if the #type_kind of the field is STRUCT.

Returns:

  • (Boolean)

    true when STRUCT, false otherwise.



382
383
384
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 382

def struct?
  type_kind == "STRUCT".freeze
end

#struct_typeStructType?

The fields of the struct, in order, if #type_kind is STRUCT. See #struct?. Optional.

Returns:



238
239
240
241
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 238

def struct_type
  return if @gapi.struct_type.nil?
  StructType.from_gapi @gapi.struct_type
end

#time?Boolean

Checks if the #type_kind of the field is TIME.

Returns:

  • (Boolean)

    true when TIME, false otherwise.



349
350
351
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 349

def time?
  type_kind == "TIME".freeze
end

#timestamp?Boolean

Checks if the #type_kind of the field is TIMESTAMP.

Returns:

  • (Boolean)

    true when TIMESTAMP, false otherwise.



360
361
362
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 360

def timestamp?
  type_kind == "TIMESTAMP".freeze
end

#type_kindString

The top level type of this field. Required. Can be any standard SQL data type (e.g., INT64, DATE, ARRAY).

Returns:

  • (String)

    The upper case type.

See Also:



219
220
221
# File 'lib/google/cloud/bigquery/standard_sql.rb', line 219

def type_kind
  @gapi.type_kind
end