Class: Google::Cloud::Bigquery::Argument

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

Overview

Argument

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

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

Instance Method Summary collapse

Constructor Details

#initialize(data_type, kind, mode, name) ⇒ Argument

Creates a new, immutable Argument object.

Parameters:

  • data_type (StandardSql::DataType, String)

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

  • argument_kind (String)

    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.

  • mode (String)

    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.
  • name (String)

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



83
84
85
86
# 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

Instance Method Details

#any_type?Boolean

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

Returns:

  • (Boolean)

    true when ANY_TYPE, false otherwise.



127
128
129
# File 'lib/google/cloud/bigquery/argument.rb', line 127

def any_type?
  @gapi.argument_kind == "ANY_TYPE"
end

#argument_kindString

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.

Returns:

  • (String)

    The upper case kind of argument.



108
109
110
# File 'lib/google/cloud/bigquery/argument.rb', line 108

def argument_kind
  @gapi.argument_kind
end

#data_typeStandardSql::DataType

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

Returns:



93
94
95
# File 'lib/google/cloud/bigquery/argument.rb', line 93

def data_type
  StandardSql::DataType.from_gapi @gapi.data_type
end

#fixed_type?Boolean

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

Returns:

  • (Boolean)

    true when FIXED_TYPE, false otherwise.



117
118
119
120
# 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?Boolean

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

Returns:

  • (Boolean)

    true when IN, false otherwise.



149
150
151
# File 'lib/google/cloud/bigquery/argument.rb', line 149

def in?
  @gapi.mode == "IN"
end

#inout?Boolean

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

Returns:

  • (Boolean)

    true when INOUT, false otherwise.



167
168
169
# File 'lib/google/cloud/bigquery/argument.rb', line 167

def inout?
  @gapi.mode == "INOUT"
end

#modeString

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.

Returns:

  • (String)

    The upper case input/output mode of the argument.



140
141
142
# File 'lib/google/cloud/bigquery/argument.rb', line 140

def mode
  @gapi.mode
end

#nameString

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

Returns:

  • (String)

    The name of the argument.



177
178
179
# File 'lib/google/cloud/bigquery/argument.rb', line 177

def name
  @gapi.name
end

#out?Boolean

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

Returns:

  • (Boolean)

    true when OUT, false otherwise.



158
159
160
# File 'lib/google/cloud/bigquery/argument.rb', line 158

def out?
  @gapi.mode == "OUT"
end