class Google::Cloud::Bigquery::StandardSql::StructType
The fields of a `STRUCT` type. See {DataType#struct_type}. See {Routine} and {Argument}.
@example
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
Public Class Methods
from_gapi(gapi)
click to toggle source
@private New StandardSql::StructType
from a Google::Apis::BigqueryV2::StandardSqlStructType object.
# File lib/google/cloud/bigquery/standard_sql.rb, line 498 def self.from_gapi gapi new.tap do |f| f.instance_variable_set :@gapi, gapi end end
new(**kwargs)
click to toggle source
Creates a new, immutable StandardSql::StructType
object.
@overload initialize(fields)
@param [Array<Field>] fields The fields of the struct. Required.
# File lib/google/cloud/bigquery/standard_sql.rb, line 473 def initialize **kwargs # Convert each field client object to gapi object, if fields given (self.from_gapi does not pass kwargs) kwargs[:fields] = kwargs[:fields]&.map(&:to_gapi) if kwargs[:fields] @gapi = Google::Apis::BigqueryV2::StandardSqlStructType.new(**kwargs) end
Public Instance Methods
fields()
click to toggle source
The fields of the struct.
@return [Array<Field>] A frozen array of fields.
# File lib/google/cloud/bigquery/standard_sql.rb, line 484 def fields Array(@gapi.fields).map do |field_gapi| Field.from_gapi field_gapi end.freeze end
to_gapi()
click to toggle source
@private New Google::Apis::BigqueryV2::StandardSqlStructType object.
# File lib/google/cloud/bigquery/standard_sql.rb, line 492 def to_gapi @gapi end