Exemple #1
0
        if isinstance(value, pd.Timestamp):
            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,
Exemple #2
0
 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,
Exemple #3
0
 ops.Translate: fixed_arity('translate', 3),
 ops.RegexExtract: _regex_extract,
 ops.StringJoin: _string_join,
 # 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,
 ops.Power: fixed_arity(sa.func.power, 2),
 # dates and times
 ops.Date: unary(lambda x: sa.cast(x, sa.Date)),
 ops.DateTruncate: _timestamp_truncate,
 ops.TimestampTruncate: _timestamp_truncate,
 ops.IntervalFromInteger: _interval_from_integer,
 ops.DateAdd: infix_op('+'),
 ops.DateSub: infix_op('-'),
 ops.DateDiff: infix_op('-'),
 ops.TimestampAdd: infix_op('+'),
 ops.TimestampSub: infix_op('-'),
 ops.TimestampDiff: infix_op('-'),
 ops.Strftime: _strftime,
 ops.ExtractYear: _extract('year'),
 ops.ExtractMonth: _extract('month'),
 ops.ExtractDay: _extract('day'),
 #ops.ExtractDayOfYear: _extract('doy'),
 #ops.ExtractQuarter: _extract('quarter'),
 #ops.ExtractEpochSeconds: _extract('epoch', sa.BigInteger),
 ops.ExtractHour: _extract('hour'),
 ops.ExtractMinute: _extract('minute'),
 ops.ExtractSecond: _second,
Exemple #4
0
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:
Exemple #5
0
        ops.Translate: fixed_arity('translate', 3),
        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,
        ops.TimestampTruncate: _timestamp_truncate,
        ops.IntervalFromInteger: _interval_from_integer,
        ops.DateAdd: alch.infix_op('+'),
        ops.DateSub: alch.infix_op('-'),
        ops.DateDiff: alch.infix_op('-'),
        ops.TimestampAdd: alch.infix_op('+'),
        ops.TimestampSub: alch.infix_op('-'),
        ops.TimestampDiff: alch.infix_op('-'),
        ops.Strftime: _strftime,
        ops.ExtractYear: _extract('year'),
        ops.ExtractMonth: _extract('month'),
        ops.ExtractDay: _extract('day'),
#        ops.ExtractDayOfYear: _extract('doy'),
#        ops.ExtractQuarter: _extract('quarter'),
#        ops.ExtractEpochSeconds: _extract('epoch', sa.BigInteger),
        ops.ExtractHour: _extract('hour'),
        ops.ExtractMinute: _extract('minute'),
        ops.ExtractSecond: _second,