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