Ver código fonte

HUE-8758 [connectors] Use the dialect from the connector for autocomplete in editor v2

Johan Ahlen 5 anos atrás
pai
commit
c14f7f466b

+ 9 - 3
desktop/core/src/desktop/js/apps/notebook/aceAutocompleteWrapper.js

@@ -39,9 +39,15 @@ class AceAutocompleteWrapper {
         timeout: options.timeout
       });
     };
-    self.snippet.type.subscribe(() => {
-      initializeAutocompleter();
-    });
+    if (window.ENABLE_NOTEBOOK_2) {
+      self.snippet.dialect.subscribe(() => {
+        initializeAutocompleter();
+      });
+    } else {
+      self.snippet.type.subscribe(() => {
+        initializeAutocompleter();
+      });
+    }
     initializeAutocompleter();
   }
 

+ 3 - 2
desktop/core/src/desktop/js/apps/notebook2/app.js

@@ -32,9 +32,10 @@ import {
   REDRAW_FIXED_HEADERS_EVENT,
   SHOW_GRID_SEARCH_EVENT,
   SHOW_NORMAL_RESULT_EVENT,
-  REDRAW_CHART_EVENT, ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT
+  REDRAW_CHART_EVENT,
+  ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT
 } from 'apps/notebook2/events';
-import {DIALECT} from 'apps/notebook2/snippet';
+import { DIALECT } from 'apps/notebook2/snippet';
 
 export const initNotebook2 = () => {
   window.Clipboard = Clipboard;

+ 1 - 1
desktop/core/src/desktop/js/apps/notebook2/editorViewModel.js

@@ -27,7 +27,7 @@ import Notebook from 'apps/notebook2/notebook';
 import Snippet from 'apps/notebook2/snippet';
 import SqlExecutable from 'apps/notebook2/execution/sqlExecutable';
 import { UPDATE_HISTORY_EVENT } from 'apps/notebook2/components/ko.queryHistory';
-import {ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT} from 'apps/notebook2/events';
+import { ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT } from 'apps/notebook2/events';
 
 class EditorViewModel {
   constructor(editorId, notebooks, options, CoordinatorEditorViewModel, RunningCoordinatorModel) {

+ 31 - 0
desktop/core/src/desktop/js/apps/notebook2/notebook.test.js

@@ -16,6 +16,8 @@
 
 import Notebook from './notebook';
 import sessionManager from 'apps/notebook2/execution/sessionManager';
+import { GET_KNOWN_CONFIG_EVENT } from 'utils/hueConfig';
+import huePubSub from 'utils/huePubSub';
 
 describe('notebook.js', () => {
   const viewModel = {
@@ -33,15 +35,44 @@ describe('notebook.js', () => {
     }
   };
 
+  const previousEnableNotebook2 = window.ENABLE_NOTEBOOK_2;
+
+  beforeAll(() => {
+    window.ENABLE_NOTEBOOK_2 = true;
+  });
+
+  afterAll(() => {
+    window.ENABLE_NOTEBOOK_2 = previousEnableNotebook2;
+  });
+
   beforeEach(() => {
     jest.spyOn(sessionManager, 'getSession').mockImplementation(() => Promise.resolve());
   });
 
   it('should serialize a notebook to JSON', async () => {
+    const spy = jest.spyOn(huePubSub, 'publish').mockImplementation((topic, cb) => {
+      if (topic === GET_KNOWN_CONFIG_EVENT && cb) {
+        cb({
+          app_config: {
+            editor: {
+              interpreters: [
+                { type: 'hive', dialect: 'hive' },
+                { type: 'impala', dialect: 'impala' }
+              ]
+            }
+          }
+        });
+      }
+    });
+
     const notebook = new Notebook(viewModel, {});
     notebook.addSnippet({ connector: { dialect: 'hive' } });
     notebook.addSnippet({ connector: { dialect: 'impala' } });
 
+    expect(spy).toHaveBeenCalled();
+
+    spy.mockRestore();
+
     const notebookJSON = await notebook.toJson();
 
     const notebookRaw = JSON.parse(notebookJSON);

+ 4 - 1
desktop/core/src/desktop/js/apps/notebook2/snippet.js

@@ -216,7 +216,10 @@ export default class Snippet {
           }
         } else if (snippetRaw.type) {
           // In the past "type" was used to denote dialect.
-          this.connector(connectors.find(connector => connector.dialect === snippetRaw.type));
+          this.connector(
+            connectors.find(connector => connector.dialect === snippetRaw.type) ||
+              connectors.find(connector => connector.type === snippetRaw.type)
+          );
         }
       }
     });

+ 28 - 0
desktop/core/src/desktop/js/apps/notebook2/snippet.test.js

@@ -16,6 +16,8 @@
 
 import Notebook from './notebook';
 import sessionManager from 'apps/notebook2/execution/sessionManager';
+import { GET_KNOWN_CONFIG_EVENT } from 'utils/hueConfig';
+import huePubSub from 'utils/huePubSub';
 
 describe('snippet.js', () => {
   const viewModel = {
@@ -33,14 +35,40 @@ describe('snippet.js', () => {
     }
   };
 
+  const previousEnableNotebook2 = window.ENABLE_NOTEBOOK_2;
+
+  beforeAll(() => {
+    window.ENABLE_NOTEBOOK_2 = true;
+  });
+
+  afterAll(() => {
+    window.ENABLE_NOTEBOOK_2 = previousEnableNotebook2;
+  });
+
   beforeEach(() => {
     jest.spyOn(sessionManager, 'getSession').mockImplementation(() => Promise.resolve());
   });
 
   it('should serialize a snippet context to JSON', async () => {
+    const spy = jest.spyOn(huePubSub, 'publish').mockImplementation((topic, cb) => {
+      if (topic === GET_KNOWN_CONFIG_EVENT && cb) {
+        cb({
+          app_config: {
+            editor: {
+              interpreters: [{ type: 'hive', dialect: 'hive' }]
+            }
+          }
+        });
+      }
+    });
+
     const notebook = new Notebook(viewModel, {});
     const snippet = notebook.addSnippet({ connector: { dialect: 'hive' } });
 
+    expect(spy).toHaveBeenCalled();
+
+    spy.mockRestore();
+
     const snippetContextJSON = snippet.toContextJson();
 
     const snippetContextRaw = JSON.parse(snippetContextJSON);

+ 16 - 14
desktop/core/src/desktop/js/ko/bindings/ace/aceLocationHandler.js

@@ -24,7 +24,7 @@ import I18n from 'utils/i18n';
 import sqlStatementsParser from 'parse/sqlStatementsParser';
 import sqlUtils from 'sql/sqlUtils';
 import stringDistance from 'sql/stringDistance';
-import { EXECUTABLE_UPDATED_EVENT } from 'apps/notebook2/execution/executable';
+import { DIALECT } from 'apps/notebook2/snippet';
 
 // TODO: depends on Ace, sqlStatementsParser
 
@@ -56,6 +56,8 @@ class AceLocationHandler {
     self.attachSqlWorker();
     self.attachMouseListeners();
 
+    self.dialect = () => (window.ENABLE_NOTEBOOK_2 ? self.snippet.dialect() : self.snippet.type());
+
     self.verifyThrottle = -1;
 
     const updateDatabaseIndex = function(databaseList) {
@@ -180,7 +182,7 @@ class AceLocationHandler {
                     // Note, as cachedOnly is set to true it will call the successCallback right away (or not at all)
                     dataCatalog
                       .getEntry({
-                        sourceType: self.snippet.type(),
+                        sourceType: self.dialect(),
                         namespace: self.snippet.namespace(),
                         compute: self.snippet.compute(),
                         temporaryOnly: self.snippet.autocompleteSettings.temporaryOnly,
@@ -400,7 +402,7 @@ class AceLocationHandler {
             } else {
               huePubSub.publish('context.popover.show', {
                 data: token.parseLocation,
-                sourceType: self.snippet.type(),
+                sourceType: self.dialect(),
                 namespace: self.snippet.namespace(),
                 compute: self.snippet.compute(),
                 defaultDatabase: self.snippet.database(),
@@ -414,7 +416,7 @@ class AceLocationHandler {
               data: token.syntaxError,
               editor: self.editor,
               range: range,
-              sourceType: self.snippet.type(),
+              sourceType: self.dialect(),
               defaultDatabase: self.snippet.database(),
               source: source
             });
@@ -693,7 +695,7 @@ class AceLocationHandler {
     const self = this;
     if (
       self.sqlSyntaxWorkerSub !== null &&
-      (self.snippet.type() === 'impala' || self.snippet.type() === 'hive')
+      (self.dialect() === DIALECT.impala || self.dialect() === DIALECT.hive)
     ) {
       const AceRange = ace.require('ace/range').Range;
       const editorChangeTime = self.editor.lastChangeTime;
@@ -723,7 +725,7 @@ class AceLocationHandler {
         beforeCursor: beforeCursor,
         afterCursor: afterCursor,
         statementLocation: statementLocation,
-        type: self.snippet.type()
+        type: self.dialect()
       });
     }
   }
@@ -848,7 +850,7 @@ class AceLocationHandler {
     const deferred = $.Deferred();
     dataCatalog
       .getChildren({
-        sourceType: self.snippet.type(),
+        sourceType: self.dialect(),
         namespace: self.snippet.namespace(),
         compute: self.snippet.compute(),
         temporaryOnly: self.snippet.autocompleteSettings.temporaryOnly,
@@ -966,7 +968,7 @@ class AceLocationHandler {
           if (typeof nextTable.subQuery === 'undefined') {
             dataCatalog
               .getChildren({
-                sourceType: self.snippet.type(),
+                sourceType: self.dialect(),
                 namespace: self.snippet.namespace(),
                 compute: self.snippet.compute(),
                 temporaryOnly: self.snippet.autocompleteSettings.temporaryOnly,
@@ -1085,7 +1087,7 @@ class AceLocationHandler {
               const uniqueValues = [];
               for (let i = 0; i < possibleValues.length; i++) {
                 possibleValues[i].name = sqlUtils.backTickIfNeeded(
-                  self.snippet.type(),
+                  self.dialect(),
                   possibleValues[i].name
                 );
                 const nameLower = possibleValues[i].name.toLowerCase();
@@ -1200,7 +1202,7 @@ class AceLocationHandler {
 
       lastKnownLocations = {
         id: self.editorId,
-        type: self.snippet.type(),
+        type: self.dialect(),
         namespace: self.snippet.namespace(),
         compute: self.snippet.compute(),
         defaultDatabase: self.snippet.database(),
@@ -1219,7 +1221,7 @@ class AceLocationHandler {
       const tokensToVerify = [];
 
       e.data.locations.forEach(location => {
-        if (location.type === 'statementType' && self.snippet.type() !== 'impala') {
+        if (location.type === 'statementType' && self.dialect() !== DIALECT.impala) {
           // We currently only have a good mapping from statement types to impala topics.
           // TODO: Extract links between Hive topic IDs and statement types
           return;
@@ -1240,7 +1242,7 @@ class AceLocationHandler {
           // The parser isn't aware of the DDL so sometimes it marks complex columns as tables
           // I.e. "Impala SELECT a FROM b.c" Is 'b' a database or a table? If table then 'c' is complex
           if (
-            self.snippet.type() === 'impala' &&
+            self.dialect() === DIALECT.impala &&
             location.identifierChain.length > 2 &&
             (location.type === 'table' || location.type === 'column') &&
             self.isDatabase(location.identifierChain[0].name)
@@ -1313,7 +1315,7 @@ class AceLocationHandler {
         }
       });
 
-      if (self.snippet.type() === 'impala' || self.snippet.type() === 'hive') {
+      if (self.dialect() === DIALECT.impala || self.dialect() === DIALECT.hive) {
         self.verifyExists(tokensToVerify, e.data.activeStatementLocations);
       }
       huePubSub.publish('editor.active.locations', lastKnownLocations);
@@ -1338,7 +1340,7 @@ class AceLocationHandler {
             huePubSub.publish('ace.sql.location.worker.post', {
               id: self.snippet.id(),
               statementDetails: statementDetails,
-              type: self.snippet.type(),
+              type: self.dialect(),
               namespace: self.snippet.namespace(),
               compute: self.snippet.compute(),
               defaultDatabase: self.snippet.database()

+ 6 - 1
desktop/core/src/desktop/js/ko/bindings/ace/ko.aceEditor.js

@@ -449,8 +449,13 @@ ko.bindingHandlers.aceEditor = {
         $(document).trigger('editorSizeChanged');
       }
       // automagically change snippet type
+      // TODO: Remove completely, check if used in code, '% dialect'
       const firstLine = editor.session.getLine(0);
-      if (firstLine.indexOf('%') === 0 && firstLine.charAt(firstLine.length - 1) === ' ') {
+      if (
+        !window.ENABLE_NOTEBOOK_2 &&
+        firstLine.indexOf('%') === 0 &&
+        firstLine.charAt(firstLine.length - 1) === ' '
+      ) {
         const availableSnippets = snippet.availableSnippets;
         let removeFirstLine = false;
         for (let i = 0; i < availableSnippets.length; i++) {

+ 37 - 40
desktop/core/src/desktop/js/sql/autocompleteResults.js

@@ -25,6 +25,7 @@ import huePubSub from 'utils/huePubSub';
 import I18n from 'utils/i18n';
 import sqlUtils from 'sql/sqlUtils';
 import { SqlSetOptions, SqlFunctions } from 'sql/sqlFunctions';
+import { DIALECT } from 'apps/notebook2/snippet';
 
 const normalizedColors = HueColors.getNormalizedColors();
 
@@ -273,6 +274,7 @@ class AutocompleteResults {
   constructor(options) {
     const self = this;
     self.snippet = options.snippet;
+    self.dialect = () => (window.ENABLE_NOTEBOOK_2 ? self.snippet.dialect() : self.snippet.type());
     self.editor = options.editor;
     self.temporaryOnly =
       options.snippet.autocompleteSettings && options.snippet.autocompleteSettings.temporaryOnly;
@@ -545,7 +547,7 @@ class AutocompleteResults {
     const databasesDeferred = $.Deferred();
     dataCatalog
       .getEntry({
-        sourceType: self.snippet.type(),
+        sourceType: self.dialect(),
         namespace: self.snippet.namespace(),
         compute: self.snippet.compute(),
         path: [],
@@ -588,11 +590,7 @@ class AutocompleteResults {
         const colRefKeywordSuggestions = [];
         Object.keys(self.parseResult.suggestColRefKeywords).forEach(typeForKeywords => {
           if (
-            SqlFunctions.matchesType(
-              self.snippet.type(),
-              [typeForKeywords],
-              [colRef.type.toUpperCase()]
-            )
+            SqlFunctions.matchesType(self.dialect(), [typeForKeywords], [colRef.type.toUpperCase()])
           ) {
             self.parseResult.suggestColRefKeywords[typeForKeywords].forEach(keyword => {
               colRefKeywordSuggestions.push({
@@ -684,7 +682,7 @@ class AutocompleteResults {
     const self = this;
     if (self.parseResult.suggestSetOptions) {
       const suggestions = [];
-      SqlSetOptions.suggestOptions(self.snippet.type(), suggestions, CATEGORIES.OPTION);
+      SqlSetOptions.suggestOptions(self.dialect(), suggestions, CATEGORIES.OPTION);
       self.appendEntries(suggestions);
     }
   }
@@ -701,7 +699,7 @@ class AutocompleteResults {
 
         colRefDeferred.done(colRef => {
           const functionsToSuggest = SqlFunctions.getFunctionsWithReturnTypes(
-            self.snippet.type(),
+            self.dialect(),
             [colRef.type.toUpperCase()],
             self.parseResult.suggestAggregateFunctions || false,
             self.parseResult.suggestAnalyticFunctions || false
@@ -729,7 +727,7 @@ class AutocompleteResults {
       } else {
         const types = self.parseResult.suggestFunctions.types || ['T'];
         const functionsToSuggest = SqlFunctions.getFunctionsWithReturnTypes(
-          self.snippet.type(),
+          self.dialect(),
           types,
           self.parseResult.suggestAggregateFunctions || false,
           self.parseResult.suggestAnalyticFunctions || false
@@ -773,7 +771,7 @@ class AutocompleteResults {
           databaseSuggestions.push({
             value:
               prefix +
-              sqlUtils.backTickIfNeeded(self.snippet.type(), dbEntry.name) +
+              sqlUtils.backTickIfNeeded(self.dialect(), dbEntry.name) +
               (suggestDatabases.appendDot ? '.' : ''),
             filterValue: dbEntry.name,
             meta: META_I18n.database,
@@ -810,7 +808,7 @@ class AutocompleteResults {
 
         dataCatalog
           .getEntry({
-            sourceType: self.snippet.type(),
+            sourceType: self.dialect(),
             namespace: self.snippet.namespace(),
             compute: self.snippet.compute(),
             path: [database],
@@ -831,8 +829,7 @@ class AutocompleteResults {
                       return;
                     }
                     tableSuggestions.push({
-                      value:
-                        prefix + sqlUtils.backTickIfNeeded(self.snippet.type(), tableEntry.name),
+                      value: prefix + sqlUtils.backTickIfNeeded(self.dialect(), tableEntry.name),
                       filterValue: tableEntry.name,
                       tableName: tableEntry.name,
                       meta: META_I18n[tableEntry.getType().toLowerCase()],
@@ -851,7 +848,7 @@ class AutocompleteResults {
       };
 
       if (
-        self.snippet.type() === 'impala' &&
+        self.dialect() === DIALECT.impala &&
         self.parseResult.suggestTables.identifierChain &&
         self.parseResult.suggestTables.identifierChain.length === 1
       ) {
@@ -872,7 +869,7 @@ class AutocompleteResults {
           }
         });
       } else if (
-        self.snippet.type() === 'impala' &&
+        self.dialect() === DIALECT.impala &&
         self.parseResult.suggestTables.identifierChain &&
         self.parseResult.suggestTables.identifierChain.length > 1
       ) {
@@ -908,7 +905,7 @@ class AutocompleteResults {
           $.when.apply($, columnDeferrals).always(() => {
             AutocompleteResults.mergeColumns(columnSuggestions);
             if (
-              self.snippet.type() === 'hive' &&
+              self.dialect() === DIALECT.hive &&
               /[^.]$/.test(self.editor().getTextBeforeCursor())
             ) {
               columnSuggestions.push({
@@ -975,7 +972,7 @@ class AutocompleteResults {
                 typeof column.type !== 'undefined' && column.type !== 'COLREF' ? column.type : 'T';
               if (typeof column.alias !== 'undefined') {
                 columnSuggestions.push({
-                  value: sqlUtils.backTickIfNeeded(self.snippet.type(), column.alias),
+                  value: sqlUtils.backTickIfNeeded(self.dialect(), column.alias),
                   filterValue: column.alias,
                   meta: type,
                   category: CATEGORIES.COLUMN,
@@ -991,7 +988,7 @@ class AutocompleteResults {
               ) {
                 columnSuggestions.push({
                   value: sqlUtils.backTickIfNeeded(
-                    self.snippet.type(),
+                    self.dialect(),
                     column.identifierChain[column.identifierChain.length - 1].name
                   ),
                   filterValue: column.identifierChain[column.identifierChain.length - 1].name,
@@ -1027,7 +1024,7 @@ class AutocompleteResults {
               typeof column.type !== 'undefined' && column.type !== 'COLREF' ? column.type : 'T';
             if (column.alias) {
               columnSuggestions.push({
-                value: sqlUtils.backTickIfNeeded(self.snippet.type(), column.alias),
+                value: sqlUtils.backTickIfNeeded(self.dialect(), column.alias),
                 filterValue: column.alias,
                 meta: type,
                 category: CATEGORIES.COLUMN,
@@ -1038,7 +1035,7 @@ class AutocompleteResults {
             } else if (column.identifierChain && column.identifierChain.length > 0) {
               columnSuggestions.push({
                 value: sqlUtils.backTickIfNeeded(
-                  self.snippet.type(),
+                  self.dialect(),
                   column.identifierChain[column.identifierChain.length - 1].name
                 ),
                 filterValue: column.identifierChain[column.identifierChain.length - 1].name,
@@ -1072,19 +1069,19 @@ class AutocompleteResults {
                   .getChildren({ silenceErrors: true, cancellable: true })
                   .done(childEntries => {
                     childEntries.forEach(childEntry => {
-                      let name = sqlUtils.backTickIfNeeded(self.snippet.type(), childEntry.name);
+                      let name = sqlUtils.backTickIfNeeded(self.dialect(), childEntry.name);
                       if (
-                        self.snippet.type() === 'hive' &&
+                        self.dialect() === DIALECT.hive &&
                         (childEntry.isArray() || childEntry.isMap())
                       ) {
                         name += '[]';
                       }
                       if (
-                        SqlFunctions.matchesType(self.snippet.type(), types, [
+                        SqlFunctions.matchesType(self.dialect(), types, [
                           childEntry.getType().toUpperCase()
                         ]) ||
                         SqlFunctions.matchesType(
-                          self.snippet.type(),
+                          self.dialect(),
                           [childEntry.getType().toUpperCase()],
                           types
                         ) ||
@@ -1110,7 +1107,7 @@ class AutocompleteResults {
                       }
                     });
                     if (
-                      self.snippet.type() === 'hive' &&
+                      self.dialect() === DIALECT.hive &&
                       (dataCatalogEntry.isArray() || dataCatalogEntry.isMap())
                     ) {
                       // Remove 'item' or 'value' and 'key' for Hive
@@ -1124,7 +1121,7 @@ class AutocompleteResults {
                       (sourceMeta.value && sourceMeta.value.fields) ||
                       (sourceMeta.item && sourceMeta.item.fields);
                     if (
-                      (self.snippet.type() === 'impala' || self.snippet.type() === 'hive') &&
+                      (self.dialect() === DIALECT.impala || self.dialect() === DIALECT.hive) &&
                       complexExtras
                     ) {
                       complexExtras.forEach(field => {
@@ -1412,7 +1409,7 @@ class AutocompleteResults {
       if (paths.length) {
         dataCatalog
           .getMultiTableEntry({
-            sourceType: self.snippet.type(),
+            sourceType: self.dialect(),
             namespace: self.snippet.namespace(),
             compute: self.snippet.compute(),
             paths: paths
@@ -1475,13 +1472,13 @@ class AutocompleteResults {
                             self.convertNavOptQualifiedIdentifier(
                               joinColPair.columns[0],
                               suggestJoins.tables,
-                              self.snippet.type()
+                              self.dialect()
                             ) +
                             ' = ' +
                             self.convertNavOptQualifiedIdentifier(
                               joinColPair.columns[1],
                               suggestJoins.tables,
-                              self.snippet.type()
+                              self.dialect()
                             );
                           first = false;
                         });
@@ -1532,7 +1529,7 @@ class AutocompleteResults {
       if (paths.length) {
         dataCatalog
           .getMultiTableEntry({
-            sourceType: self.snippet.type(),
+            sourceType: self.dialect(),
             namespace: self.snippet.namespace(),
             compute: self.snippet.compute(),
             paths: paths
@@ -1621,7 +1618,7 @@ class AutocompleteResults {
       if (paths.length) {
         dataCatalog
           .getMultiTableEntry({
-            sourceType: self.snippet.type(),
+            sourceType: self.dialect(),
             namespace: self.snippet.namespace(),
             compute: self.snippet.compute(),
             paths: paths
@@ -1684,7 +1681,7 @@ class AutocompleteResults {
                       });
                       totalCount += value.totalQueryCount;
                       value.function = SqlFunctions.findFunction(
-                        self.snippet.type(),
+                        self.dialect(),
                         value.aggregateFunction
                       );
                       aggregateFunctionsSuggestions.push({
@@ -1739,7 +1736,7 @@ class AutocompleteResults {
 
     self.cancellablePromises.push(
       dataCatalog
-        .getCatalog(self.snippet.type())
+        .getCatalog(self.dialect())
         .loadNavOptPopularityForTables({
           namespace: self.snippet.namespace(),
           compute: self.snippet.compute(),
@@ -1848,7 +1845,7 @@ class AutocompleteResults {
       if (paths.length) {
         dataCatalog
           .getMultiTableEntry({
-            sourceType: self.snippet.type(),
+            sourceType: self.dialect(),
             namespace: self.snippet.namespace(),
             compute: self.snippet.compute(),
             paths: paths
@@ -1939,7 +1936,7 @@ class AutocompleteResults {
 
       dataCatalog
         .getEntry({
-          sourceType: self.snippet.type(),
+          sourceType: self.dialect(),
           namespace: self.snippet.namespace(),
           compute: self.snippet.compute(),
           path: [db],
@@ -2025,7 +2022,7 @@ class AutocompleteResults {
 
       self.cancellablePromises.push(
         dataCatalog
-          .getCatalog(self.snippet.type())
+          .getCatalog(self.dialect())
           .loadNavOptPopularityForTables({
             namespace: self.snippet.namespace(),
             compute: self.snippet.compute(),
@@ -2244,7 +2241,7 @@ class AutocompleteResults {
 
       dataCatalog
         .getEntry({
-          sourceType: self.snippet.type(),
+          sourceType: self.dialect(),
           namespace: self.snippet.namespace(),
           compute: self.snippet.compute(),
           path: fetchedPath,
@@ -2256,7 +2253,7 @@ class AutocompleteResults {
               .getSourceMeta({ silenceErrors: true, cancellable: true })
               .done(sourceMeta => {
                 if (
-                  self.snippet.type() === 'hive' &&
+                  self.dialect() === DIALECT.hive &&
                   typeof sourceMeta.extended_columns !== 'undefined' &&
                   sourceMeta.extended_columns.length === 1 &&
                   /^(?:map|array|struct)/i.test(sourceMeta.extended_columns[0].type)
@@ -2287,10 +2284,10 @@ class AutocompleteResults {
 
     // For Hive it could be either:
     // SELECT col.struct FROM db.tbl -or- SELECT col.struct FROM tbl
-    if (path.length > 1 && (self.snippet.type() === 'impala' || self.snippet.type() === 'hive')) {
+    if (path.length > 1 && (self.dialect() === DIALECT.impala || self.dialect() === DIALECT.hive)) {
       dataCatalog
         .getEntry({
-          sourceType: self.snippet.type(),
+          sourceType: self.dialect(),
           namespace: self.snippet.namespace(),
           compute: self.snippet.compute(),
           path: [],

+ 4 - 2
desktop/core/src/desktop/js/sql/sqlAutocompleter.js

@@ -75,7 +75,9 @@ class SqlAutocompleter {
               }
             }) + this.fixedPostfix();
           sqlParserRepository
-            .getAutocompleter(this.snippet.type())
+            .getAutocompleter(
+              window.ENABLE_NOTEBOOK_2 ? this.snippet.dialect() : this.snippet.type()
+            )
             .then(autocompleteParser => {
               resolve(autocompleteParser.parseSql(beforeCursor, afterCursor));
             })
@@ -95,7 +97,7 @@ class SqlAutocompleter {
   async parseAll() {
     return new Promise((resolve, reject) => {
       sqlParserRepository
-        .getAutocompleter(this.snippet.type())
+        .getAutocompleter(window.ENABLE_NOTEBOOK_2 ? this.snippet.dialect() : this.snippet.type())
         .then(autocompleteParser => {
           resolve(
             autocompleteParser.parseSql(