def _random(t, expr): return sa.func.random() _operation_registry.update({ ops.Literal: _literal, # strings ops.Substring: _substr, ops.StringFind: _string_find, ops.Capitalize: _capitalize, ops.RegexSearch: infix_op('REGEXP'), # math ops.Log: _log, ops.Log2: unary(sa.func.log2), ops.Log10: unary(sa.func.log10), ops.Round: _round, ops.RandomScalar: _random, # dates and times ops.Date: unary(sa.func.date), ops.DateAdd: infix_op('+'), ops.DateSub: infix_op('-'), ops.DateDiff: fixed_arity(sa.func.datediff, 2), ops.TimestampAdd: infix_op('+'), ops.TimestampSub: infix_op('-'), ops.TimestampDiff: _timestamp_diff, ops.DateTruncate: _truncate, ops.TimestampTruncate: _truncate, ops.IntervalFromInteger: _interval_from_integer, ops.Strftime: fixed_arity(sa.func.date_format, 2),
ops.Literal: _literal, # strings ops.Substring: _substr, ops.StringFind: _string_find, ops.Capitalize: _capitalize, ops.RegexSearch: infix_op('REGEXP'), # math ops.Log: _log, ops.Log2: unary(sa.func.log2), ops.Log10: unary(sa.func.log10), ops.Round: _round, ops.RandomScalar: _random, # dates and times ops.Date: unary(sa.func.date), ops.DateAdd: infix_op('+'), ops.DateSub: infix_op('-'), ops.DateDiff: fixed_arity(sa.func.datediff, 2),
# types ops.Cast: _cast, ops.TypeOf: _typeof, # Floating ops.IsNan: _is_nan, ops.IsInf: _is_inf, # null handling ops.IfNull: fixed_arity(sa.func.coalesce, 2), # boolean reductions ops.Any: unary(sa.func.bool_or), ops.All: unary(sa.func.bool_and), ops.NotAny: unary(lambda x: sa.not_(sa.func.bool_or(x))), ops.NotAll: unary(lambda x: sa.not_(sa.func.bool_and(x))), # strings ops.Substring: _substr, ops.StringFind: _string_find, ops.GroupConcat: _string_agg, ops.Capitalize: unary(sa.func.initcap),
return translator _operation_registry = alch._operation_registry.copy() _operation_registry.update( { # aggregate methods ops.Count: _reduction(sa.func.count), ops.Max: _reduction('max'), ops.Min: _reduction('min'), ops.Sum: _reduction('sum'), ops.Mean: _reduction('avg', 'float64'), # string methods ops.LStrip: unary(sa.func.ltrim), ops.Lowercase: unary(sa.func.lower), ops.RStrip: unary(sa.func.rtrim), ops.Repeat: fixed_arity(sa.func.replicate, 2), ops.Reverse: unary(sa.func.reverse), ops.StringFind: _string_find, ops.StringLength: unary(sa.func.length), ops.StringReplace: fixed_arity(sa.func.replace, 3), ops.Strip: unary(sa.func.trim), ops.Substring: _substr, ops.Uppercase: unary(sa.func.upper), # math ops.Abs: unary(sa.func.abs), ops.Acos: unary(sa.func.acos), ops.Asin: unary(sa.func.asin), ops.Atan2: fixed_arity(sa.func.atn2, 2),
ops.ExtractDayOfYear: _strftime_int('%j'), ops.ExtractQuarter: _extract_quarter, ops.ExtractEpochSeconds: _extract_epoch_seconds, ops.ExtractHour: _strftime_int('%H'), ops.ExtractMinute: _strftime_int('%M'), ops.ExtractSecond: _strftime_int('%S'), ops.ExtractMillisecond: _millisecond, ops.TimestampNow: _now, ops.IdenticalTo: _identical_to, ops.RegexSearch: fixed_arity(sa.func._ibis_sqlite_regex_search, 2), ops.RegexReplace: fixed_arity(sa.func._ibis_sqlite_regex_replace, 3), ops.RegexExtract: fixed_arity(sa.func._ibis_sqlite_regex_extract, 3), ops.LPad: _lpad, ops.RPad: _rpad, ops.Repeat: _repeat, ops.Reverse: unary(sa.func._ibis_sqlite_reverse), ops.StringAscii: unary(sa.func._ibis_sqlite_string_ascii), ops.Capitalize: unary(sa.func._ibis_sqlite_capitalize), ops.Translate: fixed_arity(sa.func._ibis_sqlite_translate, 3), ops.Sqrt: unary(sa.func._ibis_sqlite_sqrt), ops.Power: fixed_arity(sa.func._ibis_sqlite_power, 2), ops.Exp: unary(sa.func._ibis_sqlite_exp), ops.Ln: unary(sa.func._ibis_sqlite_ln), ops.Log: _log, ops.Log10: unary(sa.func._ibis_sqlite_log10), ops.Log2: unary(sa.func._ibis_sqlite_log2), ops.Floor: unary(sa.func._ibis_sqlite_floor), ops.Ceil: unary(sa.func._ibis_sqlite_ceil), ops.Sign: unary(sa.func._ibis_sqlite_sign), ops.FloorDivide: fixed_arity(sa.func._ibis_sqlite_floordiv, 2), ops.Modulus: fixed_arity(sa.func._ibis_sqlite_mod, 2),
ops.IdenticalTo: _identical_to, ops.RegexSearch: fixed_arity(sa.func._ibis_sqlite_regex_search, 2), ops.RegexReplace: fixed_arity(sa.func._ibis_sqlite_regex_replace, 3), ops.RegexExtract: fixed_arity(sa.func._ibis_sqlite_regex_extract, 3), ops.LPad: _lpad, ops.RPad: _rpad, ops.Repeat: _repeat, ops.Reverse: unary(sa.func._ibis_sqlite_reverse), ops.StringAscii: unary(sa.func._ibis_sqlite_string_ascii), ops.Capitalize: unary(sa.func._ibis_sqlite_capitalize), ops.Translate: fixed_arity(sa.func._ibis_sqlite_translate, 3), ops.Sqrt: unary(sa.func._ibis_sqlite_sqrt), ops.Power: fixed_arity(sa.func._ibis_sqlite_power, 2), ops.Exp: unary(sa.func._ibis_sqlite_exp), ops.Ln: unary(sa.func._ibis_sqlite_ln), ops.Log:
return sa.func.dayname(sa_arg) _operation_registry.update( { ops.Literal: _literal, ops.TableColumn: _table_column, # types ops.Cast: _cast, # Floating ops.IsNan: _is_nan, ops.IsInf: _is_inf, # null handling ops.IfNull: fixed_arity(sa.func.coalesce, 2), # boolean reductions ops.Any: unary(sa.func.bool_or), ops.All: unary(sa.func.bool_and), ops.NotAny: unary(lambda x: sa.not_(sa.func.bool_or(x))), ops.NotAll: unary(lambda x: sa.not_(sa.func.bool_and(x))), # strings ops.Substring: _substr, ops.StringFind: _string_find, ops.GroupConcat: _string_agg, ops.Capitalize: unary(sa.func.initcap), ops.RegexSearch: fixed_arity(sa.func.REGEXP_INSTR, 2), ops.RegexReplace: _regex_replace, ops.Translate: fixed_arity('translate', 3), ops.RegexExtract: _regex_extract, ops.StringJoin: _string_join, # math ops.Log: _log,
ops.Literal: _literal, # We override this here to support time zones ops.TableColumn: _table_column, # types ops.Cast: _cast, ops.TypeOf: _typeof, # null handling ops.IfNull: fixed_arity(sa.func.coalesce, 2), # boolean reductions ops.Any: unary(sa.func.bool_or), ops.All: unary(sa.func.bool_and), ops.NotAny: unary(lambda x: sa.not_(sa.func.bool_or(x))), ops.NotAll: unary(lambda x: sa.not_(sa.func.bool_and(x))), # strings ops.Substring: _substr, ops.StringFind: _string_find, ops.GroupConcat: _string_agg, ops.Capitalize: unary(sa.func.initcap),