Skip to content

Commit

Permalink
adding logic in utils.ts for changing the parser according to hplsql …
Browse files Browse the repository at this point in the history
…mode
  • Loading branch information
agl29 committed Sep 23, 2021
1 parent 818759c commit 6385a12
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions desktop/core/src/desktop/js/apps/editor/execution/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {}

Expand Down
6 changes: 4 additions & 2 deletions desktop/core/src/desktop/js/apps/notebook/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions desktop/core/src/desktop/js/hue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
27 changes: 27 additions & 0 deletions desktop/core/src/desktop/js/parse/utils.ts
Original file line number Diff line number Diff line change
@@ -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;
}
};
3 changes: 2 additions & 1 deletion desktop/core/src/desktop/templates/global_js_constants.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 6385a12

Please sign in to comment.