elasticsearch 9.0.2__py3-none-any.whl → 9.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. elasticsearch/_async/client/__init__.py +59 -202
  2. elasticsearch/_async/client/cat.py +1011 -59
  3. elasticsearch/_async/client/cluster.py +14 -4
  4. elasticsearch/_async/client/eql.py +10 -2
  5. elasticsearch/_async/client/esql.py +33 -10
  6. elasticsearch/_async/client/indices.py +88 -44
  7. elasticsearch/_async/client/inference.py +108 -3
  8. elasticsearch/_async/client/ingest.py +0 -7
  9. elasticsearch/_async/client/license.py +4 -4
  10. elasticsearch/_async/client/ml.py +6 -17
  11. elasticsearch/_async/client/monitoring.py +1 -1
  12. elasticsearch/_async/client/rollup.py +1 -22
  13. elasticsearch/_async/client/security.py +11 -17
  14. elasticsearch/_async/client/snapshot.py +6 -0
  15. elasticsearch/_async/client/sql.py +1 -1
  16. elasticsearch/_async/client/synonyms.py +1 -0
  17. elasticsearch/_async/client/transform.py +60 -0
  18. elasticsearch/_async/client/watcher.py +4 -2
  19. elasticsearch/_sync/client/__init__.py +59 -202
  20. elasticsearch/_sync/client/cat.py +1011 -59
  21. elasticsearch/_sync/client/cluster.py +14 -4
  22. elasticsearch/_sync/client/eql.py +10 -2
  23. elasticsearch/_sync/client/esql.py +33 -10
  24. elasticsearch/_sync/client/indices.py +88 -44
  25. elasticsearch/_sync/client/inference.py +108 -3
  26. elasticsearch/_sync/client/ingest.py +0 -7
  27. elasticsearch/_sync/client/license.py +4 -4
  28. elasticsearch/_sync/client/ml.py +6 -17
  29. elasticsearch/_sync/client/monitoring.py +1 -1
  30. elasticsearch/_sync/client/rollup.py +1 -22
  31. elasticsearch/_sync/client/security.py +11 -17
  32. elasticsearch/_sync/client/snapshot.py +6 -0
  33. elasticsearch/_sync/client/sql.py +1 -1
  34. elasticsearch/_sync/client/synonyms.py +1 -0
  35. elasticsearch/_sync/client/transform.py +60 -0
  36. elasticsearch/_sync/client/watcher.py +4 -2
  37. elasticsearch/_version.py +1 -1
  38. elasticsearch/compat.py +5 -0
  39. elasticsearch/dsl/__init__.py +2 -1
  40. elasticsearch/dsl/_async/document.py +84 -0
  41. elasticsearch/dsl/_sync/document.py +84 -0
  42. elasticsearch/dsl/document_base.py +219 -16
  43. elasticsearch/dsl/field.py +245 -57
  44. elasticsearch/dsl/query.py +7 -4
  45. elasticsearch/dsl/response/aggs.py +1 -1
  46. elasticsearch/dsl/types.py +125 -88
  47. elasticsearch/dsl/utils.py +2 -2
  48. elasticsearch/{dsl/_sync/_sync_check → esql}/__init__.py +3 -0
  49. elasticsearch/esql/esql.py +1156 -0
  50. elasticsearch/esql/functions.py +1750 -0
  51. {elasticsearch-9.0.2.dist-info → elasticsearch-9.0.4.dist-info}/METADATA +1 -3
  52. {elasticsearch-9.0.2.dist-info → elasticsearch-9.0.4.dist-info}/RECORD +55 -59
  53. elasticsearch/dsl/_sync/_sync_check/document.py +0 -514
  54. elasticsearch/dsl/_sync/_sync_check/faceted_search.py +0 -50
  55. elasticsearch/dsl/_sync/_sync_check/index.py +0 -597
  56. elasticsearch/dsl/_sync/_sync_check/mapping.py +0 -49
  57. elasticsearch/dsl/_sync/_sync_check/search.py +0 -230
  58. elasticsearch/dsl/_sync/_sync_check/update_by_query.py +0 -45
  59. {elasticsearch-9.0.2.dist-info → elasticsearch-9.0.4.dist-info}/WHEEL +0 -0
  60. {elasticsearch-9.0.2.dist-info → elasticsearch-9.0.4.dist-info}/licenses/LICENSE +0 -0
  61. {elasticsearch-9.0.2.dist-info → elasticsearch-9.0.4.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,1750 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ import json
19
+ from typing import Any
20
+
21
+ from elasticsearch.dsl.document_base import InstrumentedExpression
22
+ from elasticsearch.esql.esql import ESQLBase, ExpressionType
23
+
24
+
25
+ def _render(v: Any) -> str:
26
+ return (
27
+ json.dumps(v)
28
+ if not isinstance(v, InstrumentedExpression)
29
+ else ESQLBase._format_expr(v)
30
+ )
31
+
32
+
33
+ def abs(number: ExpressionType) -> InstrumentedExpression:
34
+ """Returns the absolute value.
35
+
36
+ :param number: Numeric expression. If `null`, the function returns `null`.
37
+ """
38
+ return InstrumentedExpression(f"ABS({_render(number)})")
39
+
40
+
41
+ def acos(number: ExpressionType) -> InstrumentedExpression:
42
+ """Returns the arccosine of `n` as an angle, expressed in radians.
43
+
44
+ :param number: Number between -1 and 1. If `null`, the function returns `null`.
45
+ """
46
+ return InstrumentedExpression(f"ACOS({_render(number)})")
47
+
48
+
49
+ def asin(number: ExpressionType) -> InstrumentedExpression:
50
+ """Returns the arcsine of the input numeric expression as an angle,
51
+ expressed in radians.
52
+
53
+ :param number: Number between -1 and 1. If `null`, the function returns `null`.
54
+ """
55
+ return InstrumentedExpression(f"ASIN({_render(number)})")
56
+
57
+
58
+ def atan(number: ExpressionType) -> InstrumentedExpression:
59
+ """Returns the arctangent of the input numeric expression as an angle,
60
+ expressed in radians.
61
+
62
+ :param number: Numeric expression. If `null`, the function returns `null`.
63
+ """
64
+ return InstrumentedExpression(f"ATAN({_render(number)})")
65
+
66
+
67
+ def atan2(
68
+ y_coordinate: ExpressionType, x_coordinate: ExpressionType
69
+ ) -> InstrumentedExpression:
70
+ """The angle between the positive x-axis and the ray from the origin to the
71
+ point (x , y) in the Cartesian plane, expressed in radians.
72
+
73
+ :param y_coordinate: y coordinate. If `null`, the function returns `null`.
74
+ :param x_coordinate: x coordinate. If `null`, the function returns `null`.
75
+ """
76
+ return InstrumentedExpression(
77
+ f"ATAN2({_render(y_coordinate)}, {_render(x_coordinate)})"
78
+ )
79
+
80
+
81
+ def avg(number: ExpressionType) -> InstrumentedExpression:
82
+ """The average of a numeric field.
83
+
84
+ :param number: Expression that outputs values to average.
85
+ """
86
+ return InstrumentedExpression(f"AVG({_render(number)})")
87
+
88
+
89
+ def avg_over_time(number: ExpressionType) -> InstrumentedExpression:
90
+ """The average over time of a numeric field.
91
+
92
+ :param number: Expression that outputs values to average.
93
+ """
94
+ return InstrumentedExpression(f"AVG_OVER_TIME({_render(number)})")
95
+
96
+
97
+ def bit_length(string: ExpressionType) -> InstrumentedExpression:
98
+ """Returns the bit length of a string.
99
+
100
+ :param string: String expression. If `null`, the function returns `null`.
101
+ """
102
+ return InstrumentedExpression(f"BIT_LENGTH({_render(string)})")
103
+
104
+
105
+ def bucket(
106
+ field: ExpressionType,
107
+ buckets: ExpressionType,
108
+ from_: ExpressionType,
109
+ to: ExpressionType,
110
+ ) -> InstrumentedExpression:
111
+ """Creates groups of values - buckets - out of a datetime or numeric input.
112
+ The size of the buckets can either be provided directly, or chosen based on
113
+ a recommended count and values range.
114
+
115
+ :param field: Numeric or date expression from which to derive buckets.
116
+ :param buckets: Target number of buckets, or desired bucket size if `from`
117
+ and `to` parameters are omitted.
118
+ :param from_: Start of the range. Can be a number, a date or a date expressed
119
+ as a string.
120
+ :param to: End of the range. Can be a number, a date or a date expressed as a string.
121
+ """
122
+ return InstrumentedExpression(
123
+ f"BUCKET({_render(field)}, {_render(buckets)}, {_render(from_)}, {_render(to)})"
124
+ )
125
+
126
+
127
+ def byte_length(string: ExpressionType) -> InstrumentedExpression:
128
+ """Returns the byte length of a string.
129
+
130
+ :param string: String expression. If `null`, the function returns `null`.
131
+ """
132
+ return InstrumentedExpression(f"BYTE_LENGTH({_render(string)})")
133
+
134
+
135
+ def case(*conditions: ExpressionType) -> InstrumentedExpression:
136
+ """Accepts pairs of conditions and values. The function returns the value
137
+ that belongs to the first condition that evaluates to `true`. If the
138
+ number of arguments is odd, the last argument is the default value which is
139
+ returned when no condition matches. If the number of arguments is even, and
140
+ no condition matches, the function returns `null`.
141
+ """
142
+ return InstrumentedExpression(
143
+ f'CASE({", ".join([_render(c) for c in conditions])})'
144
+ )
145
+
146
+
147
+ def categorize(field: ExpressionType) -> InstrumentedExpression:
148
+ """Groups text messages into categories of similarly formatted text values.
149
+
150
+ :param field: Expression to categorize
151
+ """
152
+ return InstrumentedExpression(f"CATEGORIZE({_render(field)})")
153
+
154
+
155
+ def cbrt(number: ExpressionType) -> InstrumentedExpression:
156
+ """Returns the cube root of a number. The input can be any numeric value,
157
+ the return value is always a double. Cube roots of infinities are null.
158
+
159
+ :param number: Numeric expression. If `null`, the function returns `null`.
160
+ """
161
+ return InstrumentedExpression(f"CBRT({_render(number)})")
162
+
163
+
164
+ def ceil(number: ExpressionType) -> InstrumentedExpression:
165
+ """Round a number up to the nearest integer.
166
+
167
+ :param number: Numeric expression. If `null`, the function returns `null`.
168
+ """
169
+ return InstrumentedExpression(f"CEIL({_render(number)})")
170
+
171
+
172
+ def cidr_match(ip: ExpressionType, block_x: ExpressionType) -> InstrumentedExpression:
173
+ """Returns true if the provided IP is contained in one of the provided CIDR blocks.
174
+
175
+ :param ip: IP address of type `ip` (both IPv4 and IPv6 are supported).
176
+ :param block_x: CIDR block to test the IP against.
177
+ """
178
+ return InstrumentedExpression(f"CIDR_MATCH({_render(ip)}, {_render(block_x)})")
179
+
180
+
181
+ def coalesce(first: ExpressionType, rest: ExpressionType) -> InstrumentedExpression:
182
+ """Returns the first of its arguments that is not null. If all arguments
183
+ are null, it returns `null`.
184
+
185
+ :param first: Expression to evaluate.
186
+ :param rest: Other expression to evaluate.
187
+ """
188
+ return InstrumentedExpression(f"COALESCE({_render(first)}, {_render(rest)})")
189
+
190
+
191
+ def concat(*strings: ExpressionType) -> InstrumentedExpression:
192
+ """Concatenates two or more strings."""
193
+ return InstrumentedExpression(
194
+ f'CONCAT({", ".join([f"{_render(s)}" for s in strings])})'
195
+ )
196
+
197
+
198
+ def cos(angle: ExpressionType) -> InstrumentedExpression:
199
+ """Returns the cosine of an angle.
200
+
201
+ :param angle: An angle, in radians. If `null`, the function returns `null`.
202
+ """
203
+ return InstrumentedExpression(f"COS({_render(angle)})")
204
+
205
+
206
+ def cosh(number: ExpressionType) -> InstrumentedExpression:
207
+ """Returns the hyperbolic cosine of a number.
208
+
209
+ :param number: Numeric expression. If `null`, the function returns `null`.
210
+ """
211
+ return InstrumentedExpression(f"COSH({_render(number)})")
212
+
213
+
214
+ def count(field: ExpressionType) -> InstrumentedExpression:
215
+ """Returns the total number (count) of input values.
216
+
217
+ :param field: Expression that outputs values to be counted. If omitted,
218
+ equivalent to `COUNT(*)` (the number of rows).
219
+ """
220
+ return InstrumentedExpression(f"COUNT({_render(field)})")
221
+
222
+
223
+ def count_distinct(
224
+ field: ExpressionType, precision: ExpressionType
225
+ ) -> InstrumentedExpression:
226
+ """Returns the approximate number of distinct values.
227
+
228
+ :param field: Column or literal for which to count the number of distinct values.
229
+ :param precision: Precision threshold. The maximum supported value is 40000. Thresholds
230
+ above this number will have the same effect as a threshold of 40000.
231
+ The default value is 3000.
232
+ """
233
+ return InstrumentedExpression(
234
+ f"COUNT_DISTINCT({_render(field)}, {_render(precision)})"
235
+ )
236
+
237
+
238
+ def count_distinct_over_time(
239
+ field: ExpressionType, precision: ExpressionType
240
+ ) -> InstrumentedExpression:
241
+ """The count of distinct values over time for a field.
242
+
243
+ :param field:
244
+ :param precision: Precision threshold. The maximum supported value is 40000. Thresholds
245
+ above this number will have the same effect as a threshold of 40000. The
246
+ default value is 3000.
247
+ """
248
+ return InstrumentedExpression(
249
+ f"COUNT_DISTINCT_OVER_TIME({_render(field)}, {_render(precision)})"
250
+ )
251
+
252
+
253
+ def count_over_time(field: ExpressionType) -> InstrumentedExpression:
254
+ """The count over time value of a field.
255
+
256
+ :param field:
257
+ """
258
+ return InstrumentedExpression(f"COUNT_OVER_TIME({_render(field)})")
259
+
260
+
261
+ def date_diff(
262
+ unit: ExpressionType, start_timestamp: ExpressionType, end_timestamp: ExpressionType
263
+ ) -> InstrumentedExpression:
264
+ """Subtracts the `startTimestamp` from the `endTimestamp` and returns the
265
+ difference in multiples of `unit`. If `startTimestamp` is later than the
266
+ `endTimestamp`, negative values are returned.
267
+
268
+ :param unit: Time difference unit
269
+ :param start_timestamp: A string representing a start timestamp
270
+ :param end_timestamp: A string representing an end timestamp
271
+ """
272
+ return InstrumentedExpression(
273
+ f"DATE_DIFF({_render(unit)}, {_render(start_timestamp)}, {_render(end_timestamp)})"
274
+ )
275
+
276
+
277
+ def date_extract(
278
+ date_part: ExpressionType, date: ExpressionType
279
+ ) -> InstrumentedExpression:
280
+ """Extracts parts of a date, like year, month, day, hour.
281
+
282
+ :param date_part: Part of the date to extract. Can be:
283
+ `aligned_day_of_week_in_month`, `aligned_day_of_week_in_year`,
284
+ `aligned_week_of_month`, `aligned_week_of_year`, `ampm_of_day`,
285
+ `clock_hour_of_ampm`, `clock_hour_of_day`, `day_of_month`, `day_of_week`,
286
+ `day_of_year`, `epoch_day`, `era`, `hour_of_ampm`, `hour_of_day`,
287
+ `instant_seconds`, `micro_of_day`, `micro_of_second`, `milli_of_day`,
288
+ `milli_of_second`, `minute_of_day`, `minute_of_hour`, `month_of_year`,
289
+ `nano_of_day`, `nano_of_second`, `offset_seconds`, `proleptic_month`,
290
+ `second_of_day`, `second_of_minute`, `year`, or `year_of_era`. If `null`,
291
+ the function returns `null`.
292
+ :param date: Date expression. If `null`, the function returns `null`.
293
+ """
294
+ return InstrumentedExpression(
295
+ f"DATE_EXTRACT({_render(date_part)}, {_render(date)})"
296
+ )
297
+
298
+
299
+ def date_format(
300
+ date: ExpressionType,
301
+ date_format: ExpressionType = None,
302
+ ) -> InstrumentedExpression:
303
+ """Returns a string representation of a date, in the provided format.
304
+
305
+ :param date_format: Date format (optional). If no format is specified, the
306
+ `yyyy-MM-dd'T'HH:mm:ss.SSSZ` format is used. If `null`, the
307
+ function returns `null`.
308
+ :param date: Date expression. If `null`, the function returns `null`.
309
+ """
310
+ if date_format is not None:
311
+ return InstrumentedExpression(
312
+ f"DATE_FORMAT({_render(date_format)}, {_render(date)})"
313
+ )
314
+ else:
315
+ return InstrumentedExpression(f"DATE_FORMAT({_render(date)})")
316
+
317
+
318
+ def date_parse(
319
+ date_pattern: ExpressionType, date_string: ExpressionType
320
+ ) -> InstrumentedExpression:
321
+ """Returns a date by parsing the second argument using the format specified
322
+ in the first argument.
323
+
324
+ :param date_pattern: The date format. If `null`, the function returns `null`.
325
+ :param date_string: Date expression as a string. If `null` or an empty
326
+ string, the function returns `null`.
327
+ """
328
+ return InstrumentedExpression(
329
+ f"DATE_PARSE({_render(date_pattern)}, {_render(date_string)})"
330
+ )
331
+
332
+
333
+ def date_trunc(
334
+ interval: ExpressionType, date: ExpressionType
335
+ ) -> InstrumentedExpression:
336
+ """Rounds down a date to the closest interval since epoch, which starts at `0001-01-01T00:00:00Z`.
337
+
338
+ :param interval: Interval; expressed using the timespan literal syntax.
339
+ :param date: Date expression
340
+ """
341
+ return InstrumentedExpression(f"DATE_TRUNC({_render(interval)}, {_render(date)})")
342
+
343
+
344
+ def e() -> InstrumentedExpression:
345
+ """Returns Euler’s number)."""
346
+ return InstrumentedExpression("E()")
347
+
348
+
349
+ def ends_with(str: ExpressionType, suffix: ExpressionType) -> InstrumentedExpression:
350
+ """Returns a boolean that indicates whether a keyword string ends with
351
+ another string.
352
+
353
+ :param str: String expression. If `null`, the function returns `null`.
354
+ :param suffix: String expression. If `null`, the function returns `null`.
355
+ """
356
+ return InstrumentedExpression(f"ENDS_WITH({_render(str)}, {_render(suffix)})")
357
+
358
+
359
+ def exp(number: ExpressionType) -> InstrumentedExpression:
360
+ """Returns the value of e raised to the power of the given number.
361
+
362
+ :param number: Numeric expression. If `null`, the function returns `null`.
363
+ """
364
+ return InstrumentedExpression(f"EXP({_render(number)})")
365
+
366
+
367
+ def first_over_time(field: ExpressionType) -> InstrumentedExpression:
368
+ """The earliest value of a field, where recency determined by the
369
+ `@timestamp` field.
370
+
371
+ :param field:
372
+ """
373
+ return InstrumentedExpression(f"FIRST_OVER_TIME({_render(field)})")
374
+
375
+
376
+ def floor(number: ExpressionType) -> InstrumentedExpression:
377
+ """Round a number down to the nearest integer.
378
+
379
+ :param number: Numeric expression. If `null`, the function returns `null`.
380
+ """
381
+ return InstrumentedExpression(f"FLOOR({_render(number)})")
382
+
383
+
384
+ def from_base64(string: ExpressionType) -> InstrumentedExpression:
385
+ """Decode a base64 string.
386
+
387
+ :param string: A base64 string.
388
+ """
389
+ return InstrumentedExpression(f"FROM_BASE64({_render(string)})")
390
+
391
+
392
+ def greatest(first: ExpressionType, rest: ExpressionType) -> InstrumentedExpression:
393
+ """Returns the maximum value from multiple columns. This is similar to
394
+ `MV_MAX` except it is intended to run on multiple columns at once.
395
+
396
+ :param first: First of the columns to evaluate.
397
+ :param rest: The rest of the columns to evaluate.
398
+ """
399
+ return InstrumentedExpression(f"GREATEST({_render(first)}, {_render(rest)})")
400
+
401
+
402
+ def hash(algorithm: ExpressionType, input: ExpressionType) -> InstrumentedExpression:
403
+ """Computes the hash of the input using various algorithms such as MD5,
404
+ SHA, SHA-224, SHA-256, SHA-384, SHA-512.
405
+
406
+ :param algorithm: Hash algorithm to use.
407
+ :param input: Input to hash.
408
+ """
409
+ return InstrumentedExpression(f"HASH({_render(algorithm)}, {_render(input)})")
410
+
411
+
412
+ def hypot(number1: ExpressionType, number2: ExpressionType) -> InstrumentedExpression:
413
+ """Returns the hypotenuse of two numbers. The input can be any numeric
414
+ values, the return value is always a double. Hypotenuses of infinities are null.
415
+
416
+ :param number1: Numeric expression. If `null`, the function returns `null`.
417
+ :param number2: Numeric expression. If `null`, the function returns `null`.
418
+ """
419
+ return InstrumentedExpression(f"HYPOT({number1}, {number2})")
420
+
421
+
422
+ def ip_prefix(
423
+ ip: ExpressionType,
424
+ prefix_length_v4: ExpressionType,
425
+ prefix_length_v6: ExpressionType,
426
+ ) -> InstrumentedExpression:
427
+ """Truncates an IP to a given prefix length.
428
+
429
+ :param ip: IP address of type `ip` (both IPv4 and IPv6 are supported).
430
+ :param prefix_length_v4: Prefix length for IPv4 addresses.
431
+ :param prefix_length_v6: Prefix length for IPv6 addresses.
432
+ """
433
+ return InstrumentedExpression(
434
+ f"IP_PREFIX({_render(ip)}, {prefix_length_v4}, {prefix_length_v6})"
435
+ )
436
+
437
+
438
+ def knn(
439
+ field: ExpressionType, query: ExpressionType, options: ExpressionType = None
440
+ ) -> InstrumentedExpression:
441
+ """Finds the k nearest vectors to a query vector, as measured by a
442
+ similarity metric. knn function finds nearest vectors through approximate
443
+ search on indexed dense_vectors.
444
+
445
+ :param field: Field that the query will target.
446
+ :param query: Vector value to find top nearest neighbours for.
447
+ :param options: (Optional) kNN additional options as function named parameters.
448
+ """
449
+ if options is not None:
450
+ return InstrumentedExpression(
451
+ f"KNN({_render(field)}, {_render(query)}, {_render(options)})"
452
+ )
453
+ else:
454
+ return InstrumentedExpression(f"KNN({_render(field)}, {_render(query)})")
455
+
456
+
457
+ def kql(query: ExpressionType) -> InstrumentedExpression:
458
+ """Performs a KQL query. Returns true if the provided KQL query string
459
+ matches the row.
460
+
461
+ :param query: Query string in KQL query string format.
462
+ """
463
+ return InstrumentedExpression(f"KQL({_render(query)})")
464
+
465
+
466
+ def last_over_time(field: ExpressionType) -> InstrumentedExpression:
467
+ """The latest value of a field, where recency determined by the
468
+ `@timestamp` field.
469
+
470
+ :param field:
471
+ """
472
+ return InstrumentedExpression(f"LAST_OVER_TIME({_render(field)})")
473
+
474
+
475
+ def least(first: ExpressionType, rest: ExpressionType) -> InstrumentedExpression:
476
+ """Returns the minimum value from multiple columns. This is similar to
477
+ `MV_MIN` except it is intended to run on multiple columns at once.
478
+
479
+ :param first: First of the columns to evaluate.
480
+ :param rest: The rest of the columns to evaluate.
481
+ """
482
+ return InstrumentedExpression(f"LEAST({_render(first)}, {_render(rest)})")
483
+
484
+
485
+ def left(string: ExpressionType, length: ExpressionType) -> InstrumentedExpression:
486
+ """Returns the substring that extracts *length* chars from *string*
487
+ starting from the left.
488
+
489
+ :param string: The string from which to return a substring.
490
+ :param length: The number of characters to return.
491
+ """
492
+ return InstrumentedExpression(f"LEFT({_render(string)}, {_render(length)})")
493
+
494
+
495
+ def length(string: ExpressionType) -> InstrumentedExpression:
496
+ """Returns the character length of a string.
497
+
498
+ :param string: String expression. If `null`, the function returns `null`.
499
+ """
500
+ return InstrumentedExpression(f"LENGTH({_render(string)})")
501
+
502
+
503
+ def locate(
504
+ string: ExpressionType, substring: ExpressionType, start: ExpressionType
505
+ ) -> InstrumentedExpression:
506
+ """Returns an integer that indicates the position of a keyword substring
507
+ within another string. Returns `0` if the substring cannot be found. Note
508
+ that string positions start from `1`.
509
+
510
+ :param string: An input string
511
+ :param substring: A substring to locate in the input string
512
+ :param start: The start index
513
+ """
514
+ return InstrumentedExpression(
515
+ f"LOCATE({_render(string)}, {_render(substring)}, {_render(start)})"
516
+ )
517
+
518
+
519
+ def log(base: ExpressionType, number: ExpressionType) -> InstrumentedExpression:
520
+ """Returns the logarithm of a value to a base. The input can be any numeric
521
+ value, the return value is always a double. Logs of zero, negative
522
+ numbers, and base of one return `null` as well as a warning.
523
+
524
+ :param base: Base of logarithm. If `null`, the function returns `null`. If
525
+ not provided, this function returns the natural logarithm (base e) of a value.
526
+ :param number: Numeric expression. If `null`, the function returns `null`.
527
+ """
528
+ return InstrumentedExpression(f"LOG({_render(base)}, {_render(number)})")
529
+
530
+
531
+ def log10(number: ExpressionType) -> InstrumentedExpression:
532
+ """Returns the logarithm of a value to base 10. The input can be any
533
+ numeric value, the return value is always a double. Logs of 0 and negative
534
+ numbers return `null` as well as a warning.
535
+
536
+ :param number: Numeric expression. If `null`, the function returns `null`.
537
+ """
538
+ return InstrumentedExpression(f"LOG10({_render(number)})")
539
+
540
+
541
+ def ltrim(string: ExpressionType) -> InstrumentedExpression:
542
+ """Removes leading whitespaces from a string.
543
+
544
+ :param string: String expression. If `null`, the function returns `null`.
545
+ """
546
+ return InstrumentedExpression(f"LTRIM({_render(string)})")
547
+
548
+
549
+ def match(
550
+ field: ExpressionType, query: ExpressionType, options: ExpressionType = None
551
+ ) -> InstrumentedExpression:
552
+ """Use `MATCH` to perform a match query on the specified field. Using
553
+ `MATCH` is equivalent to using the `match` query in the Elasticsearch Query DSL.
554
+
555
+ :param field: Field that the query will target.
556
+ :param query: Value to find in the provided field.
557
+ :param options: (Optional) Match additional options as function named parameters.
558
+ """
559
+ if options is not None:
560
+ return InstrumentedExpression(
561
+ f"MATCH({_render(field)}, {_render(query)}, {_render(options)})"
562
+ )
563
+ else:
564
+ return InstrumentedExpression(f"MATCH({_render(field)}, {_render(query)})")
565
+
566
+
567
+ def match_phrase(
568
+ field: ExpressionType, query: ExpressionType, options: ExpressionType = None
569
+ ) -> InstrumentedExpression:
570
+ """Use `MATCH_PHRASE` to perform a `match_phrase` on the specified field.
571
+ Using `MATCH_PHRASE` is equivalent to using the `match_phrase` query in the
572
+ Elasticsearch Query DSL.
573
+
574
+ :param field: Field that the query will target.
575
+ :param query: Value to find in the provided field.
576
+ :param options: (Optional) MatchPhrase additional options as function named parameters.
577
+ """
578
+ if options is not None:
579
+ return InstrumentedExpression(
580
+ f"MATCH_PHRASE({_render(field)}, {_render(query)}, {_render(options)})"
581
+ )
582
+ else:
583
+ return InstrumentedExpression(
584
+ f"MATCH_PHRASE({_render(field)}, {_render(query)})"
585
+ )
586
+
587
+
588
+ def max(field: ExpressionType) -> InstrumentedExpression:
589
+ """The maximum value of a field.
590
+
591
+ :param field:
592
+ """
593
+ return InstrumentedExpression(f"MAX({_render(field)})")
594
+
595
+
596
+ def max_over_time(field: ExpressionType) -> InstrumentedExpression:
597
+ """The maximum over time value of a field.
598
+
599
+ :param field:
600
+ """
601
+ return InstrumentedExpression(f"MAX_OVER_TIME({_render(field)})")
602
+
603
+
604
+ def md5(input: ExpressionType) -> InstrumentedExpression:
605
+ """Computes the MD5 hash of the input.
606
+
607
+ :param input: Input to hash.
608
+ """
609
+ return InstrumentedExpression(f"MD5({_render(input)})")
610
+
611
+
612
+ def median(number: ExpressionType) -> InstrumentedExpression:
613
+ """The value that is greater than half of all values and less than half of
614
+ all values, also known as the 50% `PERCENTILE`.
615
+
616
+ :param number: Expression that outputs values to calculate the median of.
617
+ """
618
+ return InstrumentedExpression(f"MEDIAN({_render(number)})")
619
+
620
+
621
+ def median_absolute_deviation(number: ExpressionType) -> InstrumentedExpression:
622
+ """Returns the median absolute deviation, a measure of variability. It is a
623
+ robust statistic, meaning that it is useful for describing data that may
624
+ have outliers, or may not be normally distributed. For such data it can be
625
+ more descriptive than standard deviation. It is calculated as the median
626
+ of each data point’s deviation from the median of the entire sample. That
627
+ is, for a random variable `X`, the median absolute deviation is
628
+ `median(|median(X) - X|)`.
629
+
630
+ :param number:
631
+ """
632
+ return InstrumentedExpression(f"MEDIAN_ABSOLUTE_DEVIATION({_render(number)})")
633
+
634
+
635
+ def min(field: ExpressionType) -> InstrumentedExpression:
636
+ """The minimum value of a field.
637
+
638
+ :param field:
639
+ """
640
+ return InstrumentedExpression(f"MIN({_render(field)})")
641
+
642
+
643
+ def min_over_time(field: ExpressionType) -> InstrumentedExpression:
644
+ """The minimum over time value of a field.
645
+
646
+ :param field:
647
+ """
648
+ return InstrumentedExpression(f"MIN_OVER_TIME({_render(field)})")
649
+
650
+
651
+ def multi_match(
652
+ query: ExpressionType, *fields: ExpressionType, options: ExpressionType = None
653
+ ) -> InstrumentedExpression:
654
+ """Use `MULTI_MATCH` to perform a multi-match query on the specified field.
655
+ The multi_match query builds on the match query to allow multi-field queries.
656
+
657
+ :param query: Value to find in the provided fields.
658
+ :param fields: Fields to use for matching
659
+ :param options: (Optional) Additional options for MultiMatch, passed as function
660
+ named parameters
661
+ """
662
+ if options is not None:
663
+ return InstrumentedExpression(
664
+ f'MULTI_MATCH({_render(query)}, {", ".join([_render(c) for c in fields])}, {_render(options)})'
665
+ )
666
+ else:
667
+ return InstrumentedExpression(
668
+ f'MULTI_MATCH({_render(query)}, {", ".join([_render(c) for c in fields])})'
669
+ )
670
+
671
+
672
+ def mv_append(field1: ExpressionType, field2: ExpressionType) -> InstrumentedExpression:
673
+ """Concatenates values of two multi-value fields.
674
+
675
+ :param field1:
676
+ :param field2:
677
+ """
678
+ return InstrumentedExpression(f"MV_APPEND({field1}, {field2})")
679
+
680
+
681
+ def mv_avg(number: ExpressionType) -> InstrumentedExpression:
682
+ """Converts a multivalued field into a single valued field containing the
683
+ average of all of the values.
684
+
685
+ :param number: Multivalue expression.
686
+ """
687
+ return InstrumentedExpression(f"MV_AVG({_render(number)})")
688
+
689
+
690
+ def mv_concat(string: ExpressionType, delim: ExpressionType) -> InstrumentedExpression:
691
+ """Converts a multivalued string expression into a single valued column
692
+ containing the concatenation of all values separated by a delimiter.
693
+
694
+ :param string: Multivalue expression.
695
+ :param delim: Delimiter.
696
+ """
697
+ return InstrumentedExpression(f"MV_CONCAT({_render(string)}, {_render(delim)})")
698
+
699
+
700
+ def mv_count(field: ExpressionType) -> InstrumentedExpression:
701
+ """Converts a multivalued expression into a single valued column containing
702
+ a count of the number of values.
703
+
704
+ :param field: Multivalue expression.
705
+ """
706
+ return InstrumentedExpression(f"MV_COUNT({_render(field)})")
707
+
708
+
709
+ def mv_dedupe(field: ExpressionType) -> InstrumentedExpression:
710
+ """Remove duplicate values from a multivalued field.
711
+
712
+ :param field: Multivalue expression.
713
+ """
714
+ return InstrumentedExpression(f"MV_DEDUPE({_render(field)})")
715
+
716
+
717
+ def mv_first(field: ExpressionType) -> InstrumentedExpression:
718
+ """Converts a multivalued expression into a single valued column containing
719
+ the first value. This is most useful when reading from a function that
720
+ emits multivalued columns in a known order like `SPLIT`.
721
+
722
+ :param field: Multivalue expression.
723
+ """
724
+ return InstrumentedExpression(f"MV_FIRST({_render(field)})")
725
+
726
+
727
+ def mv_last(field: ExpressionType) -> InstrumentedExpression:
728
+ """Converts a multivalue expression into a single valued column containing
729
+ the last value. This is most useful when reading from a function that emits
730
+ multivalued columns in a known order like `SPLIT`.
731
+
732
+ :param field: Multivalue expression.
733
+ """
734
+ return InstrumentedExpression(f"MV_LAST({_render(field)})")
735
+
736
+
737
+ def mv_max(field: ExpressionType) -> InstrumentedExpression:
738
+ """Converts a multivalued expression into a single valued column containing
739
+ the maximum value.
740
+
741
+ :param field: Multivalue expression.
742
+ """
743
+ return InstrumentedExpression(f"MV_MAX({_render(field)})")
744
+
745
+
746
+ def mv_median(number: ExpressionType) -> InstrumentedExpression:
747
+ """Converts a multivalued field into a single valued field containing the
748
+ median value.
749
+
750
+ :param number: Multivalue expression.
751
+ """
752
+ return InstrumentedExpression(f"MV_MEDIAN({_render(number)})")
753
+
754
+
755
+ def mv_median_absolute_deviation(number: ExpressionType) -> InstrumentedExpression:
756
+ """Converts a multivalued field into a single valued field containing the
757
+ median absolute deviation. It is calculated as the median of each data
758
+ point’s deviation from the median of the entire sample. That is, for a
759
+ random variable `X`, the median absolute deviation is `median(|median(X) - X|)`.
760
+
761
+ :param number: Multivalue expression.
762
+ """
763
+ return InstrumentedExpression(f"MV_MEDIAN_ABSOLUTE_DEVIATION({_render(number)})")
764
+
765
+
766
+ def mv_min(field: ExpressionType) -> InstrumentedExpression:
767
+ """Converts a multivalued expression into a single valued column containing
768
+ the minimum value.
769
+
770
+ :param field: Multivalue expression.
771
+ """
772
+ return InstrumentedExpression(f"MV_MIN({_render(field)})")
773
+
774
+
775
+ def mv_percentile(
776
+ number: ExpressionType, percentile: ExpressionType
777
+ ) -> InstrumentedExpression:
778
+ """Converts a multivalued field into a single valued field containing the
779
+ value at which a certain percentage of observed values occur.
780
+
781
+ :param number: Multivalue expression.
782
+ :param percentile: The percentile to calculate. Must be a number between 0
783
+ and 100. Numbers out of range will return a null instead.
784
+ """
785
+ return InstrumentedExpression(
786
+ f"MV_PERCENTILE({_render(number)}, {_render(percentile)})"
787
+ )
788
+
789
+
790
+ def mv_pseries_weighted_sum(
791
+ number: ExpressionType, p: ExpressionType
792
+ ) -> InstrumentedExpression:
793
+ """Converts a multivalued expression into a single-valued column by
794
+ multiplying every element on the input list by its corresponding term in
795
+ P-Series and computing the sum.
796
+
797
+ :param number: Multivalue expression.
798
+ :param p: It is a constant number that represents the *p* parameter in the
799
+ P-Series. It impacts every element’s contribution to the weighted sum.
800
+ """
801
+ return InstrumentedExpression(
802
+ f"MV_PSERIES_WEIGHTED_SUM({_render(number)}, {_render(p)})"
803
+ )
804
+
805
+
806
+ def mv_slice(
807
+ field: ExpressionType, start: ExpressionType, end: ExpressionType = None
808
+ ) -> InstrumentedExpression:
809
+ """Returns a subset of the multivalued field using the start and end index
810
+ values. This is most useful when reading from a function that emits
811
+ multivalued columns in a known order like `SPLIT` or `MV_SORT`.
812
+
813
+ :param field: Multivalue expression. If `null`, the function returns `null`.
814
+ :param start: Start position. If `null`, the function returns `null`. The
815
+ start argument can be negative. An index of -1 is used to specify
816
+ the last value in the list.
817
+ :param end: End position(included). Optional; if omitted, the position at
818
+ `start` is returned. The end argument can be negative. An index of -1
819
+ is used to specify the last value in the list.
820
+ """
821
+ if end is not None:
822
+ return InstrumentedExpression(
823
+ f"MV_SLICE({_render(field)}, {_render(start)}, {_render(end)})"
824
+ )
825
+ else:
826
+ return InstrumentedExpression(f"MV_SLICE({_render(field)}, {_render(start)})")
827
+
828
+
829
+ def mv_sort(field: ExpressionType, order: ExpressionType) -> InstrumentedExpression:
830
+ """Sorts a multivalued field in lexicographical order.
831
+
832
+ :param field: Multivalue expression. If `null`, the function returns `null`.
833
+ :param order: Sort order. The valid options are ASC and DESC, the default is ASC.
834
+ """
835
+ return InstrumentedExpression(f"MV_SORT({_render(field)}, {_render(order)})")
836
+
837
+
838
+ def mv_sum(number: ExpressionType) -> InstrumentedExpression:
839
+ """Converts a multivalued field into a single valued field containing the
840
+ sum of all of the values.
841
+
842
+ :param number: Multivalue expression.
843
+ """
844
+ return InstrumentedExpression(f"MV_SUM({_render(number)})")
845
+
846
+
847
+ def mv_zip(
848
+ string1: ExpressionType, string2: ExpressionType, delim: ExpressionType = None
849
+ ) -> InstrumentedExpression:
850
+ """Combines the values from two multivalued fields with a delimiter that
851
+ joins them together.
852
+
853
+ :param string1: Multivalue expression.
854
+ :param string2: Multivalue expression.
855
+ :param delim: Delimiter. Optional; if omitted, `,` is used as a default delimiter.
856
+ """
857
+ if delim is not None:
858
+ return InstrumentedExpression(f"MV_ZIP({string1}, {string2}, {_render(delim)})")
859
+ else:
860
+ return InstrumentedExpression(f"MV_ZIP({string1}, {string2})")
861
+
862
+
863
+ def now() -> InstrumentedExpression:
864
+ """Returns current date and time."""
865
+ return InstrumentedExpression("NOW()")
866
+
867
+
868
+ def percentile(
869
+ number: ExpressionType, percentile: ExpressionType
870
+ ) -> InstrumentedExpression:
871
+ """Returns the value at which a certain percentage of observed values
872
+ occur. For example, the 95th percentile is the value which is greater than
873
+ 95% of the observed values and the 50th percentile is the `MEDIAN`.
874
+
875
+ :param number:
876
+ :param percentile:
877
+ """
878
+ return InstrumentedExpression(
879
+ f"PERCENTILE({_render(number)}, {_render(percentile)})"
880
+ )
881
+
882
+
883
+ def pi() -> InstrumentedExpression:
884
+ """Returns Pi, the ratio of a circle’s circumference to its diameter."""
885
+ return InstrumentedExpression("PI()")
886
+
887
+
888
+ def pow(base: ExpressionType, exponent: ExpressionType) -> InstrumentedExpression:
889
+ """Returns the value of `base` raised to the power of `exponent`.
890
+
891
+ :param base: Numeric expression for the base. If `null`, the function returns `null`.
892
+ :param exponent: Numeric expression for the exponent. If `null`, the function returns `null`.
893
+ """
894
+ return InstrumentedExpression(f"POW({_render(base)}, {_render(exponent)})")
895
+
896
+
897
+ def qstr(
898
+ query: ExpressionType, options: ExpressionType = None
899
+ ) -> InstrumentedExpression:
900
+ """Performs a query string query. Returns true if the provided query string
901
+ matches the row.
902
+
903
+ :param query: Query string in Lucene query string format.
904
+ :param options: (Optional) Additional options for Query String as function named
905
+ parameters.
906
+ """
907
+ if options is not None:
908
+ return InstrumentedExpression(f"QSTR({_render(query)}, {_render(options)})")
909
+ else:
910
+ return InstrumentedExpression(f"QSTR({_render(query)})")
911
+
912
+
913
+ def rate(field: ExpressionType) -> InstrumentedExpression:
914
+ """The rate of a counter field.
915
+
916
+ :param field:
917
+ """
918
+ return InstrumentedExpression(f"RATE({_render(field)})")
919
+
920
+
921
+ def repeat(string: ExpressionType, number: ExpressionType) -> InstrumentedExpression:
922
+ """Returns a string constructed by concatenating `string` with itself the
923
+ specified `number` of times.
924
+
925
+ :param string: String expression.
926
+ :param number: Number times to repeat.
927
+ """
928
+ return InstrumentedExpression(f"REPEAT({_render(string)}, {_render(number)})")
929
+
930
+
931
+ def replace(
932
+ string: ExpressionType, regex: ExpressionType, new_string: ExpressionType
933
+ ) -> InstrumentedExpression:
934
+ """The function substitutes in the string `str` any match of the regular
935
+ expression `regex` with the replacement string `newStr`.
936
+
937
+ :param string: String expression.
938
+ :param regex: Regular expression.
939
+ :param new_string: Replacement string.
940
+ """
941
+ return InstrumentedExpression(
942
+ f"REPLACE({_render(string)}, {_render(regex)}, {_render(new_string)})"
943
+ )
944
+
945
+
946
+ def reverse(str: ExpressionType) -> InstrumentedExpression:
947
+ """Returns a new string representing the input string in reverse order.
948
+
949
+ :param str: String expression. If `null`, the function returns `null`.
950
+ """
951
+ return InstrumentedExpression(f"REVERSE({_render(str)})")
952
+
953
+
954
+ def right(string: ExpressionType, length: ExpressionType) -> InstrumentedExpression:
955
+ """Return the substring that extracts *length* chars from *str* starting
956
+ from the right.
957
+
958
+ :param string: The string from which to returns a substring.
959
+ :param length: The number of characters to return.
960
+ """
961
+ return InstrumentedExpression(f"RIGHT({_render(string)}, {_render(length)})")
962
+
963
+
964
+ def round(
965
+ number: ExpressionType, decimals: ExpressionType = None
966
+ ) -> InstrumentedExpression:
967
+ """Rounds a number to the specified number of decimal places. Defaults to
968
+ 0, which returns the nearest integer. If the precision is a negative
969
+ number, rounds to the number of digits left of the decimal point.
970
+
971
+ :param number: The numeric value to round. If `null`, the function returns `null`.
972
+ :param decimals: The number of decimal places to round to. Defaults to 0. If
973
+ `null`, the function returns `null`.
974
+ """
975
+ if decimals is not None:
976
+ return InstrumentedExpression(f"ROUND({_render(number)}, {_render(decimals)})")
977
+ else:
978
+ return InstrumentedExpression(f"ROUND({_render(number)})")
979
+
980
+
981
+ def round_to(field: ExpressionType, points: ExpressionType) -> InstrumentedExpression:
982
+ """Rounds down to one of a list of fixed points.
983
+
984
+ :param field: The numeric value to round. If `null`, the function returns `null`.
985
+ :param points: Remaining rounding points. Must be constants.
986
+ """
987
+ return InstrumentedExpression(f"ROUND_TO({_render(field)}, {_render(points)})")
988
+
989
+
990
+ def rtrim(string: ExpressionType) -> InstrumentedExpression:
991
+ """Removes trailing whitespaces from a string.
992
+
993
+ :param string: String expression. If `null`, the function returns `null`.
994
+ """
995
+ return InstrumentedExpression(f"RTRIM({_render(string)})")
996
+
997
+
998
+ def sample(field: ExpressionType, limit: ExpressionType) -> InstrumentedExpression:
999
+ """Collects sample values for a field.
1000
+
1001
+ :param field: The field to collect sample values for.
1002
+ :param limit: The maximum number of values to collect.
1003
+ """
1004
+ return InstrumentedExpression(f"SAMPLE({_render(field)}, {_render(limit)})")
1005
+
1006
+
1007
+ def scalb(d: ExpressionType, scale_factor: ExpressionType) -> InstrumentedExpression:
1008
+ """Returns the result of `d * 2 ^ scaleFactor`, Similar to Java's `scalb`
1009
+ function. Result is rounded as if performed by a single correctly rounded
1010
+ floating-point multiply to a member of the double value set.
1011
+
1012
+ :param d: Numeric expression for the multiplier. If `null`, the function
1013
+ returns `null`.
1014
+ :param scale_factor: Numeric expression for the scale factor. If `null`, the
1015
+ function returns `null`.
1016
+ """
1017
+ return InstrumentedExpression(f"SCALB({_render(d)}, {_render(scale_factor)})")
1018
+
1019
+
1020
+ def sha1(input: ExpressionType) -> InstrumentedExpression:
1021
+ """Computes the SHA1 hash of the input.
1022
+
1023
+ :param input: Input to hash.
1024
+ """
1025
+ return InstrumentedExpression(f"SHA1({_render(input)})")
1026
+
1027
+
1028
+ def sha256(input: ExpressionType) -> InstrumentedExpression:
1029
+ """Computes the SHA256 hash of the input.
1030
+
1031
+ :param input: Input to hash.
1032
+ """
1033
+ return InstrumentedExpression(f"SHA256({_render(input)})")
1034
+
1035
+
1036
+ def signum(number: ExpressionType) -> InstrumentedExpression:
1037
+ """Returns the sign of the given number. It returns `-1` for negative
1038
+ numbers, `0` for `0` and `1` for positive numbers.
1039
+
1040
+ :param number: Numeric expression. If `null`, the function returns `null`.
1041
+ """
1042
+ return InstrumentedExpression(f"SIGNUM({_render(number)})")
1043
+
1044
+
1045
+ def sin(angle: ExpressionType) -> InstrumentedExpression:
1046
+ """Returns the sine of an angle.
1047
+
1048
+ :param angle: An angle, in radians. If `null`, the function returns `null`.
1049
+ """
1050
+ return InstrumentedExpression(f"SIN({_render(angle)})")
1051
+
1052
+
1053
+ def sinh(number: ExpressionType) -> InstrumentedExpression:
1054
+ """Returns the hyperbolic sine of a number.
1055
+
1056
+ :param number: Numeric expression. If `null`, the function returns `null`.
1057
+ """
1058
+ return InstrumentedExpression(f"SINH({_render(number)})")
1059
+
1060
+
1061
+ def space(number: ExpressionType) -> InstrumentedExpression:
1062
+ """Returns a string made of `number` spaces.
1063
+
1064
+ :param number: Number of spaces in result.
1065
+ """
1066
+ return InstrumentedExpression(f"SPACE({_render(number)})")
1067
+
1068
+
1069
+ def split(string: ExpressionType, delim: ExpressionType) -> InstrumentedExpression:
1070
+ """Split a single valued string into multiple strings.
1071
+
1072
+ :param string: String expression. If `null`, the function returns `null`.
1073
+ :param delim: Delimiter. Only single byte delimiters are currently supported.
1074
+ """
1075
+ return InstrumentedExpression(f"SPLIT({_render(string)}, {_render(delim)})")
1076
+
1077
+
1078
+ def sqrt(number: ExpressionType) -> InstrumentedExpression:
1079
+ """Returns the square root of a number. The input can be any numeric value,
1080
+ the return value is always a double. Square roots of negative numbers and
1081
+ infinities are null.
1082
+
1083
+ :param number: Numeric expression. If `null`, the function returns `null`.
1084
+ """
1085
+ return InstrumentedExpression(f"SQRT({_render(number)})")
1086
+
1087
+
1088
+ def starts_with(str: ExpressionType, prefix: ExpressionType) -> InstrumentedExpression:
1089
+ """Returns a boolean that indicates whether a keyword string starts with
1090
+ another string.
1091
+
1092
+ :param str: String expression. If `null`, the function returns `null`.
1093
+ :param prefix: String expression. If `null`, the function returns `null`.
1094
+ """
1095
+ return InstrumentedExpression(f"STARTS_WITH({_render(str)}, {_render(prefix)})")
1096
+
1097
+
1098
+ def std_dev(number: ExpressionType) -> InstrumentedExpression:
1099
+ """The population standard deviation of a numeric field.
1100
+
1101
+ :param number:
1102
+ """
1103
+ return InstrumentedExpression(f"STD_DEV({_render(number)})")
1104
+
1105
+
1106
+ def st_centroid_agg(field: ExpressionType) -> InstrumentedExpression:
1107
+ """Calculate the spatial centroid over a field with spatial point geometry type.
1108
+
1109
+ :param field:
1110
+ """
1111
+ return InstrumentedExpression(f"ST_CENTROID_AGG({_render(field)})")
1112
+
1113
+
1114
+ def st_contains(
1115
+ geom_a: ExpressionType, geom_b: ExpressionType
1116
+ ) -> InstrumentedExpression:
1117
+ """Returns whether the first geometry contains the second geometry. This is
1118
+ the inverse of the ST_WITHIN function.
1119
+
1120
+ :param geom_a: Expression of type `geo_point`, `cartesian_point`,
1121
+ `geo_shape` or `cartesian_shape`. If `null`, the function returns
1122
+ `null`.
1123
+ :param geom_b: Expression of type `geo_point`, `cartesian_point`, `geo_shape`
1124
+ or `cartesian_shape`. If `null`, the function returns `null`. The
1125
+ second parameter must also have the same coordinate system as the
1126
+ first. This means it is not possible to combine `geo_*` and
1127
+ `cartesian_*` parameters.
1128
+ """
1129
+ return InstrumentedExpression(f"ST_CONTAINS({_render(geom_a)}, {_render(geom_b)})")
1130
+
1131
+
1132
+ def st_disjoint(
1133
+ geom_a: ExpressionType, geom_b: ExpressionType
1134
+ ) -> InstrumentedExpression:
1135
+ """Returns whether the two geometries or geometry columns are disjoint.
1136
+ This is the inverse of the ST_INTERSECTS function. In mathematical terms:
1137
+ ST_Disjoint(A, B) ⇔ A ⋂ B = ∅
1138
+
1139
+ :param geom_a: Expression of type `geo_point`, `cartesian_point`,
1140
+ `geo_shape` or `cartesian_shape`. If `null`, the function returns
1141
+ `null`.
1142
+ :param geom_b: Expression of type `geo_point`, `cartesian_point`, `geo_shape`
1143
+ or `cartesian_shape`. If `null`, the function returns `null`. The
1144
+ second parameter must also have the same coordinate system as the
1145
+ first. This means it is not possible to combine `geo_*` and
1146
+ `cartesian_*` parameters.
1147
+ """
1148
+ return InstrumentedExpression(f"ST_DISJOINT({_render(geom_a)}, {_render(geom_b)})")
1149
+
1150
+
1151
+ def st_distance(
1152
+ geom_a: ExpressionType, geom_b: ExpressionType
1153
+ ) -> InstrumentedExpression:
1154
+ """Computes the distance between two points. For cartesian geometries, this
1155
+ is the pythagorean distance in the same units as the original coordinates.
1156
+ For geographic geometries, this is the circular distance along the great
1157
+ circle in meters.
1158
+
1159
+ :param geom_a: Expression of type `geo_point` or `cartesian_point`. If
1160
+ `null`, the function returns `null`.
1161
+ :param geom_b: Expression of type `geo_point` or `cartesian_point`. If
1162
+ `null`, the function returns `null`. The second parameter must
1163
+ also have the same coordinate system as the first. This means it
1164
+ is not possible to combine `geo_point` and `cartesian_point` parameters.
1165
+ """
1166
+ return InstrumentedExpression(f"ST_DISTANCE({_render(geom_a)}, {_render(geom_b)})")
1167
+
1168
+
1169
+ def st_envelope(geometry: ExpressionType) -> InstrumentedExpression:
1170
+ """Determines the minimum bounding box of the supplied geometry.
1171
+
1172
+ :param geometry: Expression of type `geo_point`, `geo_shape`,
1173
+ `cartesian_point` or `cartesian_shape`. If `null`, the function
1174
+ returns `null`.
1175
+ """
1176
+ return InstrumentedExpression(f"ST_ENVELOPE({_render(geometry)})")
1177
+
1178
+
1179
+ def st_extent_agg(field: ExpressionType) -> InstrumentedExpression:
1180
+ """Calculate the spatial extent over a field with geometry type. Returns a
1181
+ bounding box for all values of the field.
1182
+
1183
+ :param field:
1184
+ """
1185
+ return InstrumentedExpression(f"ST_EXTENT_AGG({_render(field)})")
1186
+
1187
+
1188
+ def st_geohash(
1189
+ geometry: ExpressionType, precision: ExpressionType, bounds: ExpressionType = None
1190
+ ) -> InstrumentedExpression:
1191
+ """Calculates the `geohash` of the supplied geo_point at the specified
1192
+ precision. The result is long encoded. Use ST_GEOHASH_TO_STRING to convert
1193
+ the result to a string. These functions are related to the `geo_grid`
1194
+ query and the `geohash_grid` aggregation.
1195
+
1196
+ :param geometry: Expression of type `geo_point`. If `null`, the function
1197
+ returns `null`.
1198
+ :param precision: Expression of type `integer`. If `null`, the function
1199
+ returns `null`. Valid values are between 1 and 12.
1200
+ :param bounds: Optional bounds to filter the grid tiles, a `geo_shape` of
1201
+ type `BBOX`. Use `ST_ENVELOPE` if the `geo_shape` is of any
1202
+ other type.
1203
+ """
1204
+ if bounds is not None:
1205
+ return InstrumentedExpression(
1206
+ f"ST_GEOHASH({_render(geometry)}, {_render(precision)}, {_render(bounds)})"
1207
+ )
1208
+ else:
1209
+ return InstrumentedExpression(
1210
+ f"ST_GEOHASH({_render(geometry)}, {_render(precision)})"
1211
+ )
1212
+
1213
+
1214
+ def st_geohash_to_long(grid_id: ExpressionType) -> InstrumentedExpression:
1215
+ """Converts an input value representing a geohash grid-ID in string format
1216
+ into a long.
1217
+
1218
+ :param grid_id: Input geohash grid-id. The input can be a single- or
1219
+ multi-valued column or an expression.
1220
+ """
1221
+ return InstrumentedExpression(f"ST_GEOHASH_TO_LONG({_render(grid_id)})")
1222
+
1223
+
1224
+ def st_geohash_to_string(grid_id: ExpressionType) -> InstrumentedExpression:
1225
+ """Converts an input value representing a geohash grid-ID in long format
1226
+ into a string.
1227
+
1228
+ :param grid_id: Input geohash grid-id. The input can be a single- or
1229
+ multi-valued column or an expression.
1230
+ """
1231
+ return InstrumentedExpression(f"ST_GEOHASH_TO_STRING({_render(grid_id)})")
1232
+
1233
+
1234
+ def st_geohex(
1235
+ geometry: ExpressionType, precision: ExpressionType, bounds: ExpressionType = None
1236
+ ) -> InstrumentedExpression:
1237
+ """Calculates the `geohex`, the H3 cell-id, of the supplied geo_point at
1238
+ the specified precision. The result is long encoded. Use
1239
+ ST_GEOHEX_TO_STRING to convert the result to a string. These functions are
1240
+ related to the `geo_grid` query and the `geohex_grid` aggregation.
1241
+
1242
+ :param geometry: Expression of type `geo_point`. If `null`, the function
1243
+ returns `null`.
1244
+ :param precision: Expression of type `integer`. If `null`, the function
1245
+ returns `null`. Valid values are between 0 and 15.
1246
+ :param bounds: Optional bounds to filter the grid tiles, a `geo_shape` of
1247
+ type `BBOX`. Use `ST_ENVELOPE` if the `geo_shape`
1248
+ is of any other type.
1249
+ """
1250
+ if bounds is not None:
1251
+ return InstrumentedExpression(
1252
+ f"ST_GEOHEX({_render(geometry)}, {_render(precision)}, {_render(bounds)})"
1253
+ )
1254
+ else:
1255
+ return InstrumentedExpression(
1256
+ f"ST_GEOHEX({_render(geometry)}, {_render(precision)})"
1257
+ )
1258
+
1259
+
1260
+ def st_geohex_to_long(grid_id: ExpressionType) -> InstrumentedExpression:
1261
+ """Converts an input value representing a geohex grid-ID in string format
1262
+ into a long.
1263
+
1264
+ :param grid_id: Input geohex grid-id. The input can be a single- or
1265
+ multi-valued column or an expression.
1266
+ """
1267
+ return InstrumentedExpression(f"ST_GEOHEX_TO_LONG({_render(grid_id)})")
1268
+
1269
+
1270
+ def st_geohex_to_string(grid_id: ExpressionType) -> InstrumentedExpression:
1271
+ """Converts an input value representing a Geohex grid-ID in long format
1272
+ into a string.
1273
+
1274
+ :param grid_id: Input Geohex grid-id. The input can be a single- or
1275
+ multi-valued column or an expression.
1276
+ """
1277
+ return InstrumentedExpression(f"ST_GEOHEX_TO_STRING({_render(grid_id)})")
1278
+
1279
+
1280
+ def st_geotile(
1281
+ geometry: ExpressionType, precision: ExpressionType, bounds: ExpressionType = None
1282
+ ) -> InstrumentedExpression:
1283
+ """Calculates the `geotile` of the supplied geo_point at the specified
1284
+ precision. The result is long encoded. Use ST_GEOTILE_TO_STRING to convert
1285
+ the result to a string. These functions are related to the `geo_grid`
1286
+ query and the `geotile_grid` aggregation.
1287
+
1288
+ :param geometry: Expression of type `geo_point`. If `null`, the function
1289
+ returns `null`.
1290
+ :param precision: Expression of type `integer`. If `null`, the function
1291
+ returns `null`. Valid values are between 0 and 29.
1292
+ :param bounds: Optional bounds to filter the grid tiles, a `geo_shape` of
1293
+ type `BBOX`. Use `ST_ENVELOPE` if the `geo_shape` is of any
1294
+ other type.
1295
+ """
1296
+ if bounds is not None:
1297
+ return InstrumentedExpression(
1298
+ f"ST_GEOTILE({_render(geometry)}, {_render(precision)}, {_render(bounds)})"
1299
+ )
1300
+ else:
1301
+ return InstrumentedExpression(
1302
+ f"ST_GEOTILE({_render(geometry)}, {_render(precision)})"
1303
+ )
1304
+
1305
+
1306
+ def st_geotile_to_long(grid_id: ExpressionType) -> InstrumentedExpression:
1307
+ """Converts an input value representing a geotile grid-ID in string format
1308
+ into a long.
1309
+
1310
+ :param grid_id: Input geotile grid-id. The input can be a single- or
1311
+ multi-valued column or an expression.
1312
+ """
1313
+ return InstrumentedExpression(f"ST_GEOTILE_TO_LONG({_render(grid_id)})")
1314
+
1315
+
1316
+ def st_geotile_to_string(grid_id: ExpressionType) -> InstrumentedExpression:
1317
+ """Converts an input value representing a geotile grid-ID in long format
1318
+ into a string.
1319
+
1320
+ :param grid_id: Input geotile grid-id. The input can be a single- or
1321
+ multi-valued column or an expression.
1322
+ """
1323
+ return InstrumentedExpression(f"ST_GEOTILE_TO_STRING({_render(grid_id)})")
1324
+
1325
+
1326
+ def st_intersects(
1327
+ geom_a: ExpressionType, geom_b: ExpressionType
1328
+ ) -> InstrumentedExpression:
1329
+ """Returns true if two geometries intersect. They intersect if they have
1330
+ any point in common, including their interior points (points along lines or
1331
+ within polygons). This is the inverse of the ST_DISJOINT function. In
1332
+ mathematical terms: ST_Intersects(A, B) ⇔ A ⋂ B ≠ ∅
1333
+
1334
+ :param geom_a: Expression of type `geo_point`, `cartesian_point`,
1335
+ `geo_shape` or `cartesian_shape`. If `null`, the function returns
1336
+ `null`.
1337
+ :param geom_b: Expression of type `geo_point`, `cartesian_point`, `geo_shape`
1338
+ or `cartesian_shape`. If `null`, the function returns `null`. The
1339
+ second parameter must also have the same coordinate system as the
1340
+ first. This means it is not possible to combine `geo_*` and
1341
+ `cartesian_*` parameters.
1342
+ """
1343
+ return InstrumentedExpression(
1344
+ f"ST_INTERSECTS({_render(geom_a)}, {_render(geom_b)})"
1345
+ )
1346
+
1347
+
1348
+ def st_within(geom_a: ExpressionType, geom_b: ExpressionType) -> InstrumentedExpression:
1349
+ """Returns whether the first geometry is within the second geometry. This
1350
+ is the inverse of the ST_CONTAINS function.
1351
+
1352
+ :param geom_a: Expression of type `geo_point`, `cartesian_point`,
1353
+ `geo_shape` or `cartesian_shape`. If `null`, the function returns
1354
+ `null`.
1355
+ :param geom_b: Expression of type `geo_point`, `cartesian_point`, `geo_shape`
1356
+ or `cartesian_shape`. If `null`, the function returns `null`. The
1357
+ second parameter must also have the same coordinate system as the
1358
+ first. This means it is not possible to combine `geo_*` and
1359
+ `cartesian_*` parameters.
1360
+ """
1361
+ return InstrumentedExpression(f"ST_WITHIN({_render(geom_a)}, {_render(geom_b)})")
1362
+
1363
+
1364
+ def st_x(point: ExpressionType) -> InstrumentedExpression:
1365
+ """Extracts the `x` coordinate from the supplied point. If the points is of
1366
+ type `geo_point` this is equivalent to extracting the `longitude` value.
1367
+
1368
+ :param point: Expression of type `geo_point` or `cartesian_point`. If
1369
+ `null`, the function returns `null`.
1370
+ """
1371
+ return InstrumentedExpression(f"ST_X({_render(point)})")
1372
+
1373
+
1374
+ def st_xmax(point: ExpressionType) -> InstrumentedExpression:
1375
+ """Extracts the maximum value of the `x` coordinates from the supplied
1376
+ geometry. If the geometry is of type `geo_point` or `geo_shape` this is
1377
+ equivalent to extracting the maximum `longitude` value.
1378
+
1379
+ :param point: Expression of type `geo_point`, `geo_shape`, `cartesian_point`
1380
+ or `cartesian_shape`. If `null`, the function returns `null`.
1381
+ """
1382
+ return InstrumentedExpression(f"ST_XMAX({_render(point)})")
1383
+
1384
+
1385
+ def st_xmin(point: ExpressionType) -> InstrumentedExpression:
1386
+ """Extracts the minimum value of the `x` coordinates from the supplied
1387
+ geometry. If the geometry is of type `geo_point` or `geo_shape` this is
1388
+ equivalent to extracting the minimum `longitude` value.
1389
+
1390
+ :param point: Expression of type `geo_point`, `geo_shape`, `cartesian_point`
1391
+ or `cartesian_shape`. If `null`, the function returns `null`.
1392
+ """
1393
+ return InstrumentedExpression(f"ST_XMIN({_render(point)})")
1394
+
1395
+
1396
+ def st_y(point: ExpressionType) -> InstrumentedExpression:
1397
+ """Extracts the `y` coordinate from the supplied point. If the points is of
1398
+ type `geo_point` this is equivalent to extracting the `latitude` value.
1399
+
1400
+ :param point: Expression of type `geo_point` or `cartesian_point`. If
1401
+ `null`, the function returns `null`.
1402
+ """
1403
+ return InstrumentedExpression(f"ST_Y({_render(point)})")
1404
+
1405
+
1406
+ def st_ymax(point: ExpressionType) -> InstrumentedExpression:
1407
+ """Extracts the maximum value of the `y` coordinates from the supplied
1408
+ geometry. If the geometry is of type `geo_point` or `geo_shape` this is
1409
+ equivalent to extracting the maximum `latitude` value.
1410
+
1411
+ :param point: Expression of type `geo_point`, `geo_shape`, `cartesian_point`
1412
+ or `cartesian_shape`. If `null`, the function returns `null`.
1413
+ """
1414
+ return InstrumentedExpression(f"ST_YMAX({_render(point)})")
1415
+
1416
+
1417
+ def st_ymin(point: ExpressionType) -> InstrumentedExpression:
1418
+ """Extracts the minimum value of the `y` coordinates from the supplied
1419
+ geometry. If the geometry is of type `geo_point` or `geo_shape` this is
1420
+ equivalent to extracting the minimum `latitude` value.
1421
+
1422
+ :param point: Expression of type `geo_point`, `geo_shape`, `cartesian_point`
1423
+ or `cartesian_shape`. If `null`, the function returns `null`.
1424
+ """
1425
+ return InstrumentedExpression(f"ST_YMIN({_render(point)})")
1426
+
1427
+
1428
+ def substring(
1429
+ string: ExpressionType, start: ExpressionType, length: ExpressionType = None
1430
+ ) -> InstrumentedExpression:
1431
+ """Returns a substring of a string, specified by a start position and an
1432
+ optional length.
1433
+
1434
+ :param string: String expression. If `null`, the function returns `null`.
1435
+ :param start: Start position.
1436
+ :param length: Length of the substring from the start position. Optional; if
1437
+ omitted, all positions after `start` are returned.
1438
+ """
1439
+ if length is not None:
1440
+ return InstrumentedExpression(
1441
+ f"SUBSTRING({_render(string)}, {_render(start)}, {_render(length)})"
1442
+ )
1443
+ else:
1444
+ return InstrumentedExpression(f"SUBSTRING({_render(string)}, {_render(start)})")
1445
+
1446
+
1447
+ def sum(number: ExpressionType) -> InstrumentedExpression:
1448
+ """The sum of a numeric expression.
1449
+
1450
+ :param number:
1451
+ """
1452
+ return InstrumentedExpression(f"SUM({_render(number)})")
1453
+
1454
+
1455
+ def tan(angle: ExpressionType) -> InstrumentedExpression:
1456
+ """Returns the tangent of an angle.
1457
+
1458
+ :param angle: An angle, in radians. If `null`, the function returns `null`.
1459
+ """
1460
+ return InstrumentedExpression(f"TAN({_render(angle)})")
1461
+
1462
+
1463
+ def tanh(number: ExpressionType) -> InstrumentedExpression:
1464
+ """Returns the hyperbolic tangent of a number.
1465
+
1466
+ :param number: Numeric expression. If `null`, the function returns `null`.
1467
+ """
1468
+ return InstrumentedExpression(f"TANH({_render(number)})")
1469
+
1470
+
1471
+ def tau() -> InstrumentedExpression:
1472
+ """Returns the ratio of a circle’s circumference to its radius."""
1473
+ return InstrumentedExpression("TAU()")
1474
+
1475
+
1476
+ def term(field: ExpressionType, query: ExpressionType) -> InstrumentedExpression:
1477
+ """Performs a Term query on the specified field. Returns true if the
1478
+ provided term matches the row.
1479
+
1480
+ :param field: Field that the query will target.
1481
+ :param query: Term you wish to find in the provided field.
1482
+ """
1483
+ return InstrumentedExpression(f"TERM({_render(field)}, {_render(query)})")
1484
+
1485
+
1486
+ def top(
1487
+ field: ExpressionType, limit: ExpressionType, order: ExpressionType
1488
+ ) -> InstrumentedExpression:
1489
+ """Collects the top values for a field. Includes repeated values.
1490
+
1491
+ :param field: The field to collect the top values for.
1492
+ :param limit: The maximum number of values to collect.
1493
+ :param order: The order to calculate the top values. Either `asc` or `desc`.
1494
+ """
1495
+ return InstrumentedExpression(
1496
+ f"TOP({_render(field)}, {_render(limit)}, {_render(order)})"
1497
+ )
1498
+
1499
+
1500
+ def to_aggregate_metric_double(number: ExpressionType) -> InstrumentedExpression:
1501
+ """Encode a numeric to an aggregate_metric_double.
1502
+
1503
+ :param number: Input value. The input can be a single- or multi-valued
1504
+ column or an expression.
1505
+ """
1506
+ return InstrumentedExpression(f"TO_AGGREGATE_METRIC_DOUBLE({_render(number)})")
1507
+
1508
+
1509
+ def to_base64(string: ExpressionType) -> InstrumentedExpression:
1510
+ """Encode a string to a base64 string.
1511
+
1512
+ :param string: A string.
1513
+ """
1514
+ return InstrumentedExpression(f"TO_BASE64({_render(string)})")
1515
+
1516
+
1517
+ def to_boolean(field: ExpressionType) -> InstrumentedExpression:
1518
+ """Converts an input value to a boolean value. A string value of `true`
1519
+ will be case-insensitive converted to the Boolean `true`. For anything
1520
+ else, including the empty string, the function will return `false`. The
1521
+ numerical value of `0` will be converted to `false`, anything else will be
1522
+ converted to `true`.
1523
+
1524
+ :param field: Input value. The input can be a single- or multi-valued column
1525
+ or an expression.
1526
+ """
1527
+ return InstrumentedExpression(f"TO_BOOLEAN({_render(field)})")
1528
+
1529
+
1530
+ def to_cartesianpoint(field: ExpressionType) -> InstrumentedExpression:
1531
+ """Converts an input value to a `cartesian_point` value. A string will only
1532
+ be successfully converted if it respects the WKT Point format.
1533
+
1534
+ :param field: Input value. The input can be a single- or multi-valued column
1535
+ or an expression.
1536
+ """
1537
+ return InstrumentedExpression(f"TO_CARTESIANPOINT({_render(field)})")
1538
+
1539
+
1540
+ def to_cartesianshape(field: ExpressionType) -> InstrumentedExpression:
1541
+ """Converts an input value to a `cartesian_shape` value. A string will only
1542
+ be successfully converted if it respects the WKT format.
1543
+
1544
+ :param field: Input value. The input can be a single- or multi-valued column
1545
+ or an expression.
1546
+ """
1547
+ return InstrumentedExpression(f"TO_CARTESIANSHAPE({_render(field)})")
1548
+
1549
+
1550
+ def to_dateperiod(field: ExpressionType) -> InstrumentedExpression:
1551
+ """Converts an input value into a `date_period` value.
1552
+
1553
+ :param field: Input value. The input is a valid constant date period expression.
1554
+ """
1555
+ return InstrumentedExpression(f"TO_DATEPERIOD({_render(field)})")
1556
+
1557
+
1558
+ def to_datetime(field: ExpressionType) -> InstrumentedExpression:
1559
+ """Converts an input value to a date value. A string will only be
1560
+ successfully converted if it’s respecting the format
1561
+ `yyyy-MM-dd'T'HH:mm:ss.SSS'Z'`. To convert dates in other formats, use `DATE_PARSE`.
1562
+
1563
+ :param field: Input value. The input can be a single- or multi-valued column
1564
+ or an expression.
1565
+ """
1566
+ return InstrumentedExpression(f"TO_DATETIME({_render(field)})")
1567
+
1568
+
1569
+ def to_date_nanos(field: ExpressionType) -> InstrumentedExpression:
1570
+ """Converts an input to a nanosecond-resolution date value (aka date_nanos).
1571
+
1572
+ :param field: Input value. The input can be a single- or multi-valued column
1573
+ or an expression.
1574
+ """
1575
+ return InstrumentedExpression(f"TO_DATE_NANOS({_render(field)})")
1576
+
1577
+
1578
+ def to_degrees(number: ExpressionType) -> InstrumentedExpression:
1579
+ """Converts a number in radians to degrees).
1580
+
1581
+ :param number: Input value. The input can be a single- or multi-valued
1582
+ column or an expression.
1583
+ """
1584
+ return InstrumentedExpression(f"TO_DEGREES({_render(number)})")
1585
+
1586
+
1587
+ def to_double(field: ExpressionType) -> InstrumentedExpression:
1588
+ """Converts an input value to a double value. If the input parameter is of
1589
+ a date type, its value will be interpreted as milliseconds since the Unix
1590
+ epoch, converted to double. Boolean `true` will be converted to double
1591
+ `1.0`, `false` to `0.0`.
1592
+
1593
+ :param field: Input value. The input can be a single- or multi-valued column
1594
+ or an expression.
1595
+ """
1596
+ return InstrumentedExpression(f"TO_DOUBLE({_render(field)})")
1597
+
1598
+
1599
+ def to_geopoint(field: ExpressionType) -> InstrumentedExpression:
1600
+ """Converts an input value to a `geo_point` value. A string will only be
1601
+ successfully converted if it respects the WKT Point format.
1602
+
1603
+ :param field: Input value. The input can be a single- or multi-valued column
1604
+ or an expression.
1605
+ """
1606
+ return InstrumentedExpression(f"TO_GEOPOINT({_render(field)})")
1607
+
1608
+
1609
+ def to_geoshape(field: ExpressionType) -> InstrumentedExpression:
1610
+ """Converts an input value to a `geo_shape` value. A string will only be
1611
+ successfully converted if it respects the WKT format.
1612
+
1613
+ :param field: Input value. The input can be a single- or multi-valued column
1614
+ or an expression.
1615
+ """
1616
+ return InstrumentedExpression(f"TO_GEOSHAPE({_render(field)})")
1617
+
1618
+
1619
+ def to_integer(field: ExpressionType) -> InstrumentedExpression:
1620
+ """Converts an input value to an integer value. If the input parameter is
1621
+ of a date type, its value will be interpreted as milliseconds since the
1622
+ Unix epoch, converted to integer. Boolean `true` will be converted to
1623
+ integer `1`, `false` to `0`.
1624
+
1625
+ :param field: Input value. The input can be a single- or multi-valued column
1626
+ or an expression.
1627
+ """
1628
+ return InstrumentedExpression(f"TO_INTEGER({_render(field)})")
1629
+
1630
+
1631
+ def to_ip(
1632
+ field: ExpressionType, options: ExpressionType = None
1633
+ ) -> InstrumentedExpression:
1634
+ """Converts an input string to an IP value.
1635
+
1636
+ :param field: Input value. The input can be a single- or multi-valued column
1637
+ or an expression.
1638
+ :param options: (Optional) Additional options.
1639
+ """
1640
+ if options is not None:
1641
+ return InstrumentedExpression(f"TO_IP({_render(field)}, {_render(options)})")
1642
+ else:
1643
+ return InstrumentedExpression(f"TO_IP({_render(field)})")
1644
+
1645
+
1646
+ def to_long(field: ExpressionType) -> InstrumentedExpression:
1647
+ """Converts an input value to a long value. If the input parameter is of a
1648
+ date type, its value will be interpreted as milliseconds since the Unix
1649
+ epoch, converted to long. Boolean `true` will be converted to long `1`,
1650
+ `false` to `0`.
1651
+
1652
+ :param field: Input value. The input can be a single- or multi-valued column
1653
+ or an expression.
1654
+ """
1655
+ return InstrumentedExpression(f"TO_LONG({_render(field)})")
1656
+
1657
+
1658
+ def to_lower(str: ExpressionType) -> InstrumentedExpression:
1659
+ """Returns a new string representing the input string converted to lower case.
1660
+
1661
+ :param str: String expression. If `null`, the function returns `null`. The
1662
+ input can be a single-valued column or expression, or a multi-valued
1663
+ column or expression.
1664
+ """
1665
+ return InstrumentedExpression(f"TO_LOWER({_render(str)})")
1666
+
1667
+
1668
+ def to_radians(number: ExpressionType) -> InstrumentedExpression:
1669
+ """Converts a number in degrees) to radians.
1670
+
1671
+ :param number: Input value. The input can be a single- or multi-valued
1672
+ column or an expression.
1673
+ """
1674
+ return InstrumentedExpression(f"TO_RADIANS({_render(number)})")
1675
+
1676
+
1677
+ def to_string(field: ExpressionType) -> InstrumentedExpression:
1678
+ """Converts an input value into a string.
1679
+
1680
+ :param field: Input value. The input can be a single- or multi-valued column
1681
+ or an expression.
1682
+ """
1683
+ return InstrumentedExpression(f"TO_STRING({_render(field)})")
1684
+
1685
+
1686
+ def to_timeduration(field: ExpressionType) -> InstrumentedExpression:
1687
+ """Converts an input value into a `time_duration` value.
1688
+
1689
+ :param field: Input value. The input is a valid constant time duration expression.
1690
+ """
1691
+ return InstrumentedExpression(f"TO_TIMEDURATION({_render(field)})")
1692
+
1693
+
1694
+ def to_unsigned_long(field: ExpressionType) -> InstrumentedExpression:
1695
+ """Converts an input value to an unsigned long value. If the input
1696
+ parameter is of a date type, its value will be interpreted as milliseconds
1697
+ since the Unix epoch, converted to unsigned long. Boolean `true` will be
1698
+ converted to unsigned long `1`, `false` to `0`.
1699
+
1700
+ :param field: Input value. The input can be a single- or multi-valued column
1701
+ or an expression.
1702
+ """
1703
+ return InstrumentedExpression(f"TO_UNSIGNED_LONG({_render(field)})")
1704
+
1705
+
1706
+ def to_upper(str: ExpressionType) -> InstrumentedExpression:
1707
+ """Returns a new string representing the input string converted to upper case.
1708
+
1709
+ :param str: String expression. If `null`, the function returns `null`. The
1710
+ input can be a single-valued column or expression, or a multi-valued
1711
+ column or expression.
1712
+ """
1713
+ return InstrumentedExpression(f"TO_UPPER({_render(str)})")
1714
+
1715
+
1716
+ def to_version(field: ExpressionType) -> InstrumentedExpression:
1717
+ """Converts an input string to a version value.
1718
+
1719
+ :param field: Input value. The input can be a single- or multi-valued column
1720
+ or an expression.
1721
+ """
1722
+ return InstrumentedExpression(f"TO_VERSION({_render(field)})")
1723
+
1724
+
1725
+ def trim(string: ExpressionType) -> InstrumentedExpression:
1726
+ """Removes leading and trailing whitespaces from a string.
1727
+
1728
+ :param string: String expression. If `null`, the function returns `null`.
1729
+ """
1730
+ return InstrumentedExpression(f"TRIM({_render(string)})")
1731
+
1732
+
1733
+ def values(field: ExpressionType) -> InstrumentedExpression:
1734
+ """Returns unique values as a multivalued field. The order of the returned
1735
+ values isn’t guaranteed. If you need the values returned in order use `MV_SORT`.
1736
+
1737
+ :param field:
1738
+ """
1739
+ return InstrumentedExpression(f"VALUES({_render(field)})")
1740
+
1741
+
1742
+ def weighted_avg(
1743
+ number: ExpressionType, weight: ExpressionType
1744
+ ) -> InstrumentedExpression:
1745
+ """The weighted average of a numeric expression.
1746
+
1747
+ :param number: A numeric value.
1748
+ :param weight: A numeric weight.
1749
+ """
1750
+ return InstrumentedExpression(f"WEIGHTED_AVG({_render(number)}, {_render(weight)})")