# Path: impala/sqlalchemy.py
# class TINYINT(Integer):
# class INT(Integer):
# class DOUBLE(Float):
# class STRING(String):
# class ImpalaDDLCompiler(DDLCompiler):
# class ImpalaTypeCompiler(GenericTypeCompiler):
# class Impala4TypeCompiler(ImpalaTypeCompiler):
# class ImpalaIdentifierPreparer(IdentifierPreparer):
# class ImpalaExecutionContext(DefaultExecutionContext):
# class ImpalaDialect(DefaultDialect):
# class Impala4Dialect(ImpalaDialect):
#     def visit_foreign_key_constraint(self, constraint):
#     def visit_primary_key_constraint(self, constraint):
#     def get_column_specification(self, column, **kwargs):
#     def post_create_table(self, table):
#     def visit_TEXT(self, type_):
#     def visit_DATETIME(self, type_):
#     def visit_TINYINT(self, type_):
#     def visit_INT(self, type_):
#     def visit_DOUBLE(self, type_):
#     def visit_STRING(self, type_):
#     def visit_DATE(self, type_):
#     def __init__(self, dialect):
#        def create_cursor(self):
#     def dbapi(cls):
#     def create_connect_args(self, url):
#     def initialize(self, connection):
#     def _get_server_version_info(self, connection):
#     def has_table(self, connection, table_name, schema=None):
#     def get_table_names(self, connection, schema=None, **kw):
#     def get_schema_names(self, connection, **kw):
#     def get_columns(self, connection, table_name, schema=None, **kwargs):
#     def get_pk_constraint(self, connection, table_name, schema=None, **kw):
#     def get_foreign_keys(self, connection, table_name, schema=None, **kw):
#     def get_indexes(self, connection, table_name, schema=None, **kw):
#     def do_rollback(self, dbapi_connection):
# 
# Path: impala/tests/util.py
# class ImpylaTestEnv(object):
# 
#     def __init__(self, host=None, port=None, hive_port=None, auth_mech=None,
#                  http_port=None):
#         if host is not None:
#             self.host = host
#         else:
#             self.host = get_env_var('IMPYLA_TEST_HOST', identity, 'localhost')
# 
#         if port is not None:
#             self.port = port
#         else:
#             self.port = get_env_var('IMPYLA_TEST_PORT', int, 21050)
# 
#         if http_port is not None:
#             self.http_port = http_port
#         else:
#             self.http_port = get_env_var('IMPYLA_TEST_HTTP_PORT', int, 28000)
# 
#         if hive_port is not None:
#             self.hive_port = hive_port
#         else:
#             self.hive_port = get_env_var('IMPYLA_TEST_HIVE_PORT', int, 10000)
# 
#         self.hive_user = get_env_var('IMPYLA_TEST_HIVE_USER', identity,
#                                      'cloudera')
# 
#         self.skip_hive_tests = get_env_var('IMPYLA_SKIP_HIVE_TESTS', bool, False)
# 
#         if auth_mech is not None:
#             self.auth_mech = auth_mech
#         else:
#             self.auth_mech = get_env_var('IMPYLA_TEST_AUTH_MECH', identity,
#                                          'NOSASL')
# 
#     def __repr__(self):
#         kvs = ['{0}={1}'.format(k, v)
#                for (k, v) in six.iteritems(self.__dict__)]
#         return 'ImpylaTestEnv(\n    {0})'.format(',\n    '.join(kvs))


from sqlalchemy.engine import create_engine
from sqlalchemy import Table, Column
from sqlalchemy.schema import MetaData, CreateTable
from impala.sqlalchemy import STRING, INT, DOUBLE, TINYINT, DATE, VARCHAR
from impala.tests.util import ImpylaTestEnv
                    Column('col5', DATE),
                    Column('col6', VARCHAR(10)),
                    impala_partitioned_by='(part_col STRING)',
                    impala_stored_as='PARQUET',
                    impala_table_properties={
                        'transactional': 'true',
                        'transactional_properties': 'insert_only'
                    })
    observed = str(CreateTable(mytable, bind=engine))
    # The DATE column type of 'col5' will be replaced with TIMESTAMP.
    expected = ('\nCREATE TABLE mytable (\n\tcol1 STRING, \n\tcol2 TINYINT, '
                '\n\tcol3 INT, \n\tcol4 DOUBLE, \n\tcol5 TIMESTAMP, \n\tcol6 VARCHAR(10)\n)'
                '\nPARTITIONED BY (part_col STRING)\nSTORED AS PARQUET\n'
                "TBLPROPERTIES ('transactional' = 'true', "
                "'transactional_properties' = 'insert_only')\n\n")
    assert expected == observed

def test_sqlalchemy_impala4_compilation():
    def create_test_engine():
        return create_engine('impala4://{0}:{1}'.format(TEST_ENV.host, TEST_ENV.port))

    engine = create_test_engine()
    metadata = MetaData(engine)
    # TODO: add other types to this table (e.g., functional.all_types)
    mytable = Table("mytable",
                    metadata,
                    Column('col1', STRING),
                    Column('col2', TINYINT),
                    Column('col3', INT),
                    Column('col4', DOUBLE),

# Path: impala/sqlalchemy.py
# class TINYINT(Integer):
# class INT(Integer):
# class DOUBLE(Float):
# class STRING(String):
# class ImpalaDDLCompiler(DDLCompiler):
# class ImpalaTypeCompiler(GenericTypeCompiler):
# class Impala4TypeCompiler(ImpalaTypeCompiler):
# class ImpalaIdentifierPreparer(IdentifierPreparer):
# class ImpalaExecutionContext(DefaultExecutionContext):
# class ImpalaDialect(DefaultDialect):
# class Impala4Dialect(ImpalaDialect):
#     def visit_foreign_key_constraint(self, constraint):
#     def visit_primary_key_constraint(self, constraint):
#     def get_column_specification(self, column, **kwargs):
#     def post_create_table(self, table):
#     def visit_TEXT(self, type_):
#     def visit_DATETIME(self, type_):
#     def visit_TINYINT(self, type_):
#     def visit_INT(self, type_):
#     def visit_DOUBLE(self, type_):
#     def visit_STRING(self, type_):
#     def visit_DATE(self, type_):
#     def __init__(self, dialect):
#        def create_cursor(self):
#     def dbapi(cls):
#     def create_connect_args(self, url):
#     def initialize(self, connection):
#     def _get_server_version_info(self, connection):
#     def has_table(self, connection, table_name, schema=None):
#     def get_table_names(self, connection, schema=None, **kw):
#     def get_schema_names(self, connection, **kw):
#     def get_columns(self, connection, table_name, schema=None, **kwargs):
#     def get_pk_constraint(self, connection, table_name, schema=None, **kw):
#     def get_foreign_keys(self, connection, table_name, schema=None, **kw):
#     def get_indexes(self, connection, table_name, schema=None, **kw):
#     def do_rollback(self, dbapi_connection):
# 
# Path: impala/tests/util.py
# class ImpylaTestEnv(object):
# 
#     def __init__(self, host=None, port=None, hive_port=None, auth_mech=None,
#                  http_port=None):
#         if host is not None:
#             self.host = host
#         else:
#             self.host = get_env_var('IMPYLA_TEST_HOST', identity, 'localhost')
# 
#         if port is not None:
#             self.port = port
#         else:
#             self.port = get_env_var('IMPYLA_TEST_PORT', int, 21050)
# 
#         if http_port is not None:
#             self.http_port = http_port
#         else:
#             self.http_port = get_env_var('IMPYLA_TEST_HTTP_PORT', int, 28000)
# 
#         if hive_port is not None:
#             self.hive_port = hive_port
#         else:
#             self.hive_port = get_env_var('IMPYLA_TEST_HIVE_PORT', int, 10000)
# 
#         self.hive_user = get_env_var('IMPYLA_TEST_HIVE_USER', identity,
#                                      'cloudera')
# 
#         self.skip_hive_tests = get_env_var('IMPYLA_SKIP_HIVE_TESTS', bool, False)
# 
#         if auth_mech is not None:
#             self.auth_mech = auth_mech
#         else:
#             self.auth_mech = get_env_var('IMPYLA_TEST_AUTH_MECH', identity,
#                                          'NOSASL')
# 
#     def __repr__(self):
#         kvs = ['{0}={1}'.format(k, v)
#                for (k, v) in six.iteritems(self.__dict__)]
#         return 'ImpylaTestEnv(\n    {0})'.format(',\n    '.join(kvs))


# Path: impala/tests/test_sqlalchemy.py
from sqlalchemy.engine import create_engine
from sqlalchemy import Table, Column
from sqlalchemy.schema import MetaData, CreateTable
from impala.sqlalchemy import STRING, INT, DOUBLE, TINYINT, DATE, VARCHAR
from impala.tests.util import ImpylaTestEnv

                    Column('col5', DATE),
                    Column('col6', VARCHAR(10)),
                    impala_partitioned_by='(part_col STRING)',
                    impala_stored_as='PARQUET',
                    impala_table_properties={
                        'transactional': 'true',
                        'transactional_properties': 'insert_only'
                    })
    observed = str(CreateTable(mytable, bind=engine))
    # The DATE column type of 'col5' will be replaced with TIMESTAMP.
    expected = ('\nCREATE TABLE mytable (\n\tcol1 STRING, \n\tcol2 TINYINT, '
                '\n\tcol3 INT, \n\tcol4 DOUBLE, \n\tcol5 TIMESTAMP, \n\tcol6 VARCHAR(10)\n)'
                '\nPARTITIONED BY (part_col STRING)\nSTORED AS PARQUET\n'
                "TBLPROPERTIES ('transactional' = 'true', "
                "'transactional_properties' = 'insert_only')\n\n")
    assert expected == observed

def test_sqlalchemy_impala4_compilation():
    def create_test_engine():
        return create_engine('impala4://{0}:{1}'.format(TEST_ENV.host, TEST_ENV.port))

    engine = create_test_engine()
    metadata = MetaData(engine)
    # TODO: add other types to this table (e.g., functional.all_types)
    mytable = Table("mytable",
                    metadata,
                    Column('col1', STRING),
                    Column('col2', TINYINT),
                    Column('col3', INT),
                    Column('col4', DOUBLE),

                    Column('col5', DATE),