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    }
190
191
192class Sign(Expression, Func):
193    _sql_names = ["SIGN", "SIGNUM"]
194
195
196class Sqrt(Expression, Func):
197    pass
198
199
200class Trunc(Expression, Func):
201    arg_types = {"this": True, "decimals": False, "fractions_supported": False}
202    _sql_names = ["TRUNC", "TRUNCATE"]
203
204
205# Safe arithmetic
206
207
208class SafeAdd(Expression, Func):
209    arg_types = {"this": True, "expression": True}
210
211
212class SafeDivide(Expression, Func):
213    arg_types = {"this": True, "expression": True}
214
215
216class SafeMultiply(Expression, Func):
217    arg_types = {"this": True, "expression": True}
218
219
220class SafeNegate(Expression, Func):
221    pass
222
223
224class SafeSubtract(Expression, Func):
225    arg_types = {"this": True, "expression": True}
226
227
228# Bitwise
229
230
231class BitwiseAndAgg(Expression, AggFunc):
232    pass
233
234
235class BitwiseCount(Expression, Func):
236    pass
237
238
239class BitwiseOrAgg(Expression, AggFunc):
240    pass
241
242
243class BitwiseXorAgg(Expression, AggFunc):
244    pass
245
246
247class BitmapBitPosition(Expression, Func):
248    pass
249
250
251class BitmapBucketNumber(Expression, Func):
252    pass
253
254
255class BitmapConstructAgg(Expression, AggFunc):
256    pass
257
258
259class BitmapCount(Expression, Func):
260    pass
261
262
263class BitmapOrAgg(Expression, AggFunc):
264    pass
265
266
267class Booland(Expression, Func):
268    arg_types = {"this": True, "expression": True, "round_input": False}
269
270
271class Boolnot(Expression, Func):
272    arg_types = {"this": True, "round_input": False}
273
274
275class Boolor(Expression, Func):
276    arg_types = {"this": True, "expression": True, "round_input": False}
277
278
279class BoolxorAgg(Expression, AggFunc):
280    pass
281
282
283class Getbit(Expression, Func):
284    _sql_names = ["GETBIT", "GET_BIT"]
285    # zero_is_msb means the most significant bit is indexed 0
286    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    }
arg_types = {'this': True, 'decimals': False, 'truncate': False, 'casts_non_integer_decimals': False}
key: ClassVar[str] = 'round'
required_args: 't.ClassVar[set[str]]' = {'this'}
193class Sign(Expression, Func):
194    _sql_names = ["SIGN", "SIGNUM"]
key: ClassVar[str] = 'sign'
required_args: 't.ClassVar[set[str]]' = {'this'}
197class Sqrt(Expression, Func):
198    pass
key: ClassVar[str] = 'sqrt'
required_args: 't.ClassVar[set[str]]' = {'this'}
201class Trunc(Expression, Func):
202    arg_types = {"this": True, "decimals": False, "fractions_supported": False}
203    _sql_names = ["TRUNC", "TRUNCATE"]
arg_types = {'this': True, 'decimals': False, 'fractions_supported': False}
key: ClassVar[str] = 'trunc'
required_args: 't.ClassVar[set[str]]' = {'this'}
209class SafeAdd(Expression, Func):
210    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'safeadd'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
213class SafeDivide(Expression, Func):
214    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'safedivide'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
217class SafeMultiply(Expression, Func):
218    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'safemultiply'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
221class SafeNegate(Expression, Func):
222    pass
key: ClassVar[str] = 'safenegate'
required_args: 't.ClassVar[set[str]]' = {'this'}
225class SafeSubtract(Expression, Func):
226    arg_types = {"this": True, "expression": True}
arg_types = {'this': True, 'expression': True}
key: ClassVar[str] = 'safesubtract'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}
232class BitwiseAndAgg(Expression, AggFunc):
233    pass
key: ClassVar[str] = 'bitwiseandagg'
required_args: 't.ClassVar[set[str]]' = {'this'}
236class BitwiseCount(Expression, Func):
237    pass
key: ClassVar[str] = 'bitwisecount'
required_args: 't.ClassVar[set[str]]' = {'this'}
240class BitwiseOrAgg(Expression, AggFunc):
241    pass
key: ClassVar[str] = 'bitwiseoragg'
required_args: 't.ClassVar[set[str]]' = {'this'}
244class BitwiseXorAgg(Expression, AggFunc):
245    pass
key: ClassVar[str] = 'bitwisexoragg'
required_args: 't.ClassVar[set[str]]' = {'this'}
248class BitmapBitPosition(Expression, Func):
249    pass
key: ClassVar[str] = 'bitmapbitposition'
required_args: 't.ClassVar[set[str]]' = {'this'}
class BitmapBucketNumber(sqlglot.expressions.core.Expression, sqlglot.expressions.core.Func):
252class BitmapBucketNumber(Expression, Func):
253    pass
key: ClassVar[str] = 'bitmapbucketnumber'
required_args: 't.ClassVar[set[str]]' = {'this'}
256class BitmapConstructAgg(Expression, AggFunc):
257    pass
key: ClassVar[str] = 'bitmapconstructagg'
required_args: 't.ClassVar[set[str]]' = {'this'}
260class BitmapCount(Expression, Func):
261    pass
key: ClassVar[str] = 'bitmapcount'
required_args: 't.ClassVar[set[str]]' = {'this'}
264class BitmapOrAgg(Expression, AggFunc):
265    pass
key: ClassVar[str] = 'bitmaporagg'
required_args: 't.ClassVar[set[str]]' = {'this'}
268class Booland(Expression, Func):
269    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'}
272class Boolnot(Expression, Func):
273    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'}
276class Boolor(Expression, Func):
277    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'}
280class BoolxorAgg(Expression, AggFunc):
281    pass
key: ClassVar[str] = 'boolxoragg'
required_args: 't.ClassVar[set[str]]' = {'this'}
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}
arg_types = {'this': True, 'expression': True, 'zero_is_msb': False}
key: ClassVar[str] = 'getbit'
required_args: 't.ClassVar[set[str]]' = {'expression', 'this'}