Exemple #1
0
def add_operation(op, func_name, db):
    """
    Registers the given operation within the Ibis SQL translation toolchain

    Parameters
    ----------
    op: operator class
    name: used in issuing statements to SQL engine
    database: database the relevant operator is registered to
    """
    full_name = '{0}.{1}'.format(db, func_name)
    if isinstance(op.input_type, rules.VarArgs):
        translator = comp.varargs(full_name)
    else:
        arity = len(op.input_type.types)
        translator = comp.fixed_arity(full_name, arity)

    comp._operation_registry[op] = translator
Exemple #2
0
def add_operation(op, func_name, db):
    """
    Registers the given operation within the Ibis SQL translation toolchain

    Parameters
    ----------
    op: operator class
    name: used in issuing statements to SQL engine
    database: database the relevant operator is registered to
    """
    full_name = '{0}.{1}'.format(db, func_name)
    if isinstance(op.input_type, rules.VarArgs):
        translator = comp.varargs(full_name)
    else:
        arity = len(op.input_type.types)
        translator = comp.fixed_arity(full_name, arity)

    comp._operation_registry[op] = translator
Exemple #3
0
def add_operation(op, func_name, db):
    """
    Registers the given operation within the Ibis SQL translation toolchain

    Parameters
    ----------
    op: operator class
    name: used in issuing statements to SQL engine
    database: database the relevant operator is registered to
    """
    full_name = '{0}.{1}'.format(db, func_name)
    # TODO
    # if op.input_type is rlz.listof:
    #     translator = comp.varargs(full_name)
    # else:
    arity = len(op.signature)
    translator = comp.fixed_arity(full_name, arity)

    comp._operation_registry[op] = translator
Exemple #4
0
def add_operation(op, func_name, db):
    """
    Registers the given operation within the Ibis SQL translation toolchain

    Parameters
    ----------
    op: operator class
    name: used in issuing statements to SQL engine
    database: database the relevant operator is registered to
    """
    full_name = '{0}.{1}'.format(db, func_name)
    # TODO
    # if op.input_type is rlz.listof:
    #     translator = comp.varargs(full_name)
    # else:
    arity = len(op.signature)
    translator = comp.fixed_arity(full_name, arity)

    comp._operation_registry[op] = translator
Exemple #5
0
        if isinstance(expr, ir.ArrayValue):
            return _array_literal_format(expr)
        raise NotImplementedError(type(expr).__name__)


_operation_registry = impala_compiler._operation_registry.copy()
_operation_registry.update({
    ops.ExtractYear: _extract_field('year'),
    ops.ExtractMonth: _extract_field('month'),
    ops.ExtractDay: _extract_field('day'),
    ops.ExtractHour: _extract_field('hour'),
    ops.ExtractMinute: _extract_field('minute'),
    ops.ExtractSecond: _extract_field('second'),
    ops.ExtractMillisecond: _extract_field('millisecond'),

    ops.StringReplace: fixed_arity('REPLACE', 3),
    ops.StringSplit: fixed_arity('SPLIT', 2),
    ops.StringConcat: _string_concat,
    ops.StringJoin: _string_join,
    ops.StringAscii: _string_ascii,
    ops.StringFind: _string_find,
    ops.StrRight: _string_right,
    ops.Repeat: fixed_arity('REPEAT', 2),
    ops.RegexSearch: _regex_search,
    ops.RegexExtract: _regex_extract,
    ops.RegexReplace: _regex_replace,

    ops.GroupConcat: fixed_arity('STRING_AGG', 2),

    ops.IfNull: fixed_arity('IFNULL', 2),
    ops.Cast: _cast,
Exemple #6
0
 ops.ExtractMonth:
 _extract_field('month'),
 ops.ExtractDay:
 _extract_field('day'),
 ops.ExtractHour:
 _extract_field('hour'),
 ops.ExtractMinute:
 _extract_field('minute'),
 ops.ExtractSecond:
 _extract_field('second'),
 ops.ExtractMillisecond:
 _extract_field('millisecond'),
 ops.ExtractEpochSeconds:
 _extract_field('epochseconds'),
 ops.StringReplace:
 fixed_arity('REPLACE', 3),
 ops.StringSplit:
 fixed_arity('SPLIT', 2),
 ops.StringConcat:
 _string_concat,
 ops.StringJoin:
 _string_join,
 ops.StringAscii:
 _string_ascii,
 ops.StringFind:
 _string_find,
 ops.StrRight:
 _string_right,
 ops.Repeat:
 fixed_arity('REPEAT', 2),
 ops.RegexSearch:
Exemple #7
0
    arg, digits = op.args

    arg_formatted = translator.translate(arg)

    if digits is not None:
        digits_formatted = translator.translate(digits)
        return 'bround({}, {})'.format(arg_formatted, digits_formatted)
    return 'bround({})'.format(arg_formatted)


_operation_registry = impala_compiler._operation_registry.copy()
_operation_registry.update({
    ops.IsNan:
    unary('isnan'),
    ops.IfNull:
    fixed_arity('ifnull', 2),
    ops.StructField:
    _struct_field,
    ops.MapValueForKey:
    _map_value_for_key,
    ops.ArrayLength:
    unary('size'),
    ops.Round:
    _round,
    ops.HLLCardinality:
    _reduction('approx_count_distinct'),
    ops.StrRight:
    fixed_arity('right', 2),
    ops.StringSplit:
    fixed_arity('SPLIT', 2),
    ops.RegexSearch:
Exemple #8
0
 ops.ExtractYear:
 _extract_field('year'),
 ops.ExtractMonth:
 _extract_field('month'),
 ops.ExtractDay:
 _extract_field('day'),
 ops.ExtractHour:
 _extract_field('hour'),
 ops.ExtractMinute:
 _extract_field('minute'),
 ops.ExtractSecond:
 _extract_field('second'),
 ops.ExtractMillisecond:
 _extract_field('millisecond'),
 ops.StringReplace:
 fixed_arity('REPLACE', 3),
 ops.StringSplit:
 fixed_arity('SPLIT', 2),
 ops.StringConcat:
 _string_concat,
 ops.StringJoin:
 _string_join,
 ops.StringAscii:
 _string_ascii,
 ops.StringFind:
 _string_find,
 ops.StrRight:
 _string_right,
 ops.Repeat:
 fixed_arity('REPEAT', 2),
 ops.RegexSearch:
Exemple #9
0
    dt.Timestamp: 'TIMESTAMP',
}


_operation_registry = impala_compiler._operation_registry.copy()
_operation_registry.update(
    {
        ops.ExtractYear: _extract_field('year'),
        ops.ExtractQuarter: _extract_field('quarter'),
        ops.ExtractMonth: _extract_field('month'),
        ops.ExtractDay: _extract_field('day'),
        ops.ExtractHour: _extract_field('hour'),
        ops.ExtractMinute: _extract_field('minute'),
        ops.ExtractSecond: _extract_field('second'),
        ops.ExtractMillisecond: _extract_field('millisecond'),
        ops.StringReplace: fixed_arity('REPLACE', 3),
        ops.StringSplit: fixed_arity('SPLIT', 2),
        ops.StringConcat: _string_concat,
        ops.StringJoin: _string_join,
        ops.StringAscii: _string_ascii,
        ops.StringFind: _string_find,
        ops.StrRight: _string_right,
        ops.Repeat: fixed_arity('REPEAT', 2),
        ops.RegexSearch: _regex_search,
        ops.RegexExtract: _regex_extract,
        ops.RegexReplace: _regex_replace,
        ops.GroupConcat: fixed_arity('STRING_AGG', 2),
        ops.IfNull: fixed_arity('IFNULL', 2),
        ops.Cast: _cast,
        ops.StructField: _struct_field,
        ops.ArrayCollect: unary('ARRAY_AGG'),
Exemple #10
0
    dt.Time: 'TIME',
    dt.Timestamp: 'TIMESTAMP',
}


_operation_registry = impala_compiler._operation_registry.copy()
_operation_registry.update(
    {
        ops.ExtractYear: _extract_field('year'),
        ops.ExtractMonth: _extract_field('month'),
        ops.ExtractDay: _extract_field('day'),
        ops.ExtractHour: _extract_field('hour'),
        ops.ExtractMinute: _extract_field('minute'),
        ops.ExtractSecond: _extract_field('second'),
        ops.ExtractMillisecond: _extract_field('millisecond'),
        ops.StringReplace: fixed_arity('REPLACE', 3),
        ops.StringSplit: fixed_arity('SPLIT', 2),
        ops.StringConcat: _string_concat,
        ops.StringJoin: _string_join,
        ops.StringAscii: _string_ascii,
        ops.StringFind: _string_find,
        ops.StrRight: _string_right,
        ops.Repeat: fixed_arity('REPEAT', 2),
        ops.RegexSearch: _regex_search,
        ops.RegexExtract: _regex_extract,
        ops.RegexReplace: _regex_replace,
        ops.GroupConcat: fixed_arity('STRING_AGG', 2),
        ops.IfNull: fixed_arity('IFNULL', 2),
        ops.Cast: _cast,
        ops.StructField: _struct_field,
        ops.ArrayCollect: unary('ARRAY_AGG'),