|
@@ -35,7 +35,10 @@ import huePubSub from 'utils/huePubSub';
|
|
|
import hueUtils from 'utils/hueUtils';
|
|
import hueUtils from 'utils/hueUtils';
|
|
|
import sessionManager from 'apps/notebook2/execution/sessionManager';
|
|
import sessionManager from 'apps/notebook2/execution/sessionManager';
|
|
|
import SqlExecutable from 'apps/notebook2/execution/sqlExecutable';
|
|
import SqlExecutable from 'apps/notebook2/execution/sqlExecutable';
|
|
|
-import { REDRAW_FIXED_HEADERS_EVENT } from 'apps/notebook2/events';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT,
|
|
|
|
|
+ REDRAW_FIXED_HEADERS_EVENT
|
|
|
|
|
+} from 'apps/notebook2/events';
|
|
|
import { EXECUTABLE_UPDATED_EVENT, EXECUTION_STATUS } from 'apps/notebook2/execution/executable';
|
|
import { EXECUTABLE_UPDATED_EVENT, EXECUTION_STATUS } from 'apps/notebook2/execution/executable';
|
|
|
import {
|
|
import {
|
|
|
ACTIVE_STATEMENT_CHANGED_EVENT,
|
|
ACTIVE_STATEMENT_CHANGED_EVENT,
|
|
@@ -43,6 +46,7 @@ import {
|
|
|
} from 'ko/bindings/ace/aceLocationHandler';
|
|
} from 'ko/bindings/ace/aceLocationHandler';
|
|
|
import { EXECUTE_ACTIVE_EXECUTABLE_EVENT } from 'apps/notebook2/components/ko.executableActions';
|
|
import { EXECUTE_ACTIVE_EXECUTABLE_EVENT } from 'apps/notebook2/components/ko.executableActions';
|
|
|
import { UPDATE_HISTORY_EVENT } from 'apps/notebook2/components/ko.queryHistory';
|
|
import { UPDATE_HISTORY_EVENT } from 'apps/notebook2/components/ko.queryHistory';
|
|
|
|
|
+import { GET_KNOWN_CONFIG_EVENT } from 'utils/hueConfig';
|
|
|
|
|
|
|
|
// TODO: Remove for ENABLE_NOTEBOOK_2. Temporary here for debug
|
|
// TODO: Remove for ENABLE_NOTEBOOK_2. Temporary here for debug
|
|
|
window.SqlExecutable = SqlExecutable;
|
|
window.SqlExecutable = SqlExecutable;
|
|
@@ -50,7 +54,7 @@ window.Executor = Executor;
|
|
|
|
|
|
|
|
export const CURRENT_QUERY_TAB_SWITCHED_EVENT = 'current.query.tab.switched';
|
|
export const CURRENT_QUERY_TAB_SWITCHED_EVENT = 'current.query.tab.switched';
|
|
|
|
|
|
|
|
-const TYPE = {
|
|
|
|
|
|
|
+export const DIALECT = {
|
|
|
hive: 'hive',
|
|
hive: 'hive',
|
|
|
impala: 'impala',
|
|
impala: 'impala',
|
|
|
jar: 'jar',
|
|
jar: 'jar',
|
|
@@ -107,68 +111,68 @@ const COMPATIBILITY_SOURCE_PLATFORMS = {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const COMPATIBILITY_TARGET_PLATFORMS = {
|
|
const COMPATIBILITY_TARGET_PLATFORMS = {
|
|
|
- hive: { name: 'Hive', value: TYPE.hive },
|
|
|
|
|
- impala: { name: 'Impala', value: TYPE.impala }
|
|
|
|
|
|
|
+ hive: { name: 'Hive', value: DIALECT.hive },
|
|
|
|
|
+ impala: { name: 'Impala', value: DIALECT.impala }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const getDefaultSnippetProperties = snippetType => {
|
|
const getDefaultSnippetProperties = snippetType => {
|
|
|
const properties = {};
|
|
const properties = {};
|
|
|
|
|
|
|
|
- if (snippetType === TYPE.jar || snippetType === TYPE.py) {
|
|
|
|
|
|
|
+ if (snippetType === DIALECT.jar || snippetType === DIALECT.py) {
|
|
|
properties['driverCores'] = '';
|
|
properties['driverCores'] = '';
|
|
|
properties['executorCores'] = '';
|
|
properties['executorCores'] = '';
|
|
|
properties['numExecutors'] = '';
|
|
properties['numExecutors'] = '';
|
|
|
properties['queue'] = '';
|
|
properties['queue'] = '';
|
|
|
properties['archives'] = [];
|
|
properties['archives'] = [];
|
|
|
properties['files'] = [];
|
|
properties['files'] = [];
|
|
|
- } else if (snippetType === TYPE.java) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.java) {
|
|
|
properties['archives'] = [];
|
|
properties['archives'] = [];
|
|
|
properties['files'] = [];
|
|
properties['files'] = [];
|
|
|
properties['capture_output'] = false;
|
|
properties['capture_output'] = false;
|
|
|
- } else if (snippetType === TYPE.shell) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.shell) {
|
|
|
properties['archives'] = [];
|
|
properties['archives'] = [];
|
|
|
properties['files'] = [];
|
|
properties['files'] = [];
|
|
|
- } else if (snippetType === TYPE.mapreduce) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.mapreduce) {
|
|
|
properties['app_jar'] = '';
|
|
properties['app_jar'] = '';
|
|
|
properties['hadoopProperties'] = [];
|
|
properties['hadoopProperties'] = [];
|
|
|
properties['jars'] = [];
|
|
properties['jars'] = [];
|
|
|
properties['files'] = [];
|
|
properties['files'] = [];
|
|
|
properties['archives'] = [];
|
|
properties['archives'] = [];
|
|
|
- } else if (snippetType === TYPE.spark2) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.spark2) {
|
|
|
properties['app_name'] = '';
|
|
properties['app_name'] = '';
|
|
|
properties['class'] = '';
|
|
properties['class'] = '';
|
|
|
properties['jars'] = [];
|
|
properties['jars'] = [];
|
|
|
properties['spark_opts'] = [];
|
|
properties['spark_opts'] = [];
|
|
|
properties['spark_arguments'] = [];
|
|
properties['spark_arguments'] = [];
|
|
|
properties['files'] = [];
|
|
properties['files'] = [];
|
|
|
- } else if (snippetType === TYPE.sqoop1) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.sqoop1) {
|
|
|
properties['files'] = [];
|
|
properties['files'] = [];
|
|
|
- } else if (snippetType === TYPE.hive) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.hive) {
|
|
|
properties['settings'] = [];
|
|
properties['settings'] = [];
|
|
|
properties['files'] = [];
|
|
properties['files'] = [];
|
|
|
properties['functions'] = [];
|
|
properties['functions'] = [];
|
|
|
properties['arguments'] = [];
|
|
properties['arguments'] = [];
|
|
|
- } else if (snippetType === TYPE.impala) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.impala) {
|
|
|
properties['settings'] = [];
|
|
properties['settings'] = [];
|
|
|
- } else if (snippetType === TYPE.pig) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.pig) {
|
|
|
properties['parameters'] = [];
|
|
properties['parameters'] = [];
|
|
|
properties['hadoopProperties'] = [];
|
|
properties['hadoopProperties'] = [];
|
|
|
properties['resources'] = [];
|
|
properties['resources'] = [];
|
|
|
- } else if (snippetType === TYPE.distcp) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.distcp) {
|
|
|
properties['source_path'] = '';
|
|
properties['source_path'] = '';
|
|
|
properties['destination_path'] = '';
|
|
properties['destination_path'] = '';
|
|
|
- } else if (snippetType === TYPE.shell) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.shell) {
|
|
|
properties['command_path'] = '';
|
|
properties['command_path'] = '';
|
|
|
properties['arguments'] = [];
|
|
properties['arguments'] = [];
|
|
|
properties['env_var'] = [];
|
|
properties['env_var'] = [];
|
|
|
properties['capture_output'] = true;
|
|
properties['capture_output'] = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (snippetType === TYPE.jar || snippetType === TYPE.java) {
|
|
|
|
|
|
|
+ if (snippetType === DIALECT.jar || snippetType === DIALECT.java) {
|
|
|
properties['app_jar'] = '';
|
|
properties['app_jar'] = '';
|
|
|
properties['class'] = '';
|
|
properties['class'] = '';
|
|
|
properties['arguments'] = [];
|
|
properties['arguments'] = [];
|
|
|
- } else if (snippetType === TYPE.py) {
|
|
|
|
|
|
|
+ } else if (snippetType === DIALECT.py) {
|
|
|
properties['py_file'] = '';
|
|
properties['py_file'] = '';
|
|
|
properties['arguments'] = [];
|
|
properties['arguments'] = [];
|
|
|
}
|
|
}
|
|
@@ -185,23 +189,46 @@ export default class Snippet {
|
|
|
|
|
|
|
|
this.id = ko.observable(snippetRaw.id || hueUtils.UUID());
|
|
this.id = ko.observable(snippetRaw.id || hueUtils.UUID());
|
|
|
this.name = ko.observable(snippetRaw.name || '');
|
|
this.name = ko.observable(snippetRaw.name || '');
|
|
|
- this.type = ko.observable();
|
|
|
|
|
- this.type.subscribe(newValue => {
|
|
|
|
|
- // TODO: Add session disposal for ENABLE_NOTEBOOK_2
|
|
|
|
|
- // Pre-create a session to speed up execution
|
|
|
|
|
- sessionManager.getSession({ type: newValue }).then(() => {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ this.connector = ko.observable();
|
|
|
|
|
+
|
|
|
|
|
+ this.dialect = ko.pureComputed(() => this.connector() && this.connector().dialect);
|
|
|
|
|
+
|
|
|
|
|
+ this.isSqlDialect = ko.pureComputed(() => this.connector() && this.connector().is_sql);
|
|
|
|
|
+
|
|
|
|
|
+ this.connector.subscribe(newValue => {
|
|
|
|
|
+ sessionManager.getSession({ type: newValue.type }).then(() => {
|
|
|
this.status(STATUS.ready);
|
|
this.status(STATUS.ready);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- this.type(snippetRaw.type || TYPE.hive);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ huePubSub.publish(GET_KNOWN_CONFIG_EVENT, config => {
|
|
|
|
|
+ if (config && config.app_config && config.app_config.editor) {
|
|
|
|
|
+ const connectors = config.app_config.editor.interpreters;
|
|
|
|
|
+ if (snippetRaw.connector) {
|
|
|
|
|
+ this.connector(
|
|
|
|
|
+ connectors.find(connector => connector.type === snippetRaw.connector.type) ||
|
|
|
|
|
+ connectors.find(connector => connector.dialect === snippetRaw.connector.dialect)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (!this.connector()) {
|
|
|
|
|
+ // Could happen if a connector is removed after a doc has been saved.
|
|
|
|
|
+ this.connector(snippetRaw.connector);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (snippetRaw.type) {
|
|
|
|
|
+ // In the past "type" was used to denote dialect.
|
|
|
|
|
+ this.connector(connectors.find(connector => connector.dialect === snippetRaw.type));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
this.isBatchable = ko.pureComputed(
|
|
this.isBatchable = ko.pureComputed(
|
|
|
() =>
|
|
() =>
|
|
|
- this.type() === this.hive ||
|
|
|
|
|
- this.type() === this.impala ||
|
|
|
|
|
|
|
+ this.dialect() === DIALECT.hive ||
|
|
|
|
|
+ this.dialect() === DIALECT.impala ||
|
|
|
this.parentVm.availableLanguages.some(
|
|
this.parentVm.availableLanguages.some(
|
|
|
language =>
|
|
language =>
|
|
|
- language.type === this.type() &&
|
|
|
|
|
- (language.interface == 'oozie' || language.interface == 'sqlalchemy')
|
|
|
|
|
|
|
+ language.type === this.dialect() && // TODO: language.type = dialect ?
|
|
|
|
|
+ (language.interface === 'oozie' || language.interface === 'sqlalchemy')
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -231,8 +258,8 @@ export default class Snippet {
|
|
|
|
|
|
|
|
this.inFocus.subscribe(newValue => {
|
|
this.inFocus.subscribe(newValue => {
|
|
|
if (newValue) {
|
|
if (newValue) {
|
|
|
- huePubSub.publish('active.snippet.type.changed', {
|
|
|
|
|
- type: this.type(),
|
|
|
|
|
|
|
+ huePubSub.publish(ACTIVE_SNIPPET_DIALECT_CHANGED_EVENT, {
|
|
|
|
|
+ type: this.dialect(),
|
|
|
isSqlDialect: this.isSqlDialect()
|
|
isSqlDialect: this.isSqlDialect()
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -242,16 +269,12 @@ export default class Snippet {
|
|
|
|
|
|
|
|
this.explanation = ko.observable();
|
|
this.explanation = ko.observable();
|
|
|
|
|
|
|
|
- this.getAceMode = () => this.parentVm.getSnippetViewSettings(this.type()).aceMode;
|
|
|
|
|
|
|
+ this.getAceMode = () => this.parentVm.getSnippetViewSettings(this.dialect()).aceMode;
|
|
|
|
|
|
|
|
this.dbSelectionVisible = ko.observable(false);
|
|
this.dbSelectionVisible = ko.observable(false);
|
|
|
|
|
|
|
|
this.showExecutionAnalysis = ko.observable(false);
|
|
this.showExecutionAnalysis = ko.observable(false);
|
|
|
|
|
|
|
|
- this.isSqlDialect = ko.pureComputed(
|
|
|
|
|
- () => this.parentVm.getSnippetViewSettings(this.type()).sqlDialect
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
// namespace and compute might be initialized as empty object {}
|
|
// namespace and compute might be initialized as empty object {}
|
|
|
this.namespace = ko.observable(
|
|
this.namespace = ko.observable(
|
|
|
snippetRaw.namespace && snippetRaw.namespace.id ? snippetRaw.namespace : undefined
|
|
snippetRaw.namespace && snippetRaw.namespace.id ? snippetRaw.namespace : undefined
|
|
@@ -283,8 +306,8 @@ export default class Snippet {
|
|
|
huePubSub.subscribeOnce(
|
|
huePubSub.subscribeOnce(
|
|
|
'assist.source.set',
|
|
'assist.source.set',
|
|
|
source => {
|
|
source => {
|
|
|
- if (source !== this.type()) {
|
|
|
|
|
- huePubSub.publish('assist.set.source', this.type());
|
|
|
|
|
|
|
+ if (source !== this.dialect()) {
|
|
|
|
|
+ huePubSub.publish('assist.set.source', this.dialect());
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
this.parentVm.huePubSubId
|
|
this.parentVm.huePubSubId
|
|
@@ -296,7 +319,7 @@ export default class Snippet {
|
|
|
|
|
|
|
|
if (!this.database()) {
|
|
if (!this.database()) {
|
|
|
huePubSub.publish('assist.get.database.callback', {
|
|
huePubSub.publish('assist.get.database.callback', {
|
|
|
- source: this.type(),
|
|
|
|
|
|
|
+ source: this.dialect(),
|
|
|
callback: databaseDef => {
|
|
callback: databaseDef => {
|
|
|
this.handleAssistSelection(databaseDef);
|
|
this.handleAssistSelection(databaseDef);
|
|
|
}
|
|
}
|
|
@@ -395,16 +418,16 @@ export default class Snippet {
|
|
|
this.statusForButtons = ko.observable(STATUS_FOR_BUTTONS.executed);
|
|
this.statusForButtons = ko.observable(STATUS_FOR_BUTTONS.executed);
|
|
|
|
|
|
|
|
this.properties = ko.observable(
|
|
this.properties = ko.observable(
|
|
|
- komapping.fromJS(snippetRaw.properties || getDefaultSnippetProperties(this.type()))
|
|
|
|
|
|
|
+ komapping.fromJS(snippetRaw.properties || getDefaultSnippetProperties(this.dialect()))
|
|
|
);
|
|
);
|
|
|
this.hasProperties = ko.pureComputed(
|
|
this.hasProperties = ko.pureComputed(
|
|
|
() => Object.keys(komapping.toJS(this.properties())).length > 0
|
|
() => Object.keys(komapping.toJS(this.properties())).length > 0
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- this.viewSettings = ko.pureComputed(() => this.parentVm.getSnippetViewSettings(this.type()));
|
|
|
|
|
|
|
+ this.viewSettings = ko.pureComputed(() => this.parentVm.getSnippetViewSettings(this.dialect()));
|
|
|
|
|
|
|
|
const previousProperties = {};
|
|
const previousProperties = {};
|
|
|
- this.type.subscribe(
|
|
|
|
|
|
|
+ this.dialect.subscribe(
|
|
|
oldValue => {
|
|
oldValue => {
|
|
|
previousProperties[oldValue] = this.properties();
|
|
previousProperties[oldValue] = this.properties();
|
|
|
},
|
|
},
|
|
@@ -412,7 +435,7 @@ export default class Snippet {
|
|
|
'beforeChange'
|
|
'beforeChange'
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- this.type.subscribe(newValue => {
|
|
|
|
|
|
|
+ this.dialect.subscribe(newValue => {
|
|
|
if (typeof previousProperties[newValue] !== 'undefined') {
|
|
if (typeof previousProperties[newValue] !== 'undefined') {
|
|
|
this.properties(previousProperties[newValue]);
|
|
this.properties(previousProperties[newValue]);
|
|
|
} else {
|
|
} else {
|
|
@@ -443,13 +466,13 @@ export default class Snippet {
|
|
|
this.variables.subscribe(() => {
|
|
this.variables.subscribe(() => {
|
|
|
$(document).trigger('updateResultHeaders', this);
|
|
$(document).trigger('updateResultHeaders', this);
|
|
|
});
|
|
});
|
|
|
- this.hasCurlyBracketParameters = ko.pureComputed(() => this.type() !== TYPE.pig);
|
|
|
|
|
|
|
+ this.hasCurlyBracketParameters = ko.pureComputed(() => this.dialect() !== DIALECT.pig);
|
|
|
|
|
|
|
|
this.variableNames = ko.pureComputed(() => {
|
|
this.variableNames = ko.pureComputed(() => {
|
|
|
let match,
|
|
let match,
|
|
|
matches = {},
|
|
matches = {},
|
|
|
matchList;
|
|
matchList;
|
|
|
- if (this.type() === TYPE.pig) {
|
|
|
|
|
|
|
+ if (this.dialect() === DIALECT.pig) {
|
|
|
matches = this.getPigParameters();
|
|
matches = this.getPigParameters();
|
|
|
} else {
|
|
} else {
|
|
|
const re = /(?:^|\W)\${(\w*)=?([^{}]*)}/g;
|
|
const re = /(?:^|\W)\${(\w*)=?([^{}]*)}/g;
|
|
@@ -738,7 +761,7 @@ export default class Snippet {
|
|
|
|
|
|
|
|
this.isLoading = ko.pureComputed(() => this.status() === STATUS.loading);
|
|
this.isLoading = ko.pureComputed(() => this.status() === STATUS.loading);
|
|
|
|
|
|
|
|
- this.resultsKlass = ko.pureComputed(() => 'results ' + this.type());
|
|
|
|
|
|
|
+ this.resultsKlass = ko.pureComputed(() => 'results ' + this.dialect());
|
|
|
|
|
|
|
|
this.errorsKlass = ko.pureComputed(() => this.resultsKlass() + ' alert alert-error');
|
|
this.errorsKlass = ko.pureComputed(() => this.resultsKlass() + ' alert alert-error');
|
|
|
|
|
|
|
@@ -769,11 +792,13 @@ export default class Snippet {
|
|
|
this.compatibilitySourcePlatforms.push(COMPATIBILITY_SOURCE_PLATFORMS[key]);
|
|
this.compatibilitySourcePlatforms.push(COMPATIBILITY_SOURCE_PLATFORMS[key]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- this.compatibilitySourcePlatform = ko.observable(COMPATIBILITY_SOURCE_PLATFORMS[this.type()]);
|
|
|
|
|
|
|
+ this.compatibilitySourcePlatform = ko.observable(
|
|
|
|
|
+ COMPATIBILITY_SOURCE_PLATFORMS[this.dialect()]
|
|
|
|
|
+ );
|
|
|
this.compatibilitySourcePlatform.subscribe(newValue => {
|
|
this.compatibilitySourcePlatform.subscribe(newValue => {
|
|
|
- if (newValue && newValue.value !== this.type()) {
|
|
|
|
|
|
|
+ if (newValue && newValue.value !== this.dialect()) {
|
|
|
this.hasSuggestion(null);
|
|
this.hasSuggestion(null);
|
|
|
- this.compatibilityTargetPlatform(COMPATIBILITY_TARGET_PLATFORMS[this.type()]);
|
|
|
|
|
|
|
+ this.compatibilityTargetPlatform(COMPATIBILITY_TARGET_PLATFORMS[this.dialect()]);
|
|
|
this.queryCompatibility();
|
|
this.queryCompatibility();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -782,7 +807,9 @@ export default class Snippet {
|
|
|
Object.keys(COMPATIBILITY_TARGET_PLATFORMS).forEach(key => {
|
|
Object.keys(COMPATIBILITY_TARGET_PLATFORMS).forEach(key => {
|
|
|
this.compatibilityTargetPlatforms.push(COMPATIBILITY_TARGET_PLATFORMS[key]);
|
|
this.compatibilityTargetPlatforms.push(COMPATIBILITY_TARGET_PLATFORMS[key]);
|
|
|
});
|
|
});
|
|
|
- this.compatibilityTargetPlatform = ko.observable(COMPATIBILITY_TARGET_PLATFORMS[this.type()]);
|
|
|
|
|
|
|
+ this.compatibilityTargetPlatform = ko.observable(
|
|
|
|
|
+ COMPATIBILITY_TARGET_PLATFORMS[this.dialect()]
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
this.showOptimizer = ko.observable(
|
|
this.showOptimizer = ko.observable(
|
|
|
apiHelper.getFromTotalStorage('editor', 'show.optimizer', false)
|
|
apiHelper.getFromTotalStorage('editor', 'show.optimizer', false)
|
|
@@ -903,7 +930,7 @@ export default class Snippet {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- if (this.type() === TYPE.hive || this.type() === TYPE.impala) {
|
|
|
|
|
|
|
+ if (this.dialect() === DIALECT.hive || this.dialect() === DIALECT.impala) {
|
|
|
if (this.statement_raw()) {
|
|
if (this.statement_raw()) {
|
|
|
window.setTimeout(() => {
|
|
window.setTimeout(() => {
|
|
|
this.checkComplexity();
|
|
this.checkComplexity();
|
|
@@ -920,14 +947,15 @@ export default class Snippet {
|
|
|
() =>
|
|
() =>
|
|
|
(this.statementType() === 'text' &&
|
|
(this.statementType() === 'text' &&
|
|
|
((this.isSqlDialect() && this.statement() !== '') ||
|
|
((this.isSqlDialect() && this.statement() !== '') ||
|
|
|
- ([TYPE.jar, TYPE.java, TYPE.spark2, TYPE.distcp].indexOf(this.type()) === -1 &&
|
|
|
|
|
|
|
+ ([DIALECT.jar, DIALECT.java, DIALECT.spark2, DIALECT.distcp].indexOf(this.dialect()) ===
|
|
|
|
|
+ -1 &&
|
|
|
this.statement() !== '') ||
|
|
this.statement() !== '') ||
|
|
|
- ([TYPE.jar, TYPE.java].indexOf(this.type()) !== -1 &&
|
|
|
|
|
|
|
+ ([DIALECT.jar, DIALECT.java].indexOf(this.dialect()) !== -1 &&
|
|
|
(this.properties().app_jar() !== '' && this.properties().class() !== '')) ||
|
|
(this.properties().app_jar() !== '' && this.properties().class() !== '')) ||
|
|
|
- (TYPE.spark2 === this.type() && this.properties().jars().length > 0) ||
|
|
|
|
|
- (TYPE.shell === this.type() && this.properties().command_path().length > 0) ||
|
|
|
|
|
- (TYPE.mapreduce === this.type() && this.properties().app_jar().length > 0) ||
|
|
|
|
|
- (TYPE.distcp === this.type() &&
|
|
|
|
|
|
|
+ (DIALECT.spark2 === this.dialect() && this.properties().jars().length > 0) ||
|
|
|
|
|
+ (DIALECT.shell === this.dialect() && this.properties().command_path().length > 0) ||
|
|
|
|
|
+ (DIALECT.mapreduce === this.dialect() && this.properties().app_jar().length > 0) ||
|
|
|
|
|
+ (DIALECT.distcp === this.dialect() &&
|
|
|
this.properties().source_path().length > 0 &&
|
|
this.properties().source_path().length > 0 &&
|
|
|
this.properties().destination_path().length > 0))) ||
|
|
this.properties().destination_path().length > 0))) ||
|
|
|
(this.statementType() === 'file' && this.statementPath().length > 0) ||
|
|
(this.statementType() === 'file' && this.statementPath().length > 0) ||
|
|
@@ -963,10 +991,11 @@ export default class Snippet {
|
|
|
|
|
|
|
|
this.activeExecutable = ko.observable();
|
|
this.activeExecutable = ko.observable();
|
|
|
|
|
|
|
|
|
|
+ // TODO: User connector instead of compute, namespace, sourceType, isOptimizerEnabled, isSqlEngine
|
|
|
this.executor = new Executor({
|
|
this.executor = new Executor({
|
|
|
compute: this.compute,
|
|
compute: this.compute,
|
|
|
database: this.database,
|
|
database: this.database,
|
|
|
- sourceType: this.type,
|
|
|
|
|
|
|
+ sourceType: this.dialect,
|
|
|
namespace: this.namespace,
|
|
namespace: this.namespace,
|
|
|
isOptimizerEnabled: this.parentVm.isOptimizerEnabled(),
|
|
isOptimizerEnabled: this.parentVm.isOptimizerEnabled(),
|
|
|
snippet: this,
|
|
snippet: this,
|
|
@@ -1011,6 +1040,19 @@ export default class Snippet {
|
|
|
huePubSub.publish(REFRESH_STATEMENT_LOCATIONS_EVENT, this);
|
|
huePubSub.publish(REFRESH_STATEMENT_LOCATIONS_EVENT, this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ changeDialect(dialect) {
|
|
|
|
|
+ huePubSub.publish(GET_KNOWN_CONFIG_EVENT, config => {
|
|
|
|
|
+ if (config && config.app_config && config.app_config.editor) {
|
|
|
|
|
+ const foundConnector = config.app_config.editor.interpreters.find(
|
|
|
|
|
+ connector => connector.dialect === dialect
|
|
|
|
|
+ );
|
|
|
|
|
+ if (foundConnector) {
|
|
|
|
|
+ this.connector(foundConnector);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
updateFromExecutable(executable) {
|
|
updateFromExecutable(executable) {
|
|
|
if (executable) {
|
|
if (executable) {
|
|
|
if (
|
|
if (
|
|
@@ -1049,9 +1091,11 @@ export default class Snippet {
|
|
|
|
|
|
|
|
checkCompatibility() {
|
|
checkCompatibility() {
|
|
|
this.hasSuggestion(null);
|
|
this.hasSuggestion(null);
|
|
|
- this.compatibilitySourcePlatform(COMPATIBILITY_SOURCE_PLATFORMS[this.type()]);
|
|
|
|
|
|
|
+ this.compatibilitySourcePlatform(COMPATIBILITY_SOURCE_PLATFORMS[this.dialect()]);
|
|
|
this.compatibilityTargetPlatform(
|
|
this.compatibilityTargetPlatform(
|
|
|
- COMPATIBILITY_TARGET_PLATFORMS[this.type() === TYPE.hive ? TYPE.impala : TYPE.hive]
|
|
|
|
|
|
|
+ COMPATIBILITY_TARGET_PLATFORMS[
|
|
|
|
|
+ this.dialect() === DIALECT.hive ? DIALECT.impala : DIALECT.hive
|
|
|
|
|
+ ]
|
|
|
);
|
|
);
|
|
|
this.queryCompatibility();
|
|
this.queryCompatibility();
|
|
|
}
|
|
}
|
|
@@ -1063,59 +1107,13 @@ export default class Snippet {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // async executeNext() {
|
|
|
|
|
- // hueAnalytics.log('notebook', 'execute/' + this.type());
|
|
|
|
|
- //
|
|
|
|
|
- // const now = new Date().getTime();
|
|
|
|
|
- // if (now - this.lastExecuted() < 1000) {
|
|
|
|
|
- // return; // Prevent fast clicks
|
|
|
|
|
- // }
|
|
|
|
|
- // this.lastExecuted(now);
|
|
|
|
|
- //
|
|
|
|
|
- // if (this.type() === TYPE.impala) {
|
|
|
|
|
- // this.showExecutionAnalysis(false);
|
|
|
|
|
- // huePubSub.publish('editor.clear.execution.analysis');
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // // Editor based execution
|
|
|
|
|
- // if (this.ace()) {
|
|
|
|
|
- // const selectionRange = this.ace().getSelectionRange();
|
|
|
|
|
- //
|
|
|
|
|
- // huePubSub.publish('ace.set.autoexpand', { autoExpand: false, snippet: this });
|
|
|
|
|
- // this.lastAceSelectionRowOffset(Math.min(selectionRange.start.row, selectionRange.end.row));
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // const $snip = $('#snippet_' + this.id());
|
|
|
|
|
- // $snip.find('.progress-snippet').animate(
|
|
|
|
|
- // {
|
|
|
|
|
- // height: '3px'
|
|
|
|
|
- // },
|
|
|
|
|
- // 100
|
|
|
|
|
- // );
|
|
|
|
|
- //
|
|
|
|
|
- // $('.jHueNotify').remove();
|
|
|
|
|
- // this.parentNotebook.forceHistoryInitialHeight(true);
|
|
|
|
|
- // this.errors([]);
|
|
|
|
|
- // huePubSub.publish('editor.clear.highlighted.errors', this.ace());
|
|
|
|
|
- // this.jobs([]);
|
|
|
|
|
- //
|
|
|
|
|
- // this.parentNotebook.historyCurrentPage(1);
|
|
|
|
|
- //
|
|
|
|
|
- // this.startLongOperationTimeout();
|
|
|
|
|
- //
|
|
|
|
|
- // try {
|
|
|
|
|
- // await this.executor.executeNext();
|
|
|
|
|
- // } catch (error) {}
|
|
|
|
|
- // this.stopLongOperationTimeout();
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
execute() {
|
|
execute() {
|
|
|
// From ctrl + enter
|
|
// From ctrl + enter
|
|
|
huePubSub.publish(EXECUTE_ACTIVE_EXECUTABLE_EVENT, this.activeExecutable());
|
|
huePubSub.publish(EXECUTE_ACTIVE_EXECUTABLE_EVENT, this.activeExecutable());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fetchExecutionAnalysis() {
|
|
fetchExecutionAnalysis() {
|
|
|
- if (this.type() === TYPE.impala) {
|
|
|
|
|
|
|
+ if (this.dialect() === DIALECT.impala) {
|
|
|
// TODO: Use real query ID
|
|
// TODO: Use real query ID
|
|
|
huePubSub.publish('editor.update.execution.analysis', {
|
|
huePubSub.publish('editor.update.execution.analysis', {
|
|
|
analysisPossible: true,
|
|
analysisPossible: true,
|
|
@@ -1210,7 +1208,7 @@ export default class Snippet {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
getPlaceHolder() {
|
|
getPlaceHolder() {
|
|
|
- return this.parentVm.getSnippetViewSettings(this.type()).placeHolder;
|
|
|
|
|
|
|
+ return this.parentVm.getSnippetViewSettings(this.dialect()).placeHolder;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async getSimilarQueries() {
|
|
async getSimilarQueries() {
|
|
@@ -1220,7 +1218,7 @@ export default class Snippet {
|
|
|
.statementSimilarity({
|
|
.statementSimilarity({
|
|
|
notebookJson: await this.parentNotebook.toContextJson(),
|
|
notebookJson: await this.parentNotebook.toContextJson(),
|
|
|
snippetJson: this.toContextJson(),
|
|
snippetJson: this.toContextJson(),
|
|
|
- sourcePlatform: this.type()
|
|
|
|
|
|
|
+ sourcePlatform: this.dialect()
|
|
|
})
|
|
})
|
|
|
.then(data => {
|
|
.then(data => {
|
|
|
if (data.status === 0) {
|
|
if (data.status === 0) {
|
|
@@ -1259,7 +1257,7 @@ export default class Snippet {
|
|
|
// Auth required
|
|
// Auth required
|
|
|
this.status(STATUS.expired);
|
|
this.status(STATUS.expired);
|
|
|
$(document).trigger('showAuthModal', {
|
|
$(document).trigger('showAuthModal', {
|
|
|
- type: this.type(),
|
|
|
|
|
|
|
+ type: this.dialect(),
|
|
|
callback: this.execute,
|
|
callback: this.execute,
|
|
|
message: data.message
|
|
message: data.message
|
|
|
});
|
|
});
|
|
@@ -1305,7 +1303,7 @@ export default class Snippet {
|
|
|
handleAssistSelection(databaseDef) {
|
|
handleAssistSelection(databaseDef) {
|
|
|
if (this.ignoreNextAssistDatabaseUpdate) {
|
|
if (this.ignoreNextAssistDatabaseUpdate) {
|
|
|
this.ignoreNextAssistDatabaseUpdate = false;
|
|
this.ignoreNextAssistDatabaseUpdate = false;
|
|
|
- } else if (databaseDef.sourceType === this.type()) {
|
|
|
|
|
|
|
+ } else if (databaseDef.sourceType === this.dialect()) {
|
|
|
if (this.namespace() !== databaseDef.namespace) {
|
|
if (this.namespace() !== databaseDef.namespace) {
|
|
|
this.namespace(databaseDef.namespace);
|
|
this.namespace(databaseDef.namespace);
|
|
|
}
|
|
}
|
|
@@ -1345,7 +1343,7 @@ export default class Snippet {
|
|
|
apiHelper.cancelActiveRequest(this.lastCompatibilityRequest);
|
|
apiHelper.cancelActiveRequest(this.lastCompatibilityRequest);
|
|
|
|
|
|
|
|
hueAnalytics.log('notebook', 'compatibility');
|
|
hueAnalytics.log('notebook', 'compatibility');
|
|
|
- this.compatibilityCheckRunning(targetPlatform !== this.type());
|
|
|
|
|
|
|
+ this.compatibilityCheckRunning(targetPlatform !== this.dialect());
|
|
|
this.hasSuggestion(null);
|
|
this.hasSuggestion(null);
|
|
|
const positionStatement = this.positionStatement();
|
|
const positionStatement = this.positionStatement();
|
|
|
|
|
|
|
@@ -1432,7 +1430,8 @@ export default class Snippet {
|
|
|
toContextJson() {
|
|
toContextJson() {
|
|
|
return JSON.stringify({
|
|
return JSON.stringify({
|
|
|
id: this.id(),
|
|
id: this.id(),
|
|
|
- type: this.type(),
|
|
|
|
|
|
|
+ type: this.dialect(),
|
|
|
|
|
+ connector: this.connector(),
|
|
|
status: this.status(),
|
|
status: this.status(),
|
|
|
statementType: this.statementType(),
|
|
statementType: this.statementType(),
|
|
|
statement: this.statement(),
|
|
statement: this.statement(),
|
|
@@ -1455,6 +1454,7 @@ export default class Snippet {
|
|
|
associatedDocumentUuid: this.associatedDocumentUuid(),
|
|
associatedDocumentUuid: this.associatedDocumentUuid(),
|
|
|
executor: this.executor.toJs(),
|
|
executor: this.executor.toJs(),
|
|
|
compute: this.compute(),
|
|
compute: this.compute(),
|
|
|
|
|
+ connector: this.connector(),
|
|
|
currentQueryTab: this.currentQueryTab(),
|
|
currentQueryTab: this.currentQueryTab(),
|
|
|
database: this.database(),
|
|
database: this.database(),
|
|
|
id: this.id(),
|
|
id: this.id(),
|
|
@@ -1471,7 +1471,7 @@ export default class Snippet {
|
|
|
statementPath: this.statementPath(),
|
|
statementPath: this.statementPath(),
|
|
|
statementType: this.statementType(),
|
|
statementType: this.statementType(),
|
|
|
status: this.status(),
|
|
status: this.status(),
|
|
|
- type: this.type(),
|
|
|
|
|
|
|
+ type: this.dialect(), // TODO: Drop once connectors are stable
|
|
|
variables: this.variables().map(variable => ({
|
|
variables: this.variables().map(variable => ({
|
|
|
meta: variable.meta && {
|
|
meta: variable.meta && {
|
|
|
options: variable.meta.options && variable.meta.options(), // TODO: Map?
|
|
options: variable.meta.options && variable.meta.options(), // TODO: Map?
|
|
@@ -1493,7 +1493,7 @@ export default class Snippet {
|
|
|
uploadQuery(query_id) {
|
|
uploadQuery(query_id) {
|
|
|
$.post('/metadata/api/optimizer/upload/query', {
|
|
$.post('/metadata/api/optimizer/upload/query', {
|
|
|
query_id: query_id,
|
|
query_id: query_id,
|
|
|
- sourcePlatform: this.type()
|
|
|
|
|
|
|
+ sourcePlatform: this.dialect()
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1502,15 +1502,15 @@ export default class Snippet {
|
|
|
|
|
|
|
|
$.post('/metadata/api/optimizer/upload/history', {
|
|
$.post('/metadata/api/optimizer/upload/history', {
|
|
|
n: typeof n != 'undefined' ? n : null,
|
|
n: typeof n != 'undefined' ? n : null,
|
|
|
- sourcePlatform: this.type()
|
|
|
|
|
|
|
+ sourcePlatform: this.dialect()
|
|
|
}).then(data => {
|
|
}).then(data => {
|
|
|
if (data.status === 0) {
|
|
if (data.status === 0) {
|
|
|
$(document).trigger(
|
|
$(document).trigger(
|
|
|
'info',
|
|
'info',
|
|
|
- data.upload_history[this.type()].count +
|
|
|
|
|
|
|
+ data.upload_history[this.dialect()].count +
|
|
|
' queries uploaded successfully. Processing them...'
|
|
' queries uploaded successfully. Processing them...'
|
|
|
);
|
|
);
|
|
|
- this.watchUploadStatus(data.upload_history[this.type()].status.workloadId);
|
|
|
|
|
|
|
+ this.watchUploadStatus(data.upload_history[this.dialect()].status.workloadId);
|
|
|
} else {
|
|
} else {
|
|
|
$(document).trigger('error', data.message);
|
|
$(document).trigger('error', data.message);
|
|
|
}
|
|
}
|
|
@@ -1529,7 +1529,7 @@ export default class Snippet {
|
|
|
db_tables: JSON.stringify(
|
|
db_tables: JSON.stringify(
|
|
|
options.activeTables.map(table => table.databaseName + '.' + table.tableName)
|
|
options.activeTables.map(table => table.databaseName + '.' + table.tableName)
|
|
|
),
|
|
),
|
|
|
- sourcePlatform: JSON.stringify(this.type()),
|
|
|
|
|
|
|
+ sourcePlatform: JSON.stringify(this.dialect()),
|
|
|
with_ddl: JSON.stringify(true),
|
|
with_ddl: JSON.stringify(true),
|
|
|
with_table_stats: JSON.stringify(true),
|
|
with_table_stats: JSON.stringify(true),
|
|
|
with_columns_stats: JSON.stringify(true)
|
|
with_columns_stats: JSON.stringify(true)
|