class Google::Cloud::Bigquery::Argument

# Argument

Input/output argument of a function or a stored procedure. See {Routine}.

@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 Argument from a Google API Client object.

# File lib/google/cloud/bigquery/argument.rb, line 189
def self.from_gapi gapi
  new.tap do |a|
    a.instance_variable_set :@gapi, gapi
  end
end
new(**kwargs) click to toggle source

Creates a new, immutable Argument object.

@overload initialize(data_type, kind, mode, name)

@param [StandardSql::DataType, String] data_type The data type of the argument. Required unless
  {#argument_kind} is `ANY_TYPE`.
@param [String] argument_kind The kind of argument. Optional. Defaults to `FIXED_TYPE`.

  * `FIXED_TYPE` - The argument is a variable with fully specified type, which can be a struct or an array,
    but not a table.
  * `ANY_TYPE` - The argument is any type, including struct or array, but not a table.

  To be added: `FIXED_TABLE`, `ANY_TABLE`.
@param [String] mode Specifies whether the argument is input or output. Optional. Can be set for procedures
  only.

  * IN - The argument is input-only.
  * OUT - The argument is output-only.
  * INOUT - The argument is both an input and an output.
@param [String] name The name of the argument. Optional. Can be absent for a function return argument.
# File lib/google/cloud/bigquery/argument.rb, line 83
def initialize **kwargs
  kwargs[:data_type] = StandardSql::DataType.gapi_from_string_or_data_type kwargs[:data_type]
  @gapi = Google::Apis::BigqueryV2::Argument.new(**kwargs)
end

Public Instance Methods

any_type?() click to toggle source

Checks if the value of {#argument_kind} is `ANY_TYPE`. The default is `false`.

@return [Boolean] `true` when `ANY_TYPE`, `false` otherwise.

# File lib/google/cloud/bigquery/argument.rb, line 127
def any_type?
  @gapi.argument_kind == "ANY_TYPE"
end
argument_kind() click to toggle source

The kind of argument. Optional. Defaults to `FIXED_TYPE`.

  • `FIXED_TYPE` - The argument is a variable with fully specified type, which can be a struct or an array, but not a table.

  • `ANY_TYPE` - The argument is any type, including struct or array, but not a table.

To be added: `FIXED_TABLE`, `ANY_TABLE`.

@return [String] The upper case kind of argument.

# File lib/google/cloud/bigquery/argument.rb, line 108
def argument_kind
  @gapi.argument_kind
end
data_type() click to toggle source

The data type of the argument. Required unless {#argument_kind} is `ANY_TYPE`.

@return [StandardSql::DataType] The data type.

# File lib/google/cloud/bigquery/argument.rb, line 93
def data_type
  StandardSql::DataType.from_gapi @gapi.data_type
end
fixed_type?() click to toggle source

Checks if the value of {#argument_kind} is `FIXED_TYPE`. The default is `true`.

@return [Boolean] `true` when `FIXED_TYPE`, `false` otherwise.

# File lib/google/cloud/bigquery/argument.rb, line 117
def fixed_type?
  return true if @gapi.argument_kind.nil?
  @gapi.argument_kind == "FIXED_TYPE"
end
in?() click to toggle source

Checks if the value of {#mode} is `IN`. Can be set for procedures only. The default is `false`.

@return [Boolean] `true` when `IN`, `false` otherwise.

# File lib/google/cloud/bigquery/argument.rb, line 149
def in?
  @gapi.mode == "IN"
end
inout?() click to toggle source

Checks if the value of {#mode} is `INOUT`. Can be set for procedures only. The default is `false`.

@return [Boolean] `true` when `INOUT`, `false` otherwise.

# File lib/google/cloud/bigquery/argument.rb, line 167
def inout?
  @gapi.mode == "INOUT"
end
mode() click to toggle source

Specifies whether the argument is input or output. Optional. Can be set for procedures only.

  • IN - The argument is input-only.

  • OUT - The argument is output-only.

  • INOUT - The argument is both an input and an output.

@return [String] The upper case input/output mode of the argument.

# File lib/google/cloud/bigquery/argument.rb, line 140
def mode
  @gapi.mode
end
name() click to toggle source

The name of the argument. Optional. Can be absent for a function return argument.

@return [String] The name of the argument.

# File lib/google/cloud/bigquery/argument.rb, line 177
def name
  @gapi.name
end
out?() click to toggle source

Checks if the value of {#mode} is `OUT`. Can be set for procedures only. The default is `false`.

@return [Boolean] `true` when `OUT`, `false` otherwise.

# File lib/google/cloud/bigquery/argument.rb, line 158
def out?
  @gapi.mode == "OUT"
end
to_gapi() click to toggle source

@private

# File lib/google/cloud/bigquery/argument.rb, line 183
def to_gapi
  @gapi
end