Example #1
0
    def test_ctas_ddl(self):
        con = MockConnection()

        select = ImpalaCompiler.to_ast(con.table('test1')).queries[0]
        statement = ksupport.CTASKudu(
            'another_table',
            'kudu_name',
            ['dom.d.com:7051'],
            select,
            ['string_col'],
            external=True,
            can_exist=False,
            database='foo',
        )
        result = statement.compile()

        expected = """\
CREATE EXTERNAL TABLE foo.`another_table`
TBLPROPERTIES (
  'kudu.key_columns'='string_col',
  'kudu.master_addresses'='dom.d.com:7051',
  'kudu.table_name'='kudu_name',
  'storage_handler'='com.cloudera.kudu.hive.KuduStorageHandler'
) AS
SELECT *
FROM test1"""
        assert result == expected
Example #2
0
def _create_table(table_name,
                  expr,
                  database=None,
                  can_exist=False,
                  format='parquet'):
    ast = ImpalaCompiler.to_ast(expr)
    select = ast.queries[0]
    statement = CTAS(
        table_name,
        select,
        database=database,
        format=format,
        can_exist=can_exist,
    )
    return statement
Example #3
0
def _get_select(expr, context=None):
    ast = ImpalaCompiler.to_ast(expr, context)
    select = ast.queries[0]
    context = ast.context
    return select, context