# 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.ExtractYear: _extract('year'), ops.ExtractMonth: _extract('month'), ops.ExtractDay: _extract('day'), ops.ExtractDayOfYear: unary('dayofyear'), ops.ExtractQuarter: _extract('quarter'), ops.ExtractEpochSeconds: unary('UNIX_TIMESTAMP'), ops.ExtractWeekOfYear: fixed_arity('weekofyear', 1), ops.ExtractHour: _extract('hour'),
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.ExtractYear:
# 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:
_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.Atan: unary(sa.func.atan), ops.Ceil: unary(sa.func.ceiling), ops.Cos: unary(sa.func.cos),
def _rpad(t, expr): arg, length, pad = map(t.translate, expr.op().args) return arg + _generic_pad(arg, length, pad) _operation_registry.update( { ops.Cast: _cast, ops.Substring: _substr, ops.StrRight: _string_right, ops.StringFind: _string_find, ops.Least: varargs(sa.func.min), ops.Greatest: varargs(sa.func.max), ops.IfNull: fixed_arity(sa.func.ifnull, 2), ops.DateTruncate: _truncate(sa.func.date), ops.TimestampTruncate: _truncate(sa.func.datetime), ops.Strftime: _strftime, ops.ExtractYear: _strftime_int('%Y'), ops.ExtractMonth: _strftime_int('%m'), ops.ExtractDay: _strftime_int('%d'), 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,
_operation_registry.update({ ops.Cast: _cast, ops.Substring: _substr, ops.StrRight: _string_right, ops.StringFind: _string_find, ops.Least: varargs(sa.func.min), ops.Greatest: varargs(sa.func.max), ops.IfNull: fixed_arity(sa.func.ifnull, 2), ops.DateTruncate: _truncate(sa.func.date), ops.TimestampTruncate: _truncate(sa.func.datetime), ops.Strftime: _strftime, ops.ExtractYear: _strftime_int('%Y'), ops.ExtractMonth: _strftime_int('%m'), ops.ExtractDay: _strftime_int('%d'), ops.ExtractDayOfYear: _strftime_int('%j'), ops.ExtractQuarter:
def _day_of_week_name(t, expr): (sa_arg,) = map(t.translate, expr.op().args) 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,
_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, # 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: