Browse Source

[importer_direct_upload_dialects] Adding drop down for selecting different dialects

ayush.goyal 4 years ago
parent
commit
4098ab7b5e

+ 1 - 1
desktop/core/src/desktop/js/ko/bindings/ko.hiveChooser.js

@@ -18,7 +18,7 @@ import $ from 'jquery';
 import * as ko from 'knockout';
 import * as ko from 'knockout';
 
 
 ko.bindingHandlers.hiveChooser = {
 ko.bindingHandlers.hiveChooser = {
-  init: function (element, valueAccessor, allBindingsAccessor) {
+  update: function (element, valueAccessor, allBindingsAccessor) {
     const self = $(element);
     const self = $(element);
     let options = ko.unwrap(valueAccessor());
     let options = ko.unwrap(valueAccessor());
     let complexConfiguration = false;
     let complexConfiguration = false;

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

@@ -290,11 +290,8 @@ class SQLIndexer(object):
       table_name = destination['name']
       table_name = destination['name']
     final_table_name = table_name
     final_table_name = table_name
 
 
-    # source_type = source['sourceType']
-    source_type = 'hive'
-    # editor_type = '50'  # destination['sourceType']
-    # editor_type = destination['sourceType']
-    editor_type = 'hive'
+    source_type = source['sourceType']
+    editor_type = destination['sourceType']
 
 
     columns = destination['columns']
     columns = destination['columns']
 
 

+ 3 - 1
desktop/libs/indexer/src/indexer/indexers/sql_tests.py

@@ -789,6 +789,7 @@ def test_create_ddl_with_abfs():
 def test_create_table_from_local():
 def test_create_table_from_local():
   source = {
   source = {
     'path': '',
     'path': '',
+    'sourceType': 'hive'
   }
   }
   destination = {
   destination = {
     'name': 'default.test1',
     'name': 'default.test1',
@@ -808,7 +809,8 @@ def test_create_table_from_local():
       {'name': 'time', 'type': 'bigint'},
       {'name': 'time', 'type': 'bigint'},
       {'name': 'dist', 'type': 'bigint'},
       {'name': 'dist', 'type': 'bigint'},
     ],
     ],
-    'indexerPrimaryKey': []
+    'indexerPrimaryKey': [],
+    'sourceType': 'hive'
   }
   }
   request = MockRequest(fs=MockFs())
   request = MockRequest(fs=MockFs())
   sql = SQLIndexer(user=request.user, fs=request.fs).create_table_from_local_file(source, destination).get_str()
   sql = SQLIndexer(user=request.user, fs=request.fs).create_table_from_local_file(source, destination).get_str()

+ 17 - 2
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -550,6 +550,11 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
             <!-- /ko -->
             <!-- /ko -->
 
 
             <!-- ko if: ['table', 'database'].indexOf(outputFormat()) != -1 -->
             <!-- ko if: ['table', 'database'].indexOf(outputFormat()) != -1 -->
+            <div data-bind="visible: $parent.createWizard.source.inputFormat() == 'localfile'">
+              <label for="dialectType" class="control-label "><div>${ _('Dialect') }</div>
+                <select  id="dialectType" data-bind="selectize: $parent.createWizard.source.interpreters, value: $parent.createWizard.source.interpreter, optionsText: 'name', optionsValue: 'type'"></select>
+              </label>
+            </div>
             <label for="collectionName" class="control-label "><div>${ _('Name') }</div></label>
             <label for="collectionName" class="control-label "><div>${ _('Name') }</div></label>
             <input type="text" class="input-xxlarge" data-bind="value: name, hiveChooser: name, namespace: namespace, compute: compute, skipColumns: true, skipTables: outputFormat() == 'database', valueUpdate: 'afterkeydown', apiHelperUser: '${ user }', apiHelperType: sourceType, mainScrollable: $(MAIN_SCROLLABLE), attr: { 'placeholder': outputFormat() == 'table' ? '${  _ko('Table name or <database>.<table>') }' : '${  _ko('Database name') }' }" pattern="^([a-zA-Z0-9_]+\.)?[a-zA-Z0-9_]*$" title="${ _('Only alphanumeric and underscore characters') }">
             <input type="text" class="input-xxlarge" data-bind="value: name, hiveChooser: name, namespace: namespace, compute: compute, skipColumns: true, skipTables: outputFormat() == 'database', valueUpdate: 'afterkeydown', apiHelperUser: '${ user }', apiHelperType: sourceType, mainScrollable: $(MAIN_SCROLLABLE), attr: { 'placeholder': outputFormat() == 'table' ? '${  _ko('Table name or <database>.<table>') }' : '${  _ko('Database name') }' }" pattern="^([a-zA-Z0-9_]+\.)?[a-zA-Z0-9_]*$" title="${ _('Only alphanumeric and underscore characters') }">
             <!-- /ko -->
             <!-- /ko -->
@@ -1635,7 +1640,7 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
     var Source = function (vm, wizard) {
     var Source = function (vm, wizard) {
       var self = this;
       var self = this;
 
 
-      self.sourceType = vm.sourceType;
+      self.sourceType = ko.observable(vm.sourceType);
       self.name = ko.observable('');
       self.name = ko.observable('');
       self.sample = ko.observableArray();
       self.sample = ko.observableArray();
       self.sampleCols = ko.observableArray();
       self.sampleCols = ko.observableArray();
@@ -1788,6 +1793,15 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
         return self.inputFormatsAll();
         return self.inputFormatsAll();
       });
       });
 
 
+      self.interpreters = ko.pureComputed(function() {
+        return window.getLastKnownConfig().app_config.editor.interpreters;
+      });
+      self.interpreter = ko.observable(window.getLastKnownConfig().app_config.editor.default_sql_interpreter);
+      self.interpreter.subscribe(function(val) {
+        self.sourceType(val);
+        wizard.destination.sourceType(val);
+      });
+  
       // File
       // File
       self.path = ko.observable('');
       self.path = ko.observable('');
       self.path.subscribe(function(val) {
       self.path.subscribe(function(val) {
@@ -2188,7 +2202,8 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
 
 
     var Destination = function (vm, wizard) {
     var Destination = function (vm, wizard) {
       var self = this;
       var self = this;
-      self.apiHelperType = self.sourceType = vm.sourceType;
+      self.apiHelperType = vm.sourceType;
+      self.sourceType = ko.observable(vm.sourceType);
 
 
       self.name = ko.observable('').extend({ throttle: 500 });
       self.name = ko.observable('').extend({ throttle: 500 });
       self.nameChanged = function(name) {
       self.nameChanged = function(name) {