def compile(expr): """ Force compilation of expression for the PostgreSQL target """ from .client import PostgreSQLDialect from ibis.sql.alchemy import to_sqlalchemy return to_sqlalchemy(expr, dialect=PostgreSQLDialect)
def compile(expr, params=None): """ Force compilation of expression for the SQLite target """ from ibis.sql.alchemy import to_sqlalchemy return to_sqlalchemy(expr, dialect.make_context(params=params))
def compile(expr): """Compile an ibis expression to the PostgreSQL target. Parameters ---------- expr : ibis.expr.types.Expr The ibis expression to compile Returns ------- sqlalchemy_expression : sqlalchemy.sql.expression.ClauseElement Examples -------- >>> import os >>> database = os.environ.get('IBIS_TEST_POSTGRES_DB', 'ibis_testing') >>> con = connect(database=database, host='localhost') >>> t = con.table('functional_alltypes') >>> expr = t.double_col + 1 >>> sqla = compile(expr) >>> print(str(sqla)) # doctest: +NORMALIZE_WHITESPACE SELECT t0.double_col + %(param_1)s AS tmp FROM functional_alltypes AS t0 """ return to_sqlalchemy(expr, dialect=PostgreSQLDialect)
def compile(expr, params=None): """Compile an ibis expression to the Snowflake target. Parameters ---------- expr : ibis.expr.types.Expr The ibis expression to compile params : dict or None ``dict`` mapping :class:`ibis.expr.types.ScalarParameter` objects to values Returns ------- sqlalchemy_expression : sqlalchemy.sql.expression.ClauseElement Examples -------- >>> import os >>> import getpass >>> user = os.environ.get('IBIS_TEST_SNOWFLAKE_USER', getpass.getuser()) >>> password = os.environ.get('IBIS_TEST_SNOWFLAKE_PASSWORD') >>> account = os.environ.get('IBIS_TEST_SNOWFLAKE_ACCOUNT') >>> database = os.environ.get('IBIS_TEST_SNOWFLAKE_DATABASE', ... 'ibis_testing') >>> con = connect( ... database=database, ... account=account, ... user=user, ... password=password ... ) >>> t = con.table('functional_alltypes') >>> expr = t.double_col + 1 >>> sqla = compile(expr) >>> print(str(sqla)) # doctest: +NORMALIZE_WHITESPACE SELECT t0.double_col + %(param_1)s AS tmp FROM functional_alltypes AS t0 """ return to_sqlalchemy(expr, dialect.make_context(params=params))
def compile(expr, params=None): """Compile an ibis expression to the PostgreSQL target. Parameters ---------- expr : ibis.expr.types.Expr The ibis expression to compile params : dict or None ``dict`` mapping :class:`ibis.expr.types.ScalarParameter` objects to values Returns ------- sqlalchemy_expression : sqlalchemy.sql.expression.ClauseElement Examples -------- >>> import os >>> import getpass >>> host = os.environ.get('IBIS_TEST_POSTGRES_HOST', 'localhost') >>> user = os.environ.get('IBIS_TEST_POSTGRES_USER', getpass.getuser()) >>> password = os.environ.get('IBIS_TEST_POSTGRES_PASSWORD') >>> database = os.environ.get('IBIS_TEST_POSTGRES_DATABASE', ... 'ibis_testing') >>> con = connect( ... database=database, ... host=host, ... user=user, ... password=password ... ) >>> t = con.table('functional_alltypes') >>> expr = t.double_col + 1 >>> sqla = compile(expr) >>> print(str(sqla)) # doctest: +NORMALIZE_WHITESPACE SELECT t0.double_col + %(param_1)s AS tmp FROM functional_alltypes AS t0 """ return to_sqlalchemy(expr, dialect.make_context(params=params))
def compile(expr, params=None): """Compile an ibis expression to the MSSQL target. Parameters ---------- expr : ibis.expr.types.Expr The ibis expression to compile params : dict, optional ``dict`` mapping :class:`ibis.expr.types.ScalarParameter` objects to values Returns ------- sqlalchemy_expression : sqlalchemy.sql.expression.ClauseElement Examples -------- >>> import os >>> import getpass >>> host = os.environ.get('IBIS_TEST_MSSQL_HOST', 'localhost') >>> user = os.environ.get('IBIS_TEST_MSSQL_USER', getpass.getuser()) >>> password = os.environ.get('IBIS_TEST_MSSQL_PASSWORD') >>> database = os.environ.get('IBIS_TEST_MSSQL_DATABASE', 'master') >>> con = connect( ... database=database, ... host=host, ... user=user, ... password=password, ... ) >>> t = con.table('functional_alltypes') >>> expr = t.double_col + 1 >>> sqla = compile(expr) >>> print(str(sqla)) # doctest: +NORMALIZE_WHITESPACE SELECT t0.double_col + ? AS tmp FROM functional_alltypes AS t0 """ return to_sqlalchemy(expr, dialect.make_context(params=params))
def _compare_sqla(self, expr, sqla): result = alch.to_sqlalchemy(expr) assert str(result.compile()) == str(sqla.compile())
def _compare_sqla(self, expr, sqla): context = alch.AlchemyContext(dialect=alch.AlchemyDialect()) result = alch.to_sqlalchemy(expr, context) assert str(result.compile()) == str(sqla.compile())
def compile(expr, params=None): return to_sqlalchemy(expr, dialect.make_context(params=params))