Esempio n. 1
0
    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:
Esempio n. 2
0
    # 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,
Esempio n. 3
0
 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),
Esempio n. 4
0
 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:
Esempio n. 5
0
File: compiler.py Progetto: djv/ibis
    # 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:
Esempio n. 6
0
    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,
Esempio n. 7
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: 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),
Esempio n. 8
0
        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'),
Esempio n. 9
0
 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),
Esempio n. 10
0
    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:
Esempio n. 11
0
    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,
Esempio n. 12
0

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')
})
Esempio n. 13
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: 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),
Esempio n. 14
0
    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),
Esempio n. 15
0
_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,
Esempio n. 16
0
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'),
Esempio n. 17
0
_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: