# 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, # math ops.Log: _log, ops.Log2: unary(lambda x: sa.func.log(2, x)), ops.Log10: unary(sa.func.log), ops.Round: _round, ops.Modulus: _mod, # dates and times
return sa.literal(value) _operation_registry.update({ ir.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:
# 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, # math ops.Log: _log, ops.Log2: unary(lambda x: sa.func.log(2, x)), ops.Log10: unary(sa.func.log), ops.Round: _round, ops.Modulus: _mod, # dates and times ops.Date: unary(lambda x: sa.cast(x, sa.Date)), ops.DateTruncate: _timestamp_truncate,
value = value.to_pydatetime() return sa.literal(value) 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.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, # math ops.Log:
def _string_join(t, expr): sep, elements = expr.op().args return sa.func.concat_ws(t.translate(sep), *map(t.translate, elements)) _operation_registry.update({ # 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.DateTruncate: _truncate, ops.TimestampTruncate:
return list(map(sa.literal, expr.op().value)) else: value = expr.op().value 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,