Edit on GitHub

sqlglot expressions - math, trigonometry, and bitwise functions.

  1"""sqlglot expressions - math, trigonometry, and bitwise functions."""
  2
  3from __future__ import annotations
  4
  5from sqlglot.expressions.core import Expression, Func, AggFunc
  6
  7
  8# Trigonometric
  9
 10
 11class Acos(Expression, Func):
 12    pass
 13
 14
 15class Acosh(Expression, Func):
 16    pass
 17
 18
 19class Asin(Expression, Func):
 20    pass
 21
 22
 23class Asinh(Expression, Func):
 24    pass
 25
 26
 27class Atan(Expression, Func):
 28    arg_types = {"this": True, "expression": False}
 29
 30
 31class Atanh(Expression, Func):
 32    pass
 33
 34
 35class Atan2(Expression, Func):
 36    arg_types = {"this": True, "expression": True}
 37
 38
 39class Cos(Expression, Func):
 40    pass
 41
 42
 43class Cosh(Expression, Func):
 44    pass
 45
 46
 47class Cot(Expression, Func):
 48    pass
 49
 50
 51class Coth(Expression, Func):
 52    pass
 53
 54
 55class Csc(Expression, Func):
 56    pass
 57
 58
 59class Csch(Expression, Func):
 60    pass
 61
 62
 63class Degrees(Expression, Func):
 64    pass
 65
 66
 67class Radians(Expression, Func):
 68    pass
 69
 70
 71class Sec(Expression, Func):
 72    pass
 73
 74
 75class Sech(Expression, Func):
 76    pass
 77
 78
 79class Sin(Expression, Func):
 80    pass
 81
 82
 83class Sinh(Expression, Func):
 84    pass
 85
 86
 87class Tan(Expression, Func):
 88    pass
 89
 90
 91class Tanh(Expression, Func):
 92    pass
 93
 94
 95# Geometric distance / similarity
 96
 97
 98class CosineDistance(Expression, Func):
 99    arg_types = {"this": True, "expression": True}
100
101
102class DotProduct(Expression, Func):
103    arg_types = {"this": True, "expression": True}
104
105
106class EuclideanDistance(Expression, Func):
107    arg_types = {"this": True, "expression": True}
108
109
110class JarowinklerSimilarity(Expression, Func):
111    arg_types = {
112        "this": True,
113        "expression": True,
114        "case_insensitive": False,
115        "integer_scale": False,
116    }
117
118
119class ManhattanDistance(Expression, Func):
120    arg_types = {"this": True, "expression": True}
121
122
123# Basic arithmetic / math
124
125
126class Abs(Expression, Func):
127    pass
128
129
130class Cbrt(Expression, Func):
131    pass
132
133
134class Ceil(Expression, Func):
135    arg_types = {"this": True, "decimals": False, "to": False}
136    _sql_names = ["CEIL", "CEILING"]
137
138
139class Exp(Expression, Func):
140    pass
141
142
143class Factorial(Expression, Func):
144    pass
145
146
147class Floor(Expression, Func):
148    arg_types = {"this": True, "decimals": False, "to": False}
149
150
151class IsInf(Expression, Func):
152    _sql_names = ["IS_INF", "ISINF"]
153
154
155class IsNan(Expression, Func):
156    _sql_names = ["IS_NAN", "ISNAN"]
157
158
159class Ln(Expression, Func):
160    pass
161
162
163class Log(Expression, Func):
164    arg_types = {"this": True, "expression": False}
165
166
167class Negative(Expression, Func):
168    pass
169
170
171class Nanvl(Expression, Func):
172    arg_types = {"this": True, "expression": True}
173
174
175class Pi(Expression, Func):
176    arg_types = {}
177
178
179class Rint(Expression, Func):
180    pass
181
182
183class Round(Expression, Func):
184    arg_types = {
185        "this": True,
186        "decimals": False,
187        "truncate": False,
188        "casts_non_integer_decimals": False,
189        "negative_decimals_are_zero": False,
190    }
191
192
193class Sign(Expression, Func):
194    _sql_names = ["SIGN", "SIGNUM"]
195
196
197class Sqrt(Expression, Func):
198    pass
199
200
201class Trunc(Expression, Func):
202    arg_types = {"this": True, "decimals": False, "fractions_supported": False}
203    _sql_names = ["TRUNC", "TRUNCATE"]
204
205
206# Safe arithmetic
207
208
209class SafeAdd(Expression, Func):
210    arg_types = {"this": True, "expression": True}
211
212
213class SafeDivide(Expression, Func):
214    arg_types = {"this": True, "expression": True}
215
216
217class SafeMultiply(Expression, Func):
218    arg_types = {"this": True, "expression": True}
219
220
221class SafeNegate(Expression, Func):
222    pass
223
224
225class SafeSubtract(Expression, Func):
226    arg_types = {"this": True, "expression": True}
227
228
229# Bitwise
230
231
232class BitwiseAndAgg(Expression, AggFunc):
233    pass
234
235
236class BitwiseCount(Expression, Func):
237    pass
238
239
240class BitwiseOrAgg(Expression, AggFunc):
241    pass
242
243
244class BitwiseXorAgg(Expression, AggFunc):
245    pass
246
247
248class BitmapBitPosition(Expression, Func):
249    pass
250
251
252class BitmapBucketNumber(Expression, Func):
253    pass
254
255
256class BitmapConstructAgg(Expression, AggFunc):
257    pass
258
259
260class BitmapCount(Expression, Func):
261    pass
262
263
264class BitmapOrAgg(Expression, AggFunc):
265    pass
266
267
268class Booland(Expression, Func):
269    arg_types = {"this": True, "expression": True, "round_input": False}
270
271
272class Boolnot(Expression, Func):
273    arg_types = {"this": True, "round_input": False}
274
275
276class Boolor(Expression, Func):
277    arg_types = {"this": True, "expression": True, "round_input": False}
278
279
280class BoolxorAgg(Expression, AggFunc):
281    pass
282
283
284class Getbit(Expression, Func):
285    _sql_names = ["GETBIT", "GET_BIT"]
286    # zero_is_msb means the most significant bit is indexed 0
287    arg_types = {"this": True, "expression": True, "zero_is_msb": False}
12class Acos(Expression, Func):
13    pass
key: ClassVar[str] = 'acos'
required_args: 't.ClassVar[set[str]]' = {'this'}
16class Acosh(Expression, Func):
17    pass
key: ClassVar[str] = 'acosh'
required_args: 't.ClassVar[set[str]]' = {'this'}
20class Asin(Expression, Func):
21    pass
key: ClassVar[str] = 'asin'
required_args: 't.ClassVar[set[str]]' = {'this'}
24class Asinh(Expression, Func):
25    pass
key: ClassVar[str] = 'asinh'
required_args: 't.ClassVar[set[str]]' = {'this'}
28class Atan(Expression, Func):
29    arg_types = {"this": True, "expression": False}
arg_types = {'this': True, 'expression': False}
key: ClassVar[str] = 'atan'
required_args: 't.ClassVar[set[str]]' = {'this'}
32class Atanh(Expression, Func):
33    pass
key: ClassVar[str] = 'atanh'
required_args: 't.ClassVar[set[str]]' = {'this'}
36class Atan2(Expression, Func):
37    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'atan2'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
40class Cos(Expression, Func):
41    pass
key: ClassVar[str] = 'cos'
required_args: 't.ClassVar[set[str]]' = {'this'}
44class Cosh(Expression, Func):
45    pass
key: ClassVar[str] = 'cosh'
required_args: 't.ClassVar[set[str]]' = {'this'}
48class Cot(Expression, Func):
49    pass
key: ClassVar[str] = 'cot'
required_args: 't.ClassVar[set[str]]' = {'this'}
52class Coth(Expression, Func):
53    pass
key: ClassVar[str] = 'coth'
required_args: 't.ClassVar[set[str]]' = {'this'}
56class Csc(Expression, Func):
57    pass
key: ClassVar[str] = 'csc'
required_args: 't.ClassVar[set[str]]' = {'this'}
60class Csch(Expression, Func):
61    pass
key: ClassVar[str] = 'csch'
required_args: 't.ClassVar[set[str]]' = {'this'}
64class Degrees(Expression, Func):
65    pass
key: ClassVar[str] = 'degrees'
required_args: 't.ClassVar[set[str]]' = {'this'}
68class Radians(Expression, Func):
69    pass
key: ClassVar[str] = 'radians'
required_args: 't.ClassVar[set[str]]' = {'this'}
72class Sec(Expression, Func):
73    pass
key: ClassVar[str] = 'sec'
required_args: 't.ClassVar[set[str]]' = {'this'}
76class Sech(Expression, Func):
77    pass
key: ClassVar[str] = 'sech'
required_args: 't.ClassVar[set[str]]' = {'this'}
80class Sin(Expression, Func):
81    pass
key: ClassVar[str] = 'sin'
required_args: 't.ClassVar[set[str]]' = {'this'}
84class Sinh(Expression, Func):
85    pass
key: ClassVar[str] = 'sinh'
required_args: 't.ClassVar[set[str]]' = {'this'}
88class Tan(Expression, Func):
89    pass
key: ClassVar[str] = 'tan'
required_args: 't.ClassVar[set[str]]' = {'this'}
92class Tanh(Expression, Func):
93    pass
key: ClassVar[str] = 'tanh'
required_args: 't.ClassVar[set[str]]' = {'this'}
 99class CosineDistance(Expression, Func):
100    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'cosinedistance'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
103class DotProduct(Expression, Func):
104    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'dotproduct'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
107class EuclideanDistance(Expression, Func):
108    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'euclideandistance'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
class JarowinklerSimilarity(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
111class JarowinklerSimilarity(Expression, Func):
112    arg_types = {
113        "this": True,
114        "expression": True,
115        "case_insensitive": False,
116        "integer_scale": False,
117    }
arg_types = {'this': True, 'expression': True, 'case_insensitive': False, 'integer_scale': False}
key: ClassVar[str] = 'jarowinklersimilarity'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
120class ManhattanDistance(Expression, Func):
121    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'manhattandistance'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
127class Abs(Expression, Func):
128    pass
key: ClassVar[str] = 'abs'
required_args: 't.ClassVar[set[str]]' = {'this'}
131class Cbrt(Expression, Func):
132    pass
key: ClassVar[str] = 'cbrt'
required_args: 't.ClassVar[set[str]]' = {'this'}
135class Ceil(Expression, Func):
136    arg_types = {"this": True, "decimals": False, "to": False}
137    _sql_names = ["CEIL", "CEILING"]
arg_types = {'this': True, 'decimals': False, 'to': False}
key: ClassVar[str] = 'ceil'
required_args: 't.ClassVar[set[str]]' = {'this'}
140class Exp(Expression, Func):
141    pass
key: ClassVar[str] = 'exp'
required_args: 't.ClassVar[set[str]]' = {'this'}
144class Factorial(Expression, Func):
145    pass
key: ClassVar[str] = 'factorial'
required_args: 't.ClassVar[set[str]]' = {'this'}
148class Floor(Expression, Func):
149    arg_types = {"this": True, "decimals": False, "to": False}
arg_types = {'this': True, 'decimals': False, 'to': False}
key: ClassVar[str] = 'floor'
required_args: 't.ClassVar[set[str]]' = {'this'}
152class IsInf(Expression, Func):
153    _sql_names = ["IS_INF", "ISINF"]
key: ClassVar[str] = 'isinf'
required_args: 't.ClassVar[set[str]]' = {'this'}
156class IsNan(Expression, Func):
157    _sql_names = ["IS_NAN", "ISNAN"]
key: ClassVar[str] = 'isnan'
required_args: 't.ClassVar[set[str]]' = {'this'}
160class Ln(Expression, Func):
161    pass
key: ClassVar[str] = 'ln'
required_args: 't.ClassVar[set[str]]' = {'this'}
164class Log(Expression, Func):
165    arg_types = {"this": True, "expression": False}
arg_types = {'this': True, 'expression': False}
key: ClassVar[str] = 'log'
required_args: 't.ClassVar[set[str]]' = {'this'}
168class Negative(Expression, Func):
169    pass
key: ClassVar[str] = 'negative'
required_args: 't.ClassVar[set[str]]' = {'this'}
172class Nanvl(Expression, Func):
173    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'nanvl'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
176class Pi(Expression, Func):
177    arg_types = {}
arg_types = {}
key: ClassVar[str] = 'pi'
required_args: 't.ClassVar[set[str]]' = set()
180class Rint(Expression, Func):
181    pass
key: ClassVar[str] = 'rint'
required_args: 't.ClassVar[set[str]]' = {'this'}
184class Round(Expression, Func):
185    arg_types = {
186        "this": True,
187        "decimals": False,
188        "truncate": False,
189        "casts_non_integer_decimals": False,
190        "negative_decimals_are_zero": False,
191    }
arg_types = {'this': True, 'decimals': False, 'truncate': False, 'casts_non_integer_decimals': False, 'negative_decimals_are_zero': False}
key: ClassVar[str] = 'round'
required_args: 't.ClassVar[set[str]]' = {'this'}
194class Sign(Expression, Func):
195    _sql_names = ["SIGN", "SIGNUM"]
key: ClassVar[str] = 'sign'
required_args: 't.ClassVar[set[str]]' = {'this'}
198class Sqrt(Expression, Func):
199    pass
key: ClassVar[str] = 'sqrt'
required_args: 't.ClassVar[set[str]]' = {'this'}
202class Trunc(Expression, Func):
203    arg_types = {"this": True, "decimals": False, "fractions_supported": False}
204    _sql_names = ["TRUNC", "TRUNCATE"]
arg_types = {'this': True, 'decimals': False, 'fractions_supported': False}
key: ClassVar[str] = 'trunc'
required_args: 't.ClassVar[set[str]]' = {'this'}
210class SafeAdd(Expression, Func):
211    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'safeadd'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
214class SafeDivide(Expression, Func):
215    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'safedivide'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
218class SafeMultiply(Expression, Func):
219    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'safemultiply'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
222class SafeNegate(Expression, Func):
223    pass
key: ClassVar[str] = 'safenegate'
required_args: 't.ClassVar[set[str]]' = {'this'}
226class SafeSubtract(Expression, Func):
227    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'safesubtract'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
233class BitwiseAndAgg(Expression, AggFunc):
234    pass
key: ClassVar[str] = 'bitwiseandagg'
required_args: 't.ClassVar[set[str]]' = {'this'}
237class BitwiseCount(Expression, Func):
238    pass
key: ClassVar[str] = 'bitwisecount'
required_args: 't.ClassVar[set[str]]' = {'this'}
241class BitwiseOrAgg(Expression, AggFunc):
242    pass
key: ClassVar[str] = 'bitwiseoragg'
required_args: 't.ClassVar[set[str]]' = {'this'}
245class BitwiseXorAgg(Expression, AggFunc):
246    pass
key: ClassVar[str] = 'bitwisexoragg'
required_args: 't.ClassVar[set[str]]' = {'this'}
249class BitmapBitPosition(Expression, Func):
250    pass
key: ClassVar[str] = 'bitmapbitposition'
required_args: 't.ClassVar[set[str]]' = {'this'}
class BitmapBucketNumber(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
253class BitmapBucketNumber(Expression, Func):
254    pass
key: ClassVar[str] = 'bitmapbucketnumber'
required_args: 't.ClassVar[set[str]]' = {'this'}
257class BitmapConstructAgg(Expression, AggFunc):
258    pass
key: ClassVar[str] = 'bitmapconstructagg'
required_args: 't.ClassVar[set[str]]' = {'this'}
261class BitmapCount(Expression, Func):
262    pass
key: ClassVar[str] = 'bitmapcount'
required_args: 't.ClassVar[set[str]]' = {'this'}
265class BitmapOrAgg(Expression, AggFunc):
266    pass
key: ClassVar[str] = 'bitmaporagg'
required_args: 't.ClassVar[set[str]]' = {'this'}
269class Booland(Expression, Func):
270    arg_types = {"this": True, "expression": True, "round_input": False}
arg_types = {'this': True, 'expression': True, 'round_input': False}
key: ClassVar[str] = 'booland'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
273class Boolnot(Expression, Func):
274    arg_types = {"this": True, "round_input": False}
arg_types = {'this': True, 'round_input': False}
key: ClassVar[str] = 'boolnot'
required_args: 't.ClassVar[set[str]]' = {'this'}
277class Boolor(Expression, Func):
278    arg_types = {"this": True, "expression": True, "round_input": False}
arg_types = {'this': True, 'expression': True, 'round_input': False}
key: ClassVar[str] = 'boolor'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
281class BoolxorAgg(Expression, AggFunc):
282    pass
key: ClassVar[str] = 'boolxoragg'
required_args: 't.ClassVar[set[str]]' = {'this'}
285class Getbit(Expression, Func):
286    _sql_names = ["GETBIT", "GET_BIT"]
287    # zero_is_msb means the most significant bit is indexed 0
288    arg_types = {"this": True, "expression": True, "zero_is_msb": False}
arg_types = {'this': True, 'expression': True, 'zero_is_msb': False}
key: ClassVar[str] = 'getbit'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}