require"google/cloud/bigquery"bigquery=Google::Cloud::Bigquery.newdataset=bigquery.dataset"my_dataset"routine=dataset.create_routine"my_routine"do|r|r.routine_type="SCALAR_FUNCTION"r.language=:SQLr.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
Methods
#initialize
definitialize(name,type)->Field
Creates a new, immutable StandardSql::Field object.
Overloads
definitialize(name,type)->Field
Creates a new, immutable StandardSql::Field object.
Parameters
name (String) — The name of the field. Optional. Can be absent for struct fields.
type (StandardSql::DataType, String) — 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).
The name of the field. Optional. Can be absent for struct fields.
Returns
(String, nil)
#type
deftype()->DataType,nil
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).
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[],[],null,["# BigQuery API - Class Google::Cloud::Bigquery::StandardSql::Field (v1.55.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.55.0 (latest)](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.54.0](/ruby/docs/reference/google-cloud-bigquery/1.54.0/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.53.0](/ruby/docs/reference/google-cloud-bigquery/1.53.0/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.52.1](/ruby/docs/reference/google-cloud-bigquery/1.52.1/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.51.1](/ruby/docs/reference/google-cloud-bigquery/1.51.1/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.50.0](/ruby/docs/reference/google-cloud-bigquery/1.50.0/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.49.1](/ruby/docs/reference/google-cloud-bigquery/1.49.1/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.48.1](/ruby/docs/reference/google-cloud-bigquery/1.48.1/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.47.0](/ruby/docs/reference/google-cloud-bigquery/1.47.0/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.46.1](/ruby/docs/reference/google-cloud-bigquery/1.46.1/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.45.0](/ruby/docs/reference/google-cloud-bigquery/1.45.0/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.44.2](/ruby/docs/reference/google-cloud-bigquery/1.44.2/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.43.1](/ruby/docs/reference/google-cloud-bigquery/1.43.1/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.42.0](/ruby/docs/reference/google-cloud-bigquery/1.42.0/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.41.0](/ruby/docs/reference/google-cloud-bigquery/1.41.0/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.40.0](/ruby/docs/reference/google-cloud-bigquery/1.40.0/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.39.0](/ruby/docs/reference/google-cloud-bigquery/1.39.0/Google-Cloud-Bigquery-StandardSql-Field)\n- [1.38.1](/ruby/docs/reference/google-cloud-bigquery/1.38.1/Google-Cloud-Bigquery-StandardSql-Field) \nReference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::StandardSql::Field.\n\nA field or a column. See [Routine](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-Routine \"Google::Cloud::Bigquery::Routine (class)\") and [Argument](/ruby/docs/reference/google-cloud-bigquery/latest/Google-Cloud-Bigquery-Argument \"Google::Cloud::Bigquery::Argument (class)\"). \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/bigquery\"\n\nbigquery = Google::Cloud::Bigquery.new\ndataset = bigquery.dataset \"my_dataset\"\nroutine = dataset.create_routine \"my_routine\" do |r|\n r.routine_type = \"SCALAR_FUNCTION\"\n r.language = :SQL\n r.body = \"(SELECT SUM(IF(elem.name = \\\"foo\\\",elem.val,null)) FROM UNNEST(arr) AS elem)\"\n r.arguments = [\n Google::Cloud::Bigquery::Argument.new(\n name: \"arr\",\n argument_kind: \"FIXED_TYPE\",\n data_type: Google::Cloud::Bigquery::StandardSql::DataType.new(\n type_kind: \"ARRAY\",\n array_element_type: Google::Cloud::Bigquery::StandardSql::DataType.new(\n type_kind: \"STRUCT\",\n struct_type: Google::Cloud::Bigquery::StandardSql::StructType.new(\n fields: [\n Google::Cloud::Bigquery::StandardSql::Field.new(\n name: \"name\",\n type: Google::Cloud::Bigquery::StandardSql::DataType.new(type_kind: \"STRING\")\n ),\n Google::Cloud::Bigquery::StandardSql::Field.new(\n name: \"val\",\n type: Google::Cloud::Bigquery::StandardSql::DataType.new(type_kind: \"INT64\")\n )\n ]\n )\n )\n )\n )\n ]\nend\n```\n\nMethods\n-------\n\n### #initialize\n\n def initialize(name, type) -\u003e Field\n\nCreates a new, immutable StandardSql::Field object. \n**Overloads** \n\n def initialize(name, type) -\u003e Field\n\nCreates a new, immutable StandardSql::Field object. \n**Parameters**\n\n- **name** (String) --- The name of the field. Optional. Can be absent for struct fields.\n- **type** ([StandardSql::DataType](./Google-Cloud-Bigquery-StandardSql-DataType), String) --- 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). \n**Returns**\n\n- ([Field](./Google-Cloud-Bigquery-StandardSql-Field)) --- a new instance of Field\n\n### #name\n\n def name() -\u003e String, nil\n\nThe name of the field. Optional. Can be absent for struct fields. \n**Returns**\n\n- (String, nil)\n\n### #type\n\n def type() -\u003e DataType, nil\n\nThe type of the field. Optional. Absent if not explicitly specified (e.g., `CREATE FUNCTION` statement can\nomit the return type; in this case the output parameter does not have this \"type\" field). \n**Returns**\n\n- ([DataType](./Google-Cloud-Bigquery-StandardSql-DataType), nil) --- The type of the field."]]