Class: Google::Cloud::Bigquery::Routine::Updater

Inherits:
Google::Cloud::Bigquery::Routine show all
Defined in:
lib/google/cloud/bigquery/routine.rb

Overview

Yielded to a block to accumulate changes. See Dataset#create_routine and #update.

Examples:

Creating a new routine:

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.arguments = [
    Google::Cloud::Bigquery::Argument.new(name: "x", data_type: "INT64")
  ]
  r.body = "x * 3"
  r.description = "My routine description"
end

puts routine.routine_id

Updating an existing routine:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
routine = dataset.routine "my_routine"

routine.update do |r|
  r.body = "x * 4"
  r.description = "My new routine description"
end

Lifecycle collapse

Attributes collapse

Methods inherited from Google::Cloud::Bigquery::Routine

#arguments, #body, #created_at, #data_governance_type, #dataset_id, #description, #determinism_level, #determinism_level_deterministic?, #determinism_level_not_deterministic?, #etag, #exists?, #imported_libraries, #javascript?, #language, #modified_at, #procedure?, #project_id, #reference?, #remote_function_options, #resource?, #resource_full?, #resource_partial?, #return_type, #routine_id, #routine_type, #scalar_function?, #sql?

Instance Method Details

#arguments=(new_arguments) ⇒ Object

Updates the input/output arguments of the routine. Optional.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
routine = dataset.routine "my_routine"

routine.arguments = [
  Google::Cloud::Bigquery::Argument.new(name: "x", data_type: "INT64")
]

Parameters:

  • new_arguments (Array<Argument>)

    The new arguments.



1157
1158
1159
# File 'lib/google/cloud/bigquery/routine.rb', line 1157

def arguments= new_arguments
  @gapi.arguments = new_arguments.map(&:to_gapi)
end

#body=(new_body) ⇒ Object

Updates the body of the routine. Required.

For functions (Google::Cloud::Bigquery::Routine#scalar_function?), this is the expression in the AS clause.

When the routine is a SQL function (Google::Cloud::Bigquery::Routine#sql?), it is the substring inside (but excluding) the parentheses. For example, for the function created with the following statement:

CREATE FUNCTION JoinLines(x string, y string) as (concat(x, "\n", y))

The definition_body is concat(x, "\n", y) (\n is not replaced with linebreak).

When the routine is a JavaScript function (Google::Cloud::Bigquery::Routine#javascript?), it is the evaluated string in the AS clause. For example, for the function created with the following statement:

CREATE FUNCTION f() RETURNS STRING LANGUAGE js AS 'return "\n";\n'

The definition_body is

"return \"\n\";\n"`

Note that both \n are replaced with linebreaks.

Parameters:

  • new_body (String)

    The new body of the routine.



1250
1251
1252
# File 'lib/google/cloud/bigquery/routine.rb', line 1250

def body= new_body
  @gapi.definition_body = new_body
end

#data_governance_type=(new_data_governance_type) ⇒ Object

Updates the data governance type of the routine. Optional.

If set to DATA_MASKING, the function is validated and made available as a masking function. For more information, see Create custom masking routines.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
routine = dataset.routine "my_routine"

routine.data_governance_type = "DATA_MASKING"

Parameters:

  • new_data_governance_type (String, nil)

    The new data governance type. nil to unset.



1324
1325
1326
# File 'lib/google/cloud/bigquery/routine.rb', line 1324

def data_governance_type= new_data_governance_type
  @gapi.data_governance_type = new_data_governance_type
end

#deleteObject



1358
1359
1360
# File 'lib/google/cloud/bigquery/routine.rb', line 1358

def delete
  raise "not implemented in #{self.class}"
end

#description=(new_description) ⇒ Object

Updates the description of the routine. Optional. [Experimental]

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
routine = dataset.routine "my_routine"

routine.description #=> "My routine description"
routine.update do |r|
  r.description = "My updated routine description"
end

Parameters:

  • new_description (String)

    The new routine description.



1271
1272
1273
# File 'lib/google/cloud/bigquery/routine.rb', line 1271

def description= new_description
  @gapi.description = new_description
end

#determinism_level=(new_determinism_level) ⇒ Object

Updates the JavaScript UDF determinism level. Optional.

  • DETERMINISTIC - Deterministic indicates that two calls with the same input to a UDF yield the same output. If all JavaScript UDFs are DETERMINISTIC, the query result is potentially cachable.
  • NOT_DETERMINISTIC - Not deterministic indicates that the output of the UDF is not guaranteed to yield the same output each time for a given set of inputs. If any JavaScript UDF is NOT_DETERMINISTIC, the query result is not cacheable.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
routine = dataset.routine "my_routine"

routine.determinism_level #=> "NOT_DETERMINISTIC"
routine.update do |r|
  r.determinism_level = "DETERMINISTIC"
end

Parameters:

  • new_determinism_level (String, nil)

    The new routine determinism level in upper case.



1300
1301
1302
# File 'lib/google/cloud/bigquery/routine.rb', line 1300

def determinism_level= new_determinism_level
  @gapi.determinism_level = new_determinism_level
end

#imported_libraries=(new_imported_libraries) ⇒ Object

Updates the list of the Google Cloud Storage URIs of imported JavaScript libraries. Optional. Only used if Google::Cloud::Bigquery::Routine#language is JAVASCRIPT (Google::Cloud::Bigquery::Routine#javascript?).

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
routine = dataset.routine "my_routine"

routine.update do |r|
  r.imported_libraries = [
    "gs://cloud-samples-data/bigquery/udfs/max-value.js"
  ]
end

Parameters:

  • new_imported_libraries (Array<String>, nil)

    An array of Google Cloud Storage URIs, e.g. ["gs://cloud-samples-data/bigquery/udfs/max-value.js"].



1221
1222
1223
# File 'lib/google/cloud/bigquery/routine.rb', line 1221

def imported_libraries= new_imported_libraries
  @gapi.imported_libraries = new_imported_libraries
end

#language=(new_language) ⇒ Object

Updates the programming language of routine. Optional. Defaults to "SQL".

  • SQL - SQL language.
  • JAVASCRIPT - JavaScript language.

Parameters:

  • new_language (String)

    The new language in upper case.



1137
1138
1139
# File 'lib/google/cloud/bigquery/routine.rb', line 1137

def language= new_language
  @gapi.language = new_language
end

#reload!Object Also known as: refresh!



1362
1363
1364
# File 'lib/google/cloud/bigquery/routine.rb', line 1362

def reload!
  raise "not implemented in #{self.class}"
end

#remote_function_options=(new_remote_function_options) ⇒ Object

Updates the remote function specific options. Optional.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
routine = dataset.routine "my_routine"

routine.update do |r|
  rfo = Google::Cloud::Bigquery::RemoteFunctionOptions.new
  rfo.endpoint = "https://us-east1-my_gcf_project.cloudfunctions.net/remote_add"
  rfo.connection = "projects/my-project/locations/us-east1/connections/my-connection"
  r.remote_function_options = rfo
end

Parameters:



1350
1351
1352
# File 'lib/google/cloud/bigquery/routine.rb', line 1350

def remote_function_options= new_remote_function_options
  @gapi.remote_function_options = new_remote_function_options.to_gapi
end

#return_type=(new_return_type) ⇒ Object

Updates the return type of the routine. Optional if the routine is a SQL function (Google::Cloud::Bigquery::Routine#sql?); required otherwise.

If absent, the return type is inferred from Google::Cloud::Bigquery::Routine#body at query time in each query that references this routine. If present, then the evaluated result will be cast to the specified returned type at query time.

For example, for the functions created with the following statements:

  • CREATE FUNCTION Add(x FLOAT64, y FLOAT64) RETURNS FLOAT64 AS (x + y);
  • CREATE FUNCTION Increment(x FLOAT64) AS (Add(x, 1));
  • CREATE FUNCTION Decrement(x FLOAT64) RETURNS FLOAT64 AS (Add(x, -1));

The returnType is {typeKind: "FLOAT64"} for Add and Decrement, and is absent for Increment (inferred as FLOAT64 at query time).

Suppose the function Add is replaced by CREATE OR REPLACE FUNCTION Add(x INT64, y INT64) AS (x + y);

Then the inferred return type of Increment is automatically changed to INT64 at query time, while the return type of Decrement remains FLOAT64.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.dataset "my_dataset"
routine = dataset.routine "my_routine"

routine.return_type.type_kind #=> "INT64"
routine.update do |r|
  r.return_type = "STRING"
end

Parameters:



1197
1198
1199
# File 'lib/google/cloud/bigquery/routine.rb', line 1197

def return_type= new_return_type
  @gapi.return_type = StandardSql::DataType.gapi_from_string_or_data_type new_return_type
end

#routine_type=(new_routine_type) ⇒ Object

Updates the type of routine. Required.

  • SCALAR_FUNCTION - Non-builtin permanent scalar function.
  • PROCEDURE - Stored procedure.

Parameters:

  • new_routine_type (String)

    The new type of the routine.



1125
1126
1127
# File 'lib/google/cloud/bigquery/routine.rb', line 1125

def routine_type= new_routine_type
  @gapi.routine_type = new_routine_type
end

#updateObject



1354
1355
1356
# File 'lib/google/cloud/bigquery/routine.rb', line 1354

def update
  raise "not implemented in #{self.class}"
end