class Google::Cloud::Bigquery::StandardSql::Field

A field or a column. 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::Field from a Google::Apis::BigqueryV2::StandardSqlField object.

# File lib/google/cloud/bigquery/standard_sql.rb, line 141
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::Field object.

@overload initialize(name, type)

@param [String] name The name of the field. Optional. Can be absent for struct fields.
@param [StandardSql::DataType, String] type The type of the field. Optional. Absent if not explicitly
  specified (e.g., `CREATE FUNCTION` statement can omit the return type; in this case the output parameter
  does not have this "type" field).
# File lib/google/cloud/bigquery/standard_sql.rb, line 107
def initialize **kwargs
  # Convert client object kwargs to a gapi object
  kwargs[:type] = DataType.gapi_from_string_or_data_type kwargs[:type] if kwargs[:type]
  @gapi = Google::Apis::BigqueryV2::StandardSqlField.new(**kwargs)
end

Public Instance Methods

name() click to toggle source

The name of the field. Optional. Can be absent for struct fields.

@return [String, nil]

# File lib/google/cloud/bigquery/standard_sql.rb, line 118
def name
  return if @gapi.name == "".freeze
  @gapi.name
end
to_gapi() click to toggle source

@private New Google::Apis::BigqueryV2::StandardSqlField object.

# File lib/google/cloud/bigquery/standard_sql.rb, line 135
def to_gapi
  @gapi
end
type() click to toggle source

The type of the field. Optional. Absent if not explicitly specified (e.g., `CREATE FUNCTION` statement can omit the return type; in this case the output parameter does not have this “type” field).

@return [DataType, nil] The type of the field.

# File lib/google/cloud/bigquery/standard_sql.rb, line 129
def type
  DataType.from_gapi @gapi.type if @gapi.type
end