Explorar o código

[editor] Remove snippet dependency from AceEditor component related modules

Johan Ahlen %!s(int64=5) %!d(string=hai) anos
pai
achega
cf8ec6ece2

+ 7 - 5
desktop/core/src/desktop/js/apps/notebook2/components/aceEditor/AceLocationHandler.ts

@@ -36,7 +36,6 @@ import I18n from 'utils/i18n';
 import sqlStatementsParser, { ParsedSqlStatement } from 'parse/sqlStatementsParser';
 import sqlUtils from 'sql/sqlUtils';
 import stringDistance from 'sql/stringDistance';
-import { DIALECT } from 'apps/notebook2/snippet';
 import {
   POST_FROM_LOCATION_WORKER_EVENT,
   POST_FROM_SYNTAX_WORKER_EVENT,
@@ -60,6 +59,9 @@ export const ACTIVE_STATEMENT_CHANGED_EVENT = 'editor.active.statement.changed';
 export const CURSOR_POSITION_CHANGED_EVENT = 'editor.cursor.position.changed';
 export const GET_ACTIVE_LOCATIONS_EVENT = 'get.active.editor.locations';
 
+const HIVE_DIALECT = 'hive';
+const IMPALA_DIALECT = 'impala';
+
 const STATEMENT_COUNT_AROUND_ACTIVE = 10;
 
 const VERIFY_LIMIT = 50;
@@ -755,7 +757,7 @@ export default class AceLocationHandler implements Disposable {
   checkForSyntaxErrors(statementLocation: ParsedLocation, cursorPosition: Ace.Position): void {
     if (
       this.sqlSyntaxWorkerSub &&
-      (this.getDialect() === DIALECT.impala || this.getDialect() === DIALECT.hive)
+      (this.getDialect() === IMPALA_DIALECT || this.getDialect() === HIVE_DIALECT)
     ) {
       const AceRange = ace.require('ace/range').Range;
       const editorChangeTime = this.editor.lastChangeTime;
@@ -1289,7 +1291,7 @@ export default class AceLocationHandler implements Disposable {
         const tokensToVerify: Ace.HueToken[] = [];
 
         e.data.locations.forEach(location => {
-          if (location.type === 'statementType' && this.getDialect() !== DIALECT.impala) {
+          if (location.type === 'statementType' && this.getDialect() !== IMPALA_DIALECT) {
             // We currently only have a good mapping from statement types to impala topics.
             // TODO: Extract links between Hive topic IDs and statement types
             return;
@@ -1311,7 +1313,7 @@ export default class AceLocationHandler implements Disposable {
             // 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 (
-              this.getDialect() === DIALECT.impala &&
+              this.getDialect() === IMPALA_DIALECT &&
               location.identifierChain.length > 2 &&
               (location.type === 'table' || location.type === 'column') &&
               this.isDatabase(location.identifierChain[0].name)
@@ -1384,7 +1386,7 @@ export default class AceLocationHandler implements Disposable {
           }
         });
 
-        if (this.getDialect() === DIALECT.impala || this.getDialect() === DIALECT.hive) {
+        if (this.getDialect() === IMPALA_DIALECT || this.getDialect() === HIVE_DIALECT) {
           this.verifyExists(tokensToVerify, e.data.activeStatementLocations);
         }
         huePubSub.publish('editor.active.locations', lastKnownLocations);

+ 12 - 10
desktop/core/src/desktop/js/apps/notebook2/components/aceEditor/autocomplete/AutocompleteResults.ts

@@ -48,7 +48,6 @@ import hueUtils from 'utils/hueUtils';
 import I18n from 'utils/i18n';
 import sqlUtils from 'sql/sqlUtils';
 import { matchesType } from 'sql/reference/typeUtils';
-import { DIALECT } from 'apps/notebook2/snippet';
 import { cancelActiveRequest } from 'api/apiUtils';
 import { findBrowserConnector, getRootFilePath } from 'utils/hueConfig';
 import {
@@ -128,6 +127,9 @@ const MetaLabels = {
   Virtual: I18n('virtual')
 };
 
+const HIVE_DIALECT = 'hive';
+const IMPALA_DIALECT = 'impala';
+
 const locateSubQuery = (subQueries: SubQuery[], subQueryName: string): SubQuery | undefined => {
   if (subQueries) {
     return subQueries.find(knownSubQuery =>
@@ -653,7 +655,7 @@ class AutocompleteResults {
 
     let tableSuggestions: Suggestion[] = [];
     if (
-      this.dialect() === DIALECT.impala &&
+      this.dialect() === IMPALA_DIALECT &&
       suggestTables.identifierChain &&
       suggestTables.identifierChain.length === 1
     ) {
@@ -671,7 +673,7 @@ class AutocompleteResults {
         }
       } catch (err) {}
     } else if (
-      this.dialect() === DIALECT.impala &&
+      this.dialect() === IMPALA_DIALECT &&
       suggestTables.identifierChain &&
       suggestTables.identifierChain.length > 1
     ) {
@@ -726,7 +728,7 @@ class AutocompleteResults {
 
     AutocompleteResults.mergeColumns(columnSuggestions);
 
-    if (this.dialect() === DIALECT.hive && /[^.]$/.test(this.editor.getTextBeforeCursor())) {
+    if (this.dialect() === HIVE_DIALECT && /[^.]$/.test(this.editor.getTextBeforeCursor())) {
       columnSuggestions.push({
         value: 'BLOCK__OFFSET__INSIDE__FILE',
         meta: MetaLabels.Virtual,
@@ -889,7 +891,7 @@ class AutocompleteResults {
 
         for (const childEntry of childEntries) {
           let name = await sqlUtils.backTickIfNeeded(this.executor.connector(), childEntry.name);
-          if (this.dialect() === DIALECT.hive && (childEntry.isArray() || childEntry.isMap())) {
+          if (this.dialect() === HIVE_DIALECT && (childEntry.isArray() || childEntry.isMap())) {
             name += '[]';
           }
           if (
@@ -915,7 +917,7 @@ class AutocompleteResults {
           }
         }
         if (
-          this.dialect() === DIALECT.hive &&
+          this.dialect() === HIVE_DIALECT &&
           (dataCatalogEntry.isArray() || dataCatalogEntry.isMap())
         ) {
           // Remove 'item' or 'value' and 'key' for Hive
@@ -929,7 +931,7 @@ class AutocompleteResults {
           (sourceMeta.value && sourceMeta.value.fields) ||
           (sourceMeta.item && sourceMeta.item.fields);
         if (
-          (this.dialect() === DIALECT.impala || this.dialect() === DIALECT.hive) &&
+          (this.dialect() === IMPALA_DIALECT || this.dialect() === HIVE_DIALECT) &&
           complexExtras
         ) {
           complexExtras.forEach(field => {
@@ -2007,7 +2009,7 @@ class AutocompleteResults {
     ) {
       return qualifiedIdentifier.substring(this.activeDatabase.length + 1);
     }
-    if (this.dialect() === DIALECT.hive) {
+    if (this.dialect() === HIVE_DIALECT) {
       // Remove DB reference if given for Hive
       const parts = qualifiedIdentifier.split('.');
       if (parts.length > 2) {
@@ -2085,7 +2087,7 @@ class AutocompleteResults {
       });
 
       if (
-        this.dialect() === DIALECT.hive &&
+        this.dialect() === HIVE_DIALECT &&
         typeof sourceMeta.extended_columns !== 'undefined' &&
         sourceMeta.extended_columns.length === 1 &&
         /^(?:map|array|struct)/i.test(sourceMeta.extended_columns[0].type)
@@ -2114,7 +2116,7 @@ class AutocompleteResults {
 
     // For Hive it could be either:
     // SELECT col.struct FROM db.tbl -or- SELECT col.struct FROM tbl
-    if (path.length > 1 && (this.dialect() === DIALECT.impala || this.dialect() === DIALECT.hive)) {
+    if (path.length > 1 && (this.dialect() === IMPALA_DIALECT || this.dialect() === HIVE_DIALECT)) {
       const catalogEntry = await new Promise<DataCatalogEntry>((resolve, reject) => {
         this.onCancelFunctions.push(reject);
         dataCatalog