コード例 #1
0
ファイル: compiler.py プロジェクト: tonyfast/ibis
    ops.Strftime: _strftime,
    ops.ExtractYear: _extract('year'),
    ops.ExtractMonth: _extract('month'),
    ops.ExtractDay: _extract('day'),
    ops.ExtractHour: _extract('hour'),
    ops.ExtractMinute: _extract('minute'),
    ops.ExtractSecond: _second,
    ops.ExtractMillisecond: _millisecond,
    ops.DayOfWeekIndex: _day_of_week_index,
    ops.DayOfWeekName: _day_of_week_name,
    ops.Sum: _reduction('sum'),
    ops.Mean: _reduction('avg'),
    ops.Min: _reduction('min'),
    ops.Max: _reduction('max'),
    ops.Variance: _variance_reduction('var'),
    ops.StandardDev: _variance_reduction('stddev'),

    # now is in the timezone of the server, but we want UTC
    ops.TimestampNow: lambda *args: sa.func.timezone('UTC', sa.func.now()),

    ops.CumulativeAll: unary(sa.func.bool_and),
    ops.CumulativeAny: unary(sa.func.bool_or),

    # array operations
    ops.ArrayLength: unary(_cardinality),
    ops.ArrayCollect: unary(sa.func.array_agg),
    ops.ArraySlice: _array_slice,
    ops.ArrayIndex: fixed_arity(lambda array, index: array[index + 1], 2),
    ops.ArrayConcat: fixed_arity(sa.sql.expression.ColumnElement.concat, 2),
    ops.ArrayRepeat: _array_repeat,
コード例 #2
0
    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),
    ops.Variance:
    _variance_reduction('_ibis_sqlite_var'),
    ops.StandardDev:
    toolz.compose(sa.func._ibis_sqlite_sqrt,
                  _variance_reduction('_ibis_sqlite_var')),
})


def add_operation(op, translation_func):
    _operation_registry[op] = translation_func


class SQLiteExprTranslator(alch.AlchemyExprTranslator):

    _registry = _operation_registry
    _rewrites = alch.AlchemyExprTranslator._rewrites.copy()
    _type_map = alch.AlchemyExprTranslator._type_map.copy()
コード例 #3
0
ファイル: compiler.py プロジェクト: cloudera/ibis
        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),
        ops.Variance: _variance_reduction('_ibis_sqlite_var'),
        ops.StandardDev: toolz.compose(
            sa.func._ibis_sqlite_sqrt, _variance_reduction('_ibis_sqlite_var')
        ),
    }
)


def add_operation(op, translation_func):
    _operation_registry[op] = translation_func


class SQLiteExprTranslator(alch.AlchemyExprTranslator):

    _registry = _operation_registry
    _rewrites = alch.AlchemyExprTranslator._rewrites.copy()
コード例 #4
0
ファイル: compiler.py プロジェクト: sestus/ibis
    ops.RegexReplace: fixed_arity(sa.func._ibis_sqlite_regex_replace, 3),
    ops.RegexExtract: fixed_arity(sa.func._ibis_sqlite_regex_extract, 3),

    ops.Sqrt: fixed_arity(sa.func._ibis_sqlite_sqrt, 1),
    ops.Power: fixed_arity(sa.func._ibis_sqlite_power, 2),
    ops.Exp: fixed_arity(sa.func._ibis_sqlite_exp, 1),
    ops.Ln: fixed_arity(sa.func._ibis_sqlite_ln, 1),
    ops.Log: _log,
    ops.Log10: fixed_arity(sa.func._ibis_sqlite_log10, 1),
    ops.Log2: fixed_arity(sa.func._ibis_sqlite_log2, 1),
    ops.Floor: fixed_arity(sa.func._ibis_sqlite_floor, 1),
    ops.Ceil: fixed_arity(sa.func._ibis_sqlite_ceil, 1),
    ops.Sign: fixed_arity(sa.func._ibis_sqlite_sign, 1),
    ops.FloorDivide: fixed_arity(sa.func._ibis_sqlite_floordiv, 2),

    ops.Variance: _variance_reduction('_ibis_sqlite_var'),
    ops.StandardDev: toolz.compose(
        sa.func._ibis_sqlite_sqrt,
        _variance_reduction('_ibis_sqlite_var')
    ),
})


def add_operation(op, translation_func):
    _operation_registry[op] = translation_func


class SQLiteExprTranslator(alch.AlchemyExprTranslator):

    _registry = _operation_registry
    _rewrites = alch.AlchemyExprTranslator._rewrites.copy()
コード例 #5
0
ファイル: compiler.py プロジェクト: djv/ibis
    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
    ops.Variance:
    _variance_reduction('var'),
    ops.StandardDev:
    _variance_reduction('stddev'),
    ops.IdenticalTo:
    _identical_to
})


def add_operation(op, translation_func):
    _operation_registry[op] = translation_func


class MySQLExprTranslator(alch.AlchemyExprTranslator):

    _registry = _operation_registry
    _rewrites = alch.AlchemyExprTranslator._rewrites.copy()
コード例 #6
0
ファイル: compiler.py プロジェクト: cloudera/ibis
 ops.TimestampDiff: infix_op('-'),
 ops.Strftime: _strftime,
 ops.ExtractYear: _extract('year'),
 ops.ExtractMonth: _extract('month'),
 ops.ExtractDay: _extract('day'),
 ops.ExtractHour: _extract('hour'),
 ops.ExtractMinute: _extract('minute'),
 ops.ExtractSecond: _second,
 ops.ExtractMillisecond: _millisecond,
 ops.DayOfWeekIndex: _day_of_week_index,
 ops.DayOfWeekName: _day_of_week_name,
 ops.Sum: _reduction('sum'),
 ops.Mean: _reduction('avg'),
 ops.Min: _reduction('min'),
 ops.Max: _reduction('max'),
 ops.Variance: _variance_reduction('var'),
 ops.StandardDev: _variance_reduction('stddev'),
 # now is in the timezone of the server, but we want UTC
 ops.TimestampNow: lambda *args: sa.func.timezone('UTC', sa.func.now()),
 ops.CumulativeAll: unary(sa.func.bool_and),
 ops.CumulativeAny: unary(sa.func.bool_or),
 # array operations
 ops.ArrayLength: unary(_cardinality),
 ops.ArrayCollect: unary(sa.func.array_agg),
 ops.ArraySlice: _array_slice,
 ops.ArrayIndex: fixed_arity(lambda array, index: array[index + 1], 2),
 ops.ArrayConcat: fixed_arity(
     sa.sql.expression.ColumnElement.concat, 2
 ),
 ops.ArrayRepeat: _array_repeat,
 ops.IdenticalTo: _identical_to,