|
|
@@ -900,8 +900,7 @@ def test_create_table_from_local_impala():
|
|
|
],
|
|
|
'sourceType': 'impala'
|
|
|
}
|
|
|
- request = MockRequest(fs=MockFs())
|
|
|
- sql = SQLIndexer(user=request.user, fs=request.fs).create_table_from_local_file(source, destination).get_str()
|
|
|
+ sql = SQLIndexer(user=Mock(), fs=Mock()).create_table_from_local_file(source, destination).get_str()
|
|
|
|
|
|
statement = '''USE default;
|
|
|
|
|
|
@@ -954,6 +953,77 @@ DROP TABLE IF EXISTS default.test1_tmp;'''
|
|
|
assert_equal(statement, sql)
|
|
|
|
|
|
|
|
|
+def test_create_table_only_header_file_local_impala():
|
|
|
+ with patch('indexer.indexers.sql.get_interpreter') as get_interpreter:
|
|
|
+ get_interpreter.return_value = {'Name': 'Impala', 'dialect': 'impala'}
|
|
|
+ source = {
|
|
|
+ 'path': BASE_DIR + '/apps/beeswax/data/tables/onlyheader.csv',
|
|
|
+ 'sourceType': 'impala',
|
|
|
+ 'format': {'hasHeader': True}
|
|
|
+ }
|
|
|
+ destination = {
|
|
|
+ 'name': 'default.test1',
|
|
|
+ 'columns': [
|
|
|
+ {'name': 'date', 'type': 'timestamp', 'keep': True},
|
|
|
+ {'name': 'hour', 'type': 'bigint', 'keep': True},
|
|
|
+ {'name': 'minute', 'type': 'bigint', 'keep': True},
|
|
|
+ {'name': 'dep', 'type': 'bigint', 'keep': True},
|
|
|
+ {'name': 'arr', 'type': 'bigint', 'keep': True},
|
|
|
+ {'name': 'dep_delay', 'type': 'bigint', 'keep': True},
|
|
|
+ {'name': 'arr_delay', 'type': 'bigint', 'keep': True},
|
|
|
+ {'name': 'carrier', 'type': 'string', 'keep': True},
|
|
|
+ {'name': 'flight', 'type': 'bigint', 'keep': True},
|
|
|
+ {'name': 'dest', 'type': 'string', 'keep': True},
|
|
|
+ {'name': 'plane', 'type': 'string', 'keep': True},
|
|
|
+ {'name': 'cancelled', 'type': 'boolean', 'keep': True},
|
|
|
+ {'name': 'time', 'type': 'bigint', 'keep': True},
|
|
|
+ {'name': 'dist', 'type': 'bigint', 'keep': True},
|
|
|
+ ],
|
|
|
+ 'sourceType': 'impala'
|
|
|
+ }
|
|
|
+ sql = SQLIndexer(user=Mock(), fs=Mock()).create_table_from_local_file(source, destination).get_str()
|
|
|
+
|
|
|
+ statement = '''USE default;
|
|
|
+
|
|
|
+CREATE TABLE IF NOT EXISTS default.test1_tmp (
|
|
|
+ `date` string,
|
|
|
+ `hour` string,
|
|
|
+ `minute` string,
|
|
|
+ `dep` string,
|
|
|
+ `arr` string,
|
|
|
+ `dep_delay` string,
|
|
|
+ `arr_delay` string,
|
|
|
+ `carrier` string,
|
|
|
+ `flight` string,
|
|
|
+ `dest` string,
|
|
|
+ `plane` string,
|
|
|
+ `cancelled` string,
|
|
|
+ `time` string,
|
|
|
+ `dist` string);
|
|
|
+
|
|
|
+CREATE TABLE IF NOT EXISTS default.test1
|
|
|
+AS SELECT
|
|
|
+ CAST ( `date` AS timestamp ) `date`,
|
|
|
+ CAST ( `hour` AS bigint ) `hour`,
|
|
|
+ CAST ( `minute` AS bigint ) `minute`,
|
|
|
+ CAST ( `dep` AS bigint ) `dep`,
|
|
|
+ CAST ( `arr` AS bigint ) `arr`,
|
|
|
+ CAST ( `dep_delay` AS bigint ) `dep_delay`,
|
|
|
+ CAST ( `arr_delay` AS bigint ) `arr_delay`,
|
|
|
+ CAST ( `carrier` AS string ) `carrier`,
|
|
|
+ CAST ( `flight` AS bigint ) `flight`,
|
|
|
+ CAST ( `dest` AS string ) `dest`,
|
|
|
+ CAST ( `plane` AS string ) `plane`,
|
|
|
+ CAST ( CAST ( `cancelled` AS TINYINT ) AS boolean ) `cancelled`,
|
|
|
+ CAST ( `time` AS bigint ) `time`,
|
|
|
+ CAST ( `dist` AS bigint ) `dist`
|
|
|
+FROM default.test1_tmp;
|
|
|
+
|
|
|
+DROP TABLE IF EXISTS default.test1_tmp;'''
|
|
|
+
|
|
|
+ assert_equal(statement, sql)
|
|
|
+
|
|
|
+
|
|
|
def test_create_table_with_drop_column_from_local():
|
|
|
with patch('indexer.indexers.sql.get_interpreter') as get_interpreter:
|
|
|
get_interpreter.return_value = {'Name': 'Hive', 'dialect': 'hive'}
|