How to use the siuba.sql.translate.SqlTranslator function in siuba

To help you get started, we’ve selected a few siuba examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github machow / siuba / siuba / sql / dialects / postgresql.py View on Github external
#year = lambda col: sql.func.extract('year', sql.cast(col, sql.sqltypes.Date)),
        concat = sql.func.concat,
        cat = sql.func.concat,
        str_c = sql.func.concat,
        __floordiv__ = lambda x, y: sql.cast(x / y, sa_types.Integer())
        )

aggregate = SqlTranslator(
        base_agg,
        all = sql_agg("bool_and"),
        any = sql_agg("bool_or"),
        std = sql_agg("stddev_samp"),
        var = sql_agg("var_samp"),
        )

window = SqlTranslator(
        base_win,
        any = win_agg("bool_or"),
        all = win_agg("bool_and"),
        lag = win_agg("lag"),
        var = win_agg("var_samp"),
        )

funcs = dict(scalar = scalar, aggregate = aggregate, window = window)
github machow / siuba / siuba / sql / dialects / postgresql.py View on Github external
# TODO: warn there differences in regex for python and sql?
    # TODO: validate pat is string?
    if not isinstance(pat, str):
        raise TypeError("pat argument must be a string")
    if flags != 0 or na is not None:
        raise NotImplementedError("flags and na options not supported")

    if not regex:
        case_col = col if case else col.lower()
        return case_col.contains(pat, autoescape = True)

    full_op = "~" if case else "~*"

    return col.op(full_op)(pat)

scalar = SqlTranslator(
        base_scalar,
        log = sql_log,
        round = sql_round,
        contains = sql_func_contains,
        #year = lambda col: sql.func.extract('year', sql.cast(col, sql.sqltypes.Date)),
        concat = sql.func.concat,
        cat = sql.func.concat,
        str_c = sql.func.concat,
        __floordiv__ = lambda x, y: sql.cast(x / y, sa_types.Integer())
        )

aggregate = SqlTranslator(
        base_agg,
        all = sql_agg("bool_and"),
        any = sql_agg("bool_or"),
        std = sql_agg("stddev_samp"),
github machow / siuba / siuba / sql / dialects / sqlite.py View on Github external
# sqlvariant, allow defining 3 namespaces to override defaults
from ..translate import SqlColumn, SqlColumnAgg, base_scalar, base_agg, base_nowin, SqlTranslator, win_agg
import sqlalchemy.sql.sqltypes as sa_types
from sqlalchemy import sql

# Custom dispatching in call trees ============================================

class SqliteColumn(SqlColumn): pass
class SqliteColumnAgg(SqlColumnAgg, SqliteColumn): pass

scalar = SqlTranslator(
        base_scalar,
        )

aggregate = SqlTranslator(
        base_agg
        )

window = SqlTranslator(
        # TODO: should check sqlite version, since < 3.25 can't use windows
        base_nowin,
        sd = win_agg("stddev")
        )

funcs = dict(scalar = scalar, aggregate = aggregate, window = window)
github machow / siuba / siuba / sql / dialects / sqlite.py View on Github external
# sqlvariant, allow defining 3 namespaces to override defaults
from ..translate import SqlColumn, SqlColumnAgg, base_scalar, base_agg, base_nowin, SqlTranslator, win_agg
import sqlalchemy.sql.sqltypes as sa_types
from sqlalchemy import sql

# Custom dispatching in call trees ============================================

class SqliteColumn(SqlColumn): pass
class SqliteColumnAgg(SqlColumnAgg, SqliteColumn): pass

scalar = SqlTranslator(
        base_scalar,
        )

aggregate = SqlTranslator(
        base_agg
        )

window = SqlTranslator(
        # TODO: should check sqlite version, since < 3.25 can't use windows
        base_nowin,
        sd = win_agg("stddev")
        )

funcs = dict(scalar = scalar, aggregate = aggregate, window = window)
github machow / siuba / siuba / sql / dialects / sqlite.py View on Github external
from sqlalchemy import sql

# Custom dispatching in call trees ============================================

class SqliteColumn(SqlColumn): pass
class SqliteColumnAgg(SqlColumnAgg, SqliteColumn): pass

scalar = SqlTranslator(
        base_scalar,
        )

aggregate = SqlTranslator(
        base_agg
        )

window = SqlTranslator(
        # TODO: should check sqlite version, since < 3.25 can't use windows
        base_nowin,
        sd = win_agg("stddev")
        )

funcs = dict(scalar = scalar, aggregate = aggregate, window = window)
github machow / siuba / siuba / sql / dialects / postgresql.py View on Github external
return col.op(full_op)(pat)

scalar = SqlTranslator(
        base_scalar,
        log = sql_log,
        round = sql_round,
        contains = sql_func_contains,
        #year = lambda col: sql.func.extract('year', sql.cast(col, sql.sqltypes.Date)),
        concat = sql.func.concat,
        cat = sql.func.concat,
        str_c = sql.func.concat,
        __floordiv__ = lambda x, y: sql.cast(x / y, sa_types.Integer())
        )

aggregate = SqlTranslator(
        base_agg,
        all = sql_agg("bool_and"),
        any = sql_agg("bool_or"),
        std = sql_agg("stddev_samp"),
        var = sql_agg("var_samp"),
        )

window = SqlTranslator(
        base_win,
        any = win_agg("bool_or"),
        all = win_agg("bool_and"),
        lag = win_agg("lag"),
        var = win_agg("var_samp"),
        )

funcs = dict(scalar = scalar, aggregate = aggregate, window = window)