ops.All: fixed_arity(sa.func.bool_and, 1), ops.NotAny: fixed_arity(lambda x: sa.not_(sa.func.bool_or(x)), 1), ops.NotAll: fixed_arity(lambda x: sa.not_(sa.func.bool_and(x)), 1), # strings ops.Substring: _substr, ops.StrRight: fixed_arity(sa.func.right, 2), ops.StringFind: _string_find, ops.StringLength: unary('length'), ops.GroupConcat: _string_agg, ops.Lowercase: unary('lower'), ops.Uppercase: unary('upper'), ops.Strip: unary('trim'), ops.LStrip: unary('ltrim'), ops.RStrip: unary('rtrim'), ops.LPad: fixed_arity('lpad', 3), ops.RPad:
# We override this here to support time zones ops.TableColumn: _table_column, # 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), ops.RegexSearch: infix_op('~'), ops.RegexReplace: _regex_replace, ops.Translate: fixed_arity('translate', 3), ops.RegexExtract: _regex_extract, ops.StringSplit: fixed_arity(sa.func.string_to_array, 2), ops.StringJoin: _string_join,
ops.ExtractYear: _strftime_int('%Y'), ops.ExtractMonth: _strftime_int('%m'), ops.ExtractDay: _strftime_int('%d'), 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:
# 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, # 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:
ops.Greatest: varargs(sa.func.greatest), # null handling ops.IfNull: fixed_arity(sa.func.coalesce, 2), # boolean reductions ops.Any: fixed_arity(sa.func.bool_or, 1), ops.All: fixed_arity(sa.func.bool_and, 1), ops.NotAny: fixed_arity(lambda x: sa.not_(sa.func.bool_or(x)), 1), ops.NotAll: fixed_arity(lambda x: sa.not_(sa.func.bool_and(x)), 1), # strings ops.Substring: _substr, ops.StrRight: fixed_arity(sa.func.right, 2), ops.StringFind: _string_find, ops.StringLength: unary('length'), ops.GroupConcat: _string_agg, ops.Lowercase: unary('lower'), ops.Uppercase: unary('upper'), ops.Strip: unary('trim'), ops.LStrip: unary('ltrim'), ops.RStrip: unary('rtrim'), ops.LPad: fixed_arity('lpad', 3), ops.RPad: fixed_arity('rpad', 3), ops.Reverse: unary('reverse'), ops.Capitalize: unary('initcap'), ops.Repeat: fixed_arity('repeat', 2), ops.StringReplace: fixed_arity(sa.func.replace, 3), ops.StringSQLLike: _infix_op('LIKE'), ops.RegexSearch: _infix_op('~'), ops.RegexReplace: _regex_replace,
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),
if isinstance(value, pd.Timestamp): value = value.to_pydatetime() return sa.literal(value) _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, # 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.ExtractYear: _extract('year'),
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.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:
def _extract(period): def extractor(t, expr): arg, = expr.op().args sa_arg = t.translate(arg) return sa.cast(sa.func.extract(period, sa_arg), sa.INTEGER) return extractor operation_registry = alch._operation_registry.copy() operation_registry.update({ ops.Negate: _negate, ops.ExtractYear: _extract("YEAR"), ops.ExtractMonth: _extract("MONTH"), ops.ExtractDay: _extract("DAY"), ops.ExtractHour: _extract("HOUR"), ops.ExtractMinute: _extract("MINUTE"), ops.ExtractSecond: _extract("SECOND"), ops.ExtractMillisecond: _extract("MILLISECOND"), ops.TimestampNow: _now, ops.Uppercase: unary("UPPER"), ops.Lowercase: unary("LOWER"), ops.Strip: unary('TRIM'), ops.LStrip: unary('LTRIM'), ops.RStrip: unary('RTRIM') })
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),
_operation_registry.update( { ops.Literal: _literal, # We override this here to support time zones ops.TableColumn: _table_column, # 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), ops.RegexSearch: infix_op('~'), ops.RegexReplace: _regex_replace, ops.Translate: fixed_arity('translate', 3), ops.RegexExtract: _regex_extract, ops.StringSplit: fixed_arity(sa.func.string_to_array, 2), ops.StringJoin: _string_join, ops.FindInSet: _find_in_set,
def _millisecond(t, expr): arg, = expr.op().args sa_arg = t.translate(arg) fractional_second = sa.func.strftime('%f', sa_arg) return (fractional_second * 1000) % 1000 _operation_registry.update({ ops.Cast: _cast, ops.Substring: _substr, ops.StrRight: _string_right, ops.StringFind: _string_find, ops.StringLength: unary('length'), ops.Least: varargs(sa.func.min), ops.Greatest: varargs(sa.func.max), ops.IfNull: fixed_arity(sa.func.ifnull, 2), ops.Lowercase: unary('lower'), ops.Uppercase: unary('upper'), ops.Strip: unary('trim'), ops.LStrip: unary('ltrim'), ops.RStrip: unary('rtrim'), ops.StringReplace: fixed_arity(sa.func.replace, 3), ops.StringSQLLike: _infix_op('LIKE'), ops.RegexSearch: _infix_op('REGEXP'),
_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: