فهرست منبع

[Importer] Fix manual table creation from importer (#3807)

Ayush Goyal 1 سال پیش
والد
کامیت
f6e6ef15d1

+ 2 - 2
desktop/libs/indexer/src/indexer/indexers/sql.py

@@ -140,7 +140,7 @@ class SQLIndexer(object):
         }
       else:  # Manual
         row_format = ''
-        file_format = table_format
+        file_format = 'TextFile' if table_format == 'text' else table_format
         skip_header = False
         if table_format == 'kudu':
           columns = [col for col in columns if col['name'] in primary_keys] + [col for col in columns if col['name'] not in primary_keys]
@@ -185,7 +185,7 @@ class SQLIndexer(object):
       tbl_properties['skip.header.line.count'] = '1'
     # The temp table is not transactional, but final table can be if is_transactional.
     # tbl_properties that don't exist in previous versions can safely be added without error.
-    tbl_properties['transactional'] = 'false'
+    tbl_properties['transactional'] = str(destination['isTransactional']).lower() if source['inputFormat'] == 'manual' else 'false'
 
     sql += django_mako.render_to_string("gen/create_table_statement.mako", {
         'table': {

+ 42 - 0
desktop/libs/indexer/src/indexer/indexers/sql_tests.py

@@ -1422,3 +1422,45 @@ CREATE TABLE IF NOT EXISTS default.test1 (
   `dep` bigint);'''
 
     assert statement == sql
+
+
+@pytest.mark.django_db
+def test_create_table_with_manual_steps():
+  with patch('indexer.indexers.sql.get_interpreter') as get_interpreter:
+    get_interpreter.return_value = {'Name': 'Hive', 'dialect': 'hive'}
+    source = {
+    'sourceType': 'impala', 'path': '', 'inputFormat': 'manual',
+    'format': {
+        'quoteChar': '"',
+        'fieldSeparator': ','
+      }
+    }
+    destination = {
+    'sourceType': 'impala', 'name': 'complex_test2.test3', 'description': '', 'tableFormat': 'text',
+    'columns': [
+      {'name': 'new_field_1', 'type': 'string', 'keep': True},
+      {'name': 'new_field_2', 'type': 'string', 'keep': True}
+    ],
+    'partitionColumns': [], 'kuduPartitionColumns': [], 'primaryKeys': [], 'importData': True, 'useDefaultLocation': True,
+    'nonDefaultLocation': '', 'isTransactional': True, 'isInsertOnly': True, 'useCopy': False, 'hasHeader': False,
+    'useCustomDelimiters': False, 'customFieldDelimiter': ',', 'customCollectionDelimiter': '', 'customMapDelimiter': '',
+    'customRegexp': '', 'isIceberg': False,
+    'compute': {'id': 'default', 'name': 'default', 'type': 'direct', 'credentials': {}},
+    'namespace': {
+      'id': 'default', 'name': 'default', 'status': 'CREATED',
+      'computes': [{'id': 'default', 'name': 'default', 'type': 'direct', 'credentials': {}}]},
+    'databaseName': 'complex_test2',
+    'tableName': 'test3',
+    'isTransactional': True
+    }
+    sql = SQLIndexer(user=Mock(), fs=Mock()).create_table_from_a_file(source, destination).get_str()
+
+    statement = '''USE complex_test2;
+
+CREATE TABLE `complex_test2`.`test3`
+(
+  `new_field_1` string ,
+  `new_field_2` string )   STORED AS TextFile TBLPROPERTIES('transactional'='true')
+;'''
+
+    assert statement == sql

+ 1 - 1
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -1045,7 +1045,7 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
               <!-- ko if: $root.createWizard.source.inputFormat() === 'manual' -->
 
                 <form class="form-inline inline-table" data-bind="foreach: columns">
-                  <!-- ko if: ['table'].indexOf(outputFormat()) != -1 -->
+                  <!-- ko if: $parent.outputFormat() === 'table' -->
                     <a class="pointer pull-right margin-top-20" data-bind="click: function() { $parent.columns.remove($data); }">
                       <i class="fa fa-minus"></i>
                     </a>