Esempio n. 1
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),
Esempio n. 2
0
_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.ExtractHour:
    _strftime_int('%H'),
    ops.ExtractMinute:
Esempio n. 3
0
_operation_registry.update({
    # types
    ops.Cast:
    _cast,
    ops.TypeOf:
    _typeof,

    # miscellaneous varargs
    ops.Least:
    varargs(sa.func.least),
    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:
Esempio n. 4
0
        ],
        else_=''
    )


_operation_registry.update({
    # types
    ops.Cast: _cast,
    ops.TypeOf: _typeof,

    # miscellaneous varargs
    ops.Least: varargs(sa.func.least),
    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'),
Esempio n. 5
0

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.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),
Esempio n. 6
0

_operation_registry.update({
    # We override this here to support time zones
    ops.TableColumn: _table_column,

    # types
    ops.Cast: _cast,
    ops.TypeOf: _typeof,

    # miscellaneous varargs
    ops.Least: varargs(sa.func.least),
    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'),
Esempio n. 7
0
    return sa.func._ibis_sqlite_log(sa_arg, t.translate(base))


_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'),

    ops.Strftime: _strftime,
    ops.ExtractYear: _strftime_int('%Y'),
    ops.ExtractMonth: _strftime_int('%m'),
Esempio n. 8
0
 # 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.ExtractHour: _extract('hour'),
 ops.ExtractMinute: _extract('minute'),
 ops.ExtractSecond: _extract('second'),
Esempio n. 9
0
    return sa.func.trim(sa.func.to_char(sa_arg, 'Day'))


_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),
Esempio n. 10
0
    # tie it all together in a scalar subquery and collapse that into an ARRAY
    selected = sa.select([array[index]]).select_from(series)
    return sa.func.array(selected.as_scalar())


_operation_registry.update({
    # types
    ops.Cast: _cast,
    ops.TypeOf: _typeof,

    # miscellaneous varargs
    ops.Least: varargs(sa.func.least),
    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'),
Esempio n. 11
0
    # 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:
Esempio n. 12
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,
 # 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.ExtractHour: _extract('hour'),
 ops.ExtractMinute: _extract('minute'),
 ops.ExtractSecond: _extract('second'),
 ops.ExtractMillisecond: _extract('millisecond'),
 # reductions
Esempio n. 13
0
    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.ExtractMonth: _extract('month'),
    ops.ExtractDay: _extract('day'),
    ops.ExtractHour: _extract('hour'),
    ops.ExtractMinute: _extract('minute'),
    ops.ExtractSecond: _extract('second'),
    ops.ExtractMillisecond: _extract('millisecond'),
Esempio n. 14
0
_operation_registry.update({
    # types
    ops.Cast:
    _cast,
    ops.TypeOf:
    _typeof,

    # miscellaneous varargs
    ops.Least:
    varargs(sa.func.least),
    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:
Esempio n. 15
0
_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),
Esempio n. 16
0
File: compiler.py Progetto: djv/ibis
    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:
Esempio n. 17
0
    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'),

    ops.Strftime: _strftime,
    ops.ExtractYear: _strftime_int('%Y'),
    ops.ExtractMonth: _strftime_int('%m'),
Esempio n. 18
0
 _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