def test_select_basics(self): name = 'testing123456' expr = self.t.limit(10) select, _ = _get_select(expr, ImpalaDialect.make_context()) stmt = ddl.InsertSelect(name, select, database='foo') result = stmt.compile() expected = """\ INSERT INTO foo.`testing123456` SELECT * FROM functional_alltypes LIMIT 10""" assert result == expected stmt = ddl.InsertSelect(name, select, database='foo', overwrite=True) result = stmt.compile() expected = """\ INSERT OVERWRITE foo.`testing123456` SELECT * FROM functional_alltypes LIMIT 10""" assert result == expected
def test_select_basics(t): name = 'testing123456' expr = t.limit(10) select, _ = _get_select(expr, ImpalaDialect.make_context()) stmt = ddl.InsertSelect(name, select, database='foo') result = stmt.compile() expected = """\ INSERT INTO foo.`testing123456` SELECT * FROM functional_alltypes LIMIT 10""" assert result == expected stmt = ddl.InsertSelect(name, select, database='foo', overwrite=True) result = stmt.compile() expected = """\ INSERT OVERWRITE foo.`testing123456` SELECT * FROM functional_alltypes LIMIT 10""" assert result == expected
def test_create_external_table_as(mockcon): path = '/path/to/table' select, _ = _get_select( mockcon.table('test1'), ImpalaDialect.make_context() ) statement = ddl.CTAS( 'another_table', select, external=True, can_exist=False, path=path, database='foo', ) result = statement.compile() expected = """\ CREATE EXTERNAL TABLE foo.`another_table` STORED AS PARQUET LOCATION '{0}' AS SELECT * FROM test1""".format( path ) assert result == expected
def _create_table(table_name, expr, database=None, can_exist=False, format='parquet'): ast = build_ast(expr, ImpalaDialect.make_context()) select = ast.queries[0] statement = ddl.CTAS(table_name, select, database=database, format=format, can_exist=can_exist) return statement
def _create_table( table_name, expr, database=None, can_exist=False, format='parquet' ): ast = build_ast(expr, ImpalaDialect.make_context()) select = ast.queries[0] statement = ddl.CTAS( table_name, select, database=database, format=format, can_exist=can_exist, ) return statement
def test_correlated_predicate_subquery(self): t0 = self.table t1 = t0.view() expr = t0.g == t1.g ctx = ImpalaDialect.make_context() ctx.make_alias(t0) # Grab alias from parent context subctx = ctx.subcontext() subctx.make_alias(t1) subctx.make_alias(t0) result = self._translate(expr, context=subctx) expected = "t0.`g` = t1.`g`" assert result == expected
def test_column_ref_table_aliases(self): context = ImpalaDialect.make_context() table1 = ibis.table([ ('key1', 'string'), ('value1', 'double') ]) table2 = ibis.table([ ('key2', 'string'), ('value and2', 'double') ]) context.set_ref(table1, 't0') context.set_ref(table2, 't1') expr = table1['value1'] - table2['value and2'] result = self._translate(expr, context=context) expected = 't0.`value1` - t1.`value and2`' assert result == expected
def _translate(self, expr, context=None, named=False): if context is None: context = ImpalaDialect.make_context() translator = ImpalaExprTranslator(expr, context=context, named=named) return translator.get_result()