google_cloud_bigquery/http/routine/
mod.rs

1use std::collections::HashMap;
2
3use crate::http::types::{StandardSqlDataType, StandardSqlField};
4
5pub mod delete;
6pub mod get;
7pub mod insert;
8pub mod list;
9pub mod update;
10
11#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
12#[serde(rename_all = "camelCase")]
13pub struct RoutineReference {
14    /// Required. The ID of the project containing this table.
15    pub project_id: String,
16    /// Required. The ID of the dataset containing this table.
17    pub dataset_id: String,
18    /// Required. The ID of the routine.
19    /// The ID must contain only letters (a-z, A-Z), numbers (0-9), or underscores (_).
20    /// The maximum length is 256 characters.
21    pub routine_id: String,
22}
23
24#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
25#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
26pub enum RoutineType {
27    #[default]
28    RoutineTypeUnspecified,
29    ScalarFunction,
30    Procedure,
31    TableValuedFunction,
32}
33
34#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
35#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
36pub enum Language {
37    #[default]
38    LanguageUnspecified,
39    Sql,
40    Javascript,
41    Python,
42    Java,
43    Scala,
44}
45
46#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
47#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
48pub enum ArgumentKind {
49    #[default]
50    ArgumentKindUnspecified,
51    FixedType,
52    AnyType,
53}
54
55#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
56#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
57pub enum Mode {
58    #[default]
59    ModeUnspecified,
60    In,
61    Out,
62    Inout,
63}
64
65#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
66#[serde(rename_all = "camelCase")]
67pub struct StandardSqlTableType {
68    /// The columns in this table type
69    pub columns: Vec<StandardSqlField>,
70}
71
72/// JavaScript UDF determinism levels.
73/// If all JavaScript UDFs are DETERMINISTIC, the query result is potentially cachable (see below).
74/// If any JavaScript UDF is NOT_DETERMINISTIC, the query result is not cacheable.
75/// Even if a JavaScript UDF is deterministic, many other factors can prevent usage of cached query results.
76/// Example factors include but not limited to: DDL/DML, non-deterministic SQL function calls,
77/// update of referenced tables/views/UDFs or imported JavaScript libraries.
78/// SQL UDFs cannot have determinism specified. Their determinism is automatically determined.
79#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
80#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
81pub enum DeterminismLevel {
82    #[default]
83    DeterminismLevelUnspecified,
84    Deterministic,
85    NotDeterministic,
86}
87
88#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
89#[serde(rename_all = "camelCase")]
90pub struct RemoteFunctionOptions {
91    /// Endpoint of the user-provided remote service,
92    /// e.g. https://us-east1-my_gcf_project.cloudfunctions.net/remote_add
93    pub endpoint: Option<String>,
94    /// Fully qualified name of the user-provided connection object which holds the authentication
95    /// information to send requests to the remote service. Format: "projects/{projectId}/locations/{locationId}/connections/{connectionId}"
96    pub connection: Option<String>,
97    /// User-defined context as a set of key/value pairs, which will be sent as function invocation context together with batched arguments in the requests to the remote service. The total number of bytes of keys and values must be less than 8KB.
98    /// An object containing a list of "key": value pairs.
99    /// Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.
100    pub user_defined_context: Option<HashMap<String, String>>,
101    /// Max number of rows in each batch sent to the remote service.
102    /// If absent or if 0, BigQuery dynamically decides the number of rows in a batch.
103    #[serde(default, deserialize_with = "crate::http::from_str_option")]
104    pub max_batching_rows: Option<i64>,
105}
106
107#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
108#[serde(rename_all = "camelCase")]
109pub struct Argument {
110    /// Optional. The name of this argument. Can be absent for function return argument.
111    pub name: Option<String>,
112    /// Optional. Defaults to FIXED_TYPE.
113    pub argument_kind: Option<ArgumentKind>,
114    /// Optional. Specifies whether the argument is input or output. Can be set for procedures only.
115    pub mode: Option<Mode>,
116    /// Required unless argumentKind = ANY_TYPE.
117    pub data_type: StandardSqlDataType,
118}
119
120#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
121#[serde(rename_all = "camelCase")]
122pub struct SparkOptions {
123    /// Fully qualified name of the user-provided Spark connection object.
124    /// Format: "projects/{projectId}/locations/{locationId}/connections/{connectionId}"
125    pub connection: Option<String>,
126    /// Runtime version.
127    /// If not specified, the default runtime version is used.
128    pub runtime_version: Option<String>,
129    /// Custom container image for the runtime environment.
130    pub container_image: Option<String>,
131    /// Configuration properties as a set of key/value pairs, which will be passed on to the Spark application.
132    /// For more information, see Apache Spark and the procedure option list.
133    /// An object containing a list of "key": value pairs.
134    /// Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.
135    pub properties: Option<HashMap<String, String>>,
136    /// The main file/jar URI of the Spark application.
137    /// Exactly one of the definitionBody field and the mainFileUri field must be set for Python.
138    /// Exactly one of mainClass and mainFileUri field should be set for Java/Scala language type.
139    pub main_file_uri: Option<String>,
140    /// Python files to be placed on the PYTHONPATH for PySpark application.
141    /// Supported file types: .py, .egg, and .zip. For more information about Apache Spark, see Apache Spark.
142    pub py_file_uris: Option<Vec<String>>,
143    /// JARs to include on the driver and executor CLASSPATH.
144    /// For more information about Apache Spark, see Apache Spark.
145    pub jar_uris: Option<Vec<String>>,
146    /// Files to be placed in the working directory of each executor.
147    /// For more information about Apache Spark, see Apache Spark.
148    pub file_uris: Option<Vec<String>>,
149    /// Archive files to be extracted into the working directory of each executor.
150    /// For more information about Apache Spark, see Apache Spark.
151    pub archive_uris: Option<Vec<String>>,
152    /// The fully qualified name of a class in jarUris, for example, com.example.wordcount.
153    /// Exactly one of mainClass and main_jar_uri field should be set for Java/Scala language type.
154    pub main_class: Option<String>,
155}
156
157#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
158#[serde(rename_all = "camelCase")]
159pub struct Routine {
160    /// Output only. A hash of this resource.
161    pub etag: String,
162    /// Required. Reference describing the ID of this routine.
163    pub routine_reference: RoutineReference,
164    /// Required. The type of routine.
165    pub routine_type: RoutineType,
166    /// Output only. The time when this routine was created, in milliseconds since the epoch.
167    #[serde(default, deserialize_with = "crate::http::from_str_option")]
168    pub creation_time: Option<i64>,
169    /// Output only. The time when this routine was last modified, in milliseconds since the epoch.
170    #[serde(default, deserialize_with = "crate::http::from_str_option")]
171    pub last_modified_time: Option<i64>,
172    /// Optional. Defaults to "SQL" if remoteFunctionOptions field is absent, not set otherwise.
173    pub language: Option<Language>,
174    /// Optional.
175    pub arguments: Option<Vec<Argument>>,
176    /// Optional if language = "SQL"; required otherwise. Cannot be set if routineType = "TABLE_VALUED_FUNCTION".
177    /// If absent, the return type is inferred from definitionBody at query time in each query that references this routine. If present,
178    /// then the evaluated result will be cast to the specified returned type at query time.
179    /// For example, for the functions created with the following statements:
180    /// CREATE FUNCTION Add(x FLOAT64, y FLOAT64) RETURNS FLOAT64 AS (x + y);
181    /// CREATE FUNCTION Increment(x FLOAT64) AS (Add(x, 1));
182    /// CREATE FUNCTION Decrement(x FLOAT64) RETURNS FLOAT64 AS (Add(x, -1));
183    /// The returnType is {typeKind: "FLOAT64"} for Add and Decrement, and is absent for Increment (inferred as FLOAT64 at query time).
184    /// Suppose the function Add is replaced by CREATE OR REPLACE FUNCTION Add(x INT64, y INT64) AS (x + y);
185    /// Then the inferred return type of Increment is automatically changed to INT64 at query time, while the return type of Decrement remains FLOAT64.
186    pub return_type: Option<StandardSqlDataType>,
187    /// Optional. Can be set only if routineType = "TABLE_VALUED_FUNCTION".
188    /// If absent, the return table type is inferred from definitionBody at query time in each query that references this routine.
189    /// If present, then the columns in the evaluated table result will be cast to match the column types specified in return table type, at query time.
190    pub return_table_type: Option<StandardSqlTableType>,
191    /// Optional. If language = "JAVASCRIPT", this field stores the path of the imported JAVASCRIPT libraries.
192    pub imported_libraries: Option<Vec<String>>,
193    /// Required. The body of the routine.
194    /// For functions, this is the expression in the AS clause.
195    /// If language=SQL, it is the substring inside (but excluding) the parentheses.
196    /// For example, for the function created with the following statement:
197    /// CREATE FUNCTION JoinLines(x string, y string) as (concat(x, "\n", y))
198    /// The definitionBody is concat(x, "\n", y) (\n is not replaced with linebreak).
199    /// If language=JAVASCRIPT, it is the evaluated string in the AS clause.
200    /// For example, for the function created with the following statement:
201    /// CREATE FUNCTION f() RETURNS STRING LANGUAGE js AS 'return "\n";\n'
202    /// The definitionBody is return "\n";\n
203    /// Note that both \n are replaced with linebreaks.
204    pub definition_body: String,
205    /// Optional. The description of the routine, if defined.
206    pub description: Option<String>,
207    /// Optional. The determinism level of the JavaScript UDF, if defined.
208    pub determinism_level: Option<DeterminismLevel>,
209    /// Optional. Remote function specific options.
210    pub remote_function_options: Option<RemoteFunctionOptions>,
211    /// Optional. Spark specific options.
212    pub spark_options: Option<SparkOptions>,
213}