Преглед на файлове

adding logic in utils.ts for changing the parser according to hplsql mode

ayush.goyal преди 4 години
родител
ревизия
6385a12199

+ 5 - 2
desktop/core/src/desktop/js/apps/editor/components/aceEditor/AceLocationHandler.ts

@@ -40,7 +40,8 @@ import { EditorInterpreter } from 'config/types';
 import { hueWindow } from 'types/types';
 import huePubSub, { HueSubscription } from 'utils/huePubSub';
 import I18n from 'utils/i18n';
-import sqlStatementsParser, { ParsedSqlStatement } from 'parse/sqlStatementsParser';
+import { ParsedSqlStatement } from 'parse/sqlStatementsParser';
+import { getStatementsParser } from 'parse/utils';
 import sqlUtils from 'sql/sqlUtils';
 import stringDistance from 'sql/stringDistance';
 import {
@@ -738,7 +739,9 @@ export default class AceLocationHandler implements Disposable {
     if (this.isSqlDialect()) {
       try {
         const lastChangeTime = this.editor.lastChangeTime;
-        this.lastKnownStatements.statements = sqlStatementsParser.parse(this.editor.getValue());
+        this.lastKnownStatements.statements = getStatementsParser(this.executor.connector()).parse(
+          this.editor.getValue()
+        );
         this.lastKnownStatements.editorChangeTime = lastChangeTime;
 
         const hueDebug = (<hueWindow>window).hueDebug;

+ 3 - 2
desktop/core/src/desktop/js/apps/editor/execution/api.ts

@@ -32,7 +32,8 @@ import { ResultRow, ResultType } from 'apps/editor/execution/executionResult';
 import { CancellablePromise } from 'api/cancellablePromise';
 import SubscriptionTracker from 'components/utils/SubscriptionTracker';
 import { Compute, Connector, Namespace } from 'config/types';
-import sqlStatementsParser, { ParsedSqlStatement } from 'parse/sqlStatementsParser';
+import { ParsedSqlStatement } from 'parse/sqlStatementsParser';
+import { getStatementsParser } from 'parse/utils';
 
 type SessionPropertyValue = string | number | boolean | null | undefined;
 
@@ -307,7 +308,7 @@ export const executeSingleStatement = ({
     let parsedStatement: ParsedSqlStatement | undefined = undefined;
 
     try {
-      const parsedStatements = sqlStatementsParser.parse(statement);
+      const parsedStatements = getStatementsParser(connector).parse(statement);
       parsedStatement = parsedStatements[0];
     } catch {}
 

+ 4 - 2
desktop/core/src/desktop/js/apps/notebook/snippet.js

@@ -27,7 +27,7 @@ import huePubSub from 'utils/huePubSub';
 import { getFromLocalStorage, setInLocalStorage } from 'utils/storageUtils';
 import Result from 'apps/notebook/result';
 import Session from 'apps/notebook/session';
-import sqlStatementsParser from 'parse/sqlStatementsParser';
+import { getStatementsParser } from 'parse/utils';
 import { SHOW_EVENT as SHOW_GIST_MODAL_EVENT } from 'ko/components/ko.shareGistModal';
 import { cancelActiveRequest } from 'api/apiUtils';
 import { ACTIVE_SNIPPET_CONNECTOR_CHANGED_EVENT } from 'apps/editor/events';
@@ -1823,7 +1823,9 @@ class Snippet {
         data => {
           try {
             if (self.isSqlDialect() && data && data.handle) {
-              self.lastExecutedStatement(sqlStatementsParser.parse(data.handle.statement)[0]);
+              self.lastExecutedStatement(
+                getStatementsParser(self.connector()).parse(data.handle.statement)[0]
+              );
             } else {
               self.lastExecutedStatement(null);
             }

+ 2 - 0
desktop/core/src/desktop/js/hue.js

@@ -70,6 +70,7 @@ import NotebookViewModel from 'apps/notebook/NotebookViewModel'; // In history,
 import HdfsAutocompleter from 'utils/hdfsAutocompleter';
 import SqlAutocompleter from 'sql/sqlAutocompleter';
 import sqlStatementsParser from 'parse/sqlStatementsParser'; // In search.ko and notebook.ko
+import hplsqlStatementsParser from 'parse/hplsqlStatementsParser';
 import HueFileEntry from 'doc/hueFileEntry';
 import HueDocument from 'doc/hueDocument';
 import { getLastKnownConfig, refreshConfig } from 'config/hueConfig';
@@ -111,6 +112,7 @@ window.qq = qq;
 window.sprintf = sprintf;
 window.SqlAutocompleter = SqlAutocompleter;
 window.sqlStatementsParser = sqlStatementsParser;
+window.hplsqlStatementsParser = hplsqlStatementsParser;
 window.sqlUtils = sqlUtils;
 
 $(document).ready(async () => {

+ 4 - 2
desktop/core/src/desktop/js/ko/bindings/ace/aceLocationHandler.js

@@ -20,7 +20,7 @@ import ace from 'ext/aceHelper';
 import { DIALECT } from 'apps/editor/snippet';
 import dataCatalog from 'catalog/dataCatalog';
 import AssistStorageEntry from 'ko/components/assist/assistStorageEntry';
-import sqlStatementsParser from 'parse/sqlStatementsParser';
+import { getStatementsParser } from 'parse/utils';
 import sqlUtils from 'sql/sqlUtils';
 import {
   POST_FROM_LOCATION_WORKER_EVENT,
@@ -610,7 +610,9 @@ class AceLocationHandler {
       if (self.snippet.isSqlDialect()) {
         try {
           const lastChangeTime = self.editor.lastChangeTime;
-          lastKnownStatements = sqlStatementsParser.parse(self.editor.getValue());
+          lastKnownStatements = getStatementsParser(self.snippet.connector()).parse(
+            self.editor.getValue()
+          );
           lastKnownStatements.editorChangeTime = lastChangeTime;
 
           if (typeof hueDebug !== 'undefined' && hueDebug.logStatementLocations) {

+ 4 - 2
desktop/core/src/desktop/js/ko/components/contextPopover/ko.quickQueryContext.js

@@ -29,7 +29,7 @@ import { CONFIG_REFRESHED_TOPIC } from 'config/events';
 import { filterEditorConnectors } from 'config/hueConfig';
 import componentUtils from 'ko/components/componentUtils';
 import DisposableComponent from 'ko/components/DisposableComponent';
-import sqlStatementsParser from 'parse/sqlStatementsParser';
+import { getStatementsParser } from 'parse/utils';
 
 export const NAME = 'quick-query-context';
 
@@ -143,7 +143,9 @@ class QuickQueryContext extends DisposableComponent {
     const refreshExecutable = () => {
       window.clearTimeout(refreshExecutableThrottle);
       refreshExecutableThrottle = window.setTimeout(() => {
-        const parsedStatement = sqlStatementsParser.parse(this.statement() || '')[0];
+        const parsedStatement = getStatementsParser(this.connector()).parse(
+          this.statement() || ''
+        )[0];
 
         const executable = new SqlExecutable({
           executor: this.executor,

+ 2 - 0
desktop/core/src/desktop/js/parse/hplsqlStatementsParser.test.js

@@ -82,11 +82,13 @@ describe('hplsqlStatementsParser.js', () => {
       "CREATE PROCEDURE greet(name STRING)\nBEGIN\n  PRINT 'Hello ' || name;\nEND;/\nprint 'world';",
       [
         {
+          type: 'statement',
           statement: "CREATE PROCEDURE greet(name STRING)\nBEGIN\n  PRINT 'Hello ' || name;\nEND;;",
           location: { first_line: 1, first_column: 0, last_line: 4, last_column: 5 },
           firstToken: 'CREATE'
         },
         {
+          type: 'statement',
           statement: "\nprint 'world';",
           location: { first_line: 4, first_column: 5, last_line: 5, last_column: 14 },
           firstToken: 'print'

+ 27 - 0
desktop/core/src/desktop/js/parse/utils.ts

@@ -0,0 +1,27 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import { Connector } from 'config/types';
+import hplsqlStatementsParser from 'parse/hplsqlStatementsParser';
+import sqlStatementsParser from 'parse/sqlStatementsParser';
+
+export const getStatementsParser = (connector: Connector): any => {
+  if (connector.dialect === 'hive' && window.HPLSQL) {
+    return hplsqlStatementsParser;
+  } else {
+    return sqlStatementsParser;
+  }
+};

+ 2 - 1
desktop/core/src/desktop/templates/global_js_constants.mako

@@ -24,7 +24,7 @@
       VCS, ENABLE_GIST, ENABLE_LINK_SHARING, has_channels, has_connectors, ENABLE_UNIFIED_ANALYTICS, RAZ
   from desktop.models import hue_version, _get_apps, get_cluster_config
 
-  from beeswax.conf import DOWNLOAD_BYTES_LIMIT, DOWNLOAD_ROW_LIMIT, LIST_PARTITIONS_LIMIT, CLOSE_SESSIONS
+  from beeswax.conf import DOWNLOAD_BYTES_LIMIT, DOWNLOAD_ROW_LIMIT, LIST_PARTITIONS_LIMIT, CLOSE_SESSIONS, HPLSQL
   from dashboard.conf import HAS_SQL_ENABLED
   from jobbrowser.conf import ENABLE_HISTORY_V2
   from filebrowser.conf import SHOW_UPLOAD_BUTTON, REMOTE_STORAGE_HOME
@@ -137,6 +137,7 @@
   window.JB_SINGLE_CHECK_INTERVAL_IN_MILLIS = 5000;
   window.JB_MULTI_CHECK_INTERVAL_IN_MILLIS = 20000;
   window.CLOSE_SESSIONS = {'hive': '${ CLOSE_SESSIONS.get() }' === 'True'};
+  window.HPLSQL = '${ HPLSQL.get() }' === 'True';
 
   window.HUE_URLS = {
     IMPORTER_CREATE_TABLE: '${ 'indexer' in apps and url('indexer:importer_prefill', source_type = 'all', target_type = 'table')}',

+ 1 - 1
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -2012,7 +2012,7 @@ var TempDocument = function () {
         if (data && data.data && data.data.snippets.length > 0) {
           self.name(data.document.name);
           var snippet = data.data.snippets[0];
-          self.parsedStatements(sqlStatementsParser.parse(snippet.statement));
+          self.parsedStatements(getStatementsParser(snippet.connector).parse(snippet.statement));
           self.selectedStatement(self.parsedStatements()[0].statement);
           self.selectedStatementId(0);
         }