Browse Source

removing trim_statement_semicolon property from connector and removing duplication of primary keys menu

ayush.goyal 4 years ago
parent
commit
784f4cedac

+ 1 - 1
desktop/core/src/desktop/js/ko/components/ko.historyPanel.js

@@ -192,7 +192,7 @@ class HistoryPanel {
         phoenix: {
           placeHolder: I18n('Example: SELECT * FROM tablename, or press CTRL + space'),
           aceMode: 'ace/mode/phoenix',
-          snippetImage: window.STATIC_URLS['beeswax/art/icon_beeswax_48.png'],
+          snippetImage: window.STATIC_URLS['rdbms/art/icon_rdbms_48.png'],
           sqlDialect: true
         },
         java: {

+ 0 - 27
desktop/core/src/desktop/lib/connectors/types.py

@@ -58,7 +58,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': True,
       'has_reference_functions': True,
       'has_use_statement': True,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -86,7 +85,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': True,
       'has_reference_functions': True,
       'has_use_statement': True,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -115,7 +113,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': True,
       'has_reference_functions': True,
       'has_use_statement': True,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -143,7 +140,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': True,
       'has_reference_functions': True,
       'has_use_statement': True,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -171,7 +167,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': True,
     }
   },
   {
@@ -199,7 +194,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': True,
     }
   },
   {
@@ -227,7 +221,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': True,
     }
   },
   {
@@ -255,7 +248,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': True,
     }
   },
   {
@@ -286,7 +278,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': True,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -314,7 +305,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -342,7 +332,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': True,
     }
   },
   {
@@ -370,7 +359,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -398,7 +386,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -427,7 +414,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': True,
     }
   },
   {
@@ -455,7 +441,6 @@ CONNECTOR_TYPES = [
       'has_auto_limit': False,
       'has_reference_language': False,
       'has_reference_functions': False,
-      'trim_statement_semicolon': True,
     }
   },
   {
@@ -483,7 +468,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -512,7 +496,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -542,7 +525,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -568,7 +550,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -594,7 +575,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -621,7 +601,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -649,7 +628,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -677,7 +655,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': True,
     }
   },
   {
@@ -705,7 +682,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -733,7 +709,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -764,7 +739,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
   {
@@ -791,7 +765,6 @@ CONNECTOR_TYPES = [
       'has_reference_language': False,
       'has_reference_functions': False,
       'has_use_statement': False,
-      'trim_statement_semicolon': False,
     }
   },
 

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

@@ -326,7 +326,7 @@ CONSTRAINT my_pk PRIMARY KEY (%(primary_keys)s));
           'database': database,
           'table_name': table_name,
           'columns': ',\n'.join(['  %(name)s %(type)s' % col for col in columns]),
-          'primary_keys': ', '.join(destination.get('indexerPrimaryKey'))
+          'primary_keys': ', '.join(destination.get('primaryKeys'))
       }
 
     path = urllib_unquote(source['path'])
@@ -334,12 +334,12 @@ CONSTRAINT my_pk PRIMARY KEY (%(primary_keys)s));
     if path:                                                     # data insertion
       with open(BASE_DIR + path, 'r') as local_file:
         reader = csv.reader(local_file)
-        list_of_tuples = list(map(tuple, reader))
+        _csv_rows = list(map(tuple, reader))
 
         if source['format']['hasHeader']:
-          list_of_tuples = list_of_tuples[1:]
+          _csv_rows = _csv_rows[1:]
 
-        csv_rows = str(list_of_tuples)[1:-1]
+        csv_rows = str(_csv_rows)[1:-1]
 
         if dialect in ('hive', 'mysql'):
           sql += '''\nINSERT INTO %(database)s.%(table_name)s VALUES %(csv_rows)s;
@@ -348,8 +348,8 @@ CONSTRAINT my_pk PRIMARY KEY (%(primary_keys)s));
                   'table_name': table_name,
                   'csv_rows': csv_rows
                 }
-        if dialect == 'phoenix':
-          for csv_row in list_of_tuples:
+        elif dialect == 'phoenix':
+          for csv_row in _csv_rows:
             _sql = ', '.join([ "'{0}'".format(col_val) if columns[count]['type'] in ('CHAR(255)', 'timestamp') \
               else '{0}'.format(col_val) for count, col_val in enumerate(csv_row)])
 

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

@@ -887,7 +887,7 @@ def test_create_table_from_local_phoenix():
         {'name': 'field_3', 'type': 'bigint'},
       ],
       'sourceType': 'phoenix',
-      'indexerPrimaryKey': ['field_3']
+      'primaryKeys': ['field_3']
     }
     sql = SQLIndexer(user=Mock(), fs=Mock()).create_table_from_local_file(source, destination).get_str()
 

+ 5 - 11
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -554,11 +554,6 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
               <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 data-bind="visible: dialect() == 'phoenix'">
-                <label for="PhoenixPks" class="control-label"><div>${ _('Primary key') }</div>
-                  <select id="PhoenixPks" data-bind="selectize: columns, selectedOptions: indexerPrimaryKey, selectedObjects: indexerPrimaryKeyObject, optionsValue: 'name', optionsText: 'name', innerSubscriber: 'name'" size="1"></select>
-                </label>
-              </div>
             </div>
             <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') }">
@@ -709,7 +704,7 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
               </label>
             </div>
 
-            <div class="control-group" data-bind="visible: tableFormat() == 'kudu'">
+            <div class="control-group" data-bind="visible: (tableFormat() == 'kudu' || $root.createWizard.destination.dialect() == 'phoenix')">
               <label for="kuduPksTable" class="control-label"><div>${ _('Primary keys') }</div>
                 ## At least one selected
                 <select id="kuduPksTable" data-bind="selectize: columns, selectedOptions: primaryKeys, selectedObjects: primaryKeyObjects, optionsValue: 'name', optionsText: 'name', innerSubscriber: 'name'" size="3" multiple="true"></select>
@@ -1805,11 +1800,10 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
       self.interpreter.subscribe(function(val) {
         self.sourceType(val);
         wizard.destination.sourceType(val);
-        for (let i = 0; i < self.interpreters().length; i++) {
-          if (val == self.interpreters()[i]['type']) {
-            wizard.destination.dialect(self.interpreters()[i]['dialect']);
-          }
-        }
+        var dialect = self.interpreters().filter(function(interpreter) {
+          return interpreter['type'] === val;
+        });
+        wizard.destination.dialect(dialect[0]['dialect']);
       });
   
       // File

+ 3 - 3
desktop/libs/notebook/src/notebook/connectors/sql_alchemy.py

@@ -239,8 +239,8 @@ class SqlAlchemyApi(Api):
 
     engine = self._get_engine()
     connection = self._create_connection(engine)
-    stmt_dict = self._get_current_statement(notebook, snippet)
-    statement = stmt_dict['statement']
+    current_statement = self._get_current_statement(notebook, snippet)
+    statement = current_statement['statement']
 
     if self.interpreter['dialect_properties'].get('has_use_statement') and snippet.get('database'):
       connection.execute(
@@ -280,7 +280,7 @@ class SqlAlchemyApi(Api):
         'type': 'table'
       }
     }
-    response.update(stmt_dict)
+    response.update(current_statement)
 
     return response
 

+ 8 - 0
desktop/libs/notebook/src/notebook/connectors/sql_alchemy_tests.py

@@ -351,6 +351,14 @@ class TestApi(object):
 
           execute.assert_called_with('SELECT 1')
 
+          # No Trim
+          interpreter['options']['url'] = 'mysql://hue:3306/hue'
+          interpreter['dialect_properties']['sql_identifier_quote'] = '`'
+
+          engine = SqlAlchemyApi(self.user, interpreter).execute(notebook, snippet)
+
+          execute.assert_called_with('SELECT 1')
+
 
   def test_get_log(self):
     notebook = Mock()