|
@@ -45,7 +45,6 @@ import dataCatalog from 'catalog/dataCatalog';
|
|
|
import { SetDetails, UdfDetails } from 'sql/reference/types';
|
|
import { SetDetails, UdfDetails } from 'sql/reference/types';
|
|
|
import { hueWindow } from 'types/types';
|
|
import { hueWindow } from 'types/types';
|
|
|
import hueUtils from 'utils/hueUtils';
|
|
import hueUtils from 'utils/hueUtils';
|
|
|
-import huePubSub from 'utils/huePubSub';
|
|
|
|
|
import I18n from 'utils/i18n';
|
|
import I18n from 'utils/i18n';
|
|
|
import sqlUtils from 'sql/sqlUtils';
|
|
import sqlUtils from 'sql/sqlUtils';
|
|
|
import { matchesType } from 'sql/reference/typeUtils';
|
|
import { matchesType } from 'sql/reference/typeUtils';
|
|
@@ -144,28 +143,11 @@ class AutocompleteResults {
|
|
|
activeDatabase: string;
|
|
activeDatabase: string;
|
|
|
|
|
|
|
|
parseResult!: AutocompleteParseResult;
|
|
parseResult!: AutocompleteParseResult;
|
|
|
- entries: Suggestion[] = [];
|
|
|
|
|
subTracker = new SubscriptionTracker();
|
|
subTracker = new SubscriptionTracker();
|
|
|
onCancelFunctions: (() => void)[] = [];
|
|
onCancelFunctions: (() => void)[] = [];
|
|
|
lastKnownRequests: JQueryXHR[] = [];
|
|
lastKnownRequests: JQueryXHR[] = [];
|
|
|
cancellablePromises: CancellableJqPromise<unknown>[] = [];
|
|
cancellablePromises: CancellableJqPromise<unknown>[] = [];
|
|
|
|
|
|
|
|
- loadingKeywords = false;
|
|
|
|
|
- loadingFunctions = false;
|
|
|
|
|
- loadingDatabases = false;
|
|
|
|
|
- loadingTables = false;
|
|
|
|
|
- loadingColumns = false;
|
|
|
|
|
- loadingValues = false;
|
|
|
|
|
- loadingPaths = false;
|
|
|
|
|
- loadingJoins = false;
|
|
|
|
|
- loadingJoinConditions = false;
|
|
|
|
|
- loadingAggregateFunctions = false;
|
|
|
|
|
- loadingGroupBys = false;
|
|
|
|
|
- loadingOrderBys = false;
|
|
|
|
|
- loadingFilters = false;
|
|
|
|
|
- loadingPopularTables = false;
|
|
|
|
|
- loadingPopularColumns = false;
|
|
|
|
|
-
|
|
|
|
|
constructor(options: { executor: Executor; editor: Ace.Editor; temporaryOnly: boolean }) {
|
|
constructor(options: { executor: Executor; editor: Ace.Editor; temporaryOnly: boolean }) {
|
|
|
this.executor = options.executor;
|
|
this.executor = options.executor;
|
|
|
this.editor = options.editor;
|
|
this.editor = options.editor;
|
|
@@ -177,7 +159,7 @@ class AutocompleteResults {
|
|
|
return this.executor.connector().dialect || this.executor.connector().type;
|
|
return this.executor.connector().dialect || this.executor.connector().type;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async update(parseResult: AutocompleteParseResult): Promise<void> {
|
|
|
|
|
|
|
+ async update(parseResult: AutocompleteParseResult, suggestions: Suggestion[]): Promise<void[]> {
|
|
|
let cancelFn;
|
|
let cancelFn;
|
|
|
while ((cancelFn = this.onCancelFunctions.pop())) {
|
|
while ((cancelFn = this.onCancelFunctions.pop())) {
|
|
|
cancelFn();
|
|
cancelFn();
|
|
@@ -185,24 +167,6 @@ class AutocompleteResults {
|
|
|
this.activeDatabase = parseResult.useDatabase || this.executor.database();
|
|
this.activeDatabase = parseResult.useDatabase || this.executor.database();
|
|
|
this.parseResult = parseResult;
|
|
this.parseResult = parseResult;
|
|
|
|
|
|
|
|
- this.entries = [];
|
|
|
|
|
-
|
|
|
|
|
- this.loadingKeywords = false;
|
|
|
|
|
- this.loadingFunctions = false;
|
|
|
|
|
- this.loadingDatabases = false;
|
|
|
|
|
- this.loadingTables = false;
|
|
|
|
|
- this.loadingColumns = false;
|
|
|
|
|
- this.loadingValues = false;
|
|
|
|
|
- this.loadingPaths = false;
|
|
|
|
|
- this.loadingJoins = false;
|
|
|
|
|
- this.loadingJoinConditions = false;
|
|
|
|
|
- this.loadingAggregateFunctions = false;
|
|
|
|
|
- this.loadingGroupBys = false;
|
|
|
|
|
- this.loadingOrderBys = false;
|
|
|
|
|
- this.loadingFilters = false;
|
|
|
|
|
- this.loadingPopularTables = false;
|
|
|
|
|
- this.loadingPopularColumns = false;
|
|
|
|
|
-
|
|
|
|
|
if (this.parseResult.udfArgument) {
|
|
if (this.parseResult.udfArgument) {
|
|
|
await this.adjustForUdfArgument();
|
|
await this.adjustForUdfArgument();
|
|
|
}
|
|
}
|
|
@@ -213,9 +177,9 @@ class AutocompleteResults {
|
|
|
const wrapped = new Promise<void>(resolve => {
|
|
const wrapped = new Promise<void>(resolve => {
|
|
|
this.onCancelFunctions.push(resolve);
|
|
this.onCancelFunctions.push(resolve);
|
|
|
promise
|
|
promise
|
|
|
- .then(suggestions => {
|
|
|
|
|
- if (suggestions && suggestions.length) {
|
|
|
|
|
- this.entries = [...this.entries, ...suggestions];
|
|
|
|
|
|
|
+ .then(newSuggestions => {
|
|
|
|
|
+ if (newSuggestions && newSuggestions.length) {
|
|
|
|
|
+ suggestions.push(...newSuggestions);
|
|
|
}
|
|
}
|
|
|
resolve();
|
|
resolve();
|
|
|
})
|
|
})
|
|
@@ -252,8 +216,7 @@ class AutocompleteResults {
|
|
|
trackPromise(this.handlePopularColumns(columnsPromise));
|
|
trackPromise(this.handlePopularColumns(columnsPromise));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- await Promise.all(promises);
|
|
|
|
|
- huePubSub.publish('hue.ace.autocompleter.done');
|
|
|
|
|
|
|
+ return Promise.all(promises);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async adjustForUdfArgument(): Promise<void> {
|
|
async adjustForUdfArgument(): Promise<void> {
|
|
@@ -389,7 +352,6 @@ class AutocompleteResults {
|
|
|
if (!suggestColRefKeywords) {
|
|
if (!suggestColRefKeywords) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- this.loadingKeywords = true;
|
|
|
|
|
// Wait for the column reference type to be resolved to pick the right keywords
|
|
// Wait for the column reference type to be resolved to pick the right keywords
|
|
|
const colRef = await colRefPromise;
|
|
const colRef = await colRefPromise;
|
|
|
const colRefKeywordSuggestions: Suggestion[] = [];
|
|
const colRefKeywordSuggestions: Suggestion[] = [];
|
|
@@ -408,7 +370,6 @@ class AutocompleteResults {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- this.loadingKeywords = false;
|
|
|
|
|
return colRefKeywordSuggestions;
|
|
return colRefKeywordSuggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -516,7 +477,6 @@ class AutocompleteResults {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.loadingFunctions = true;
|
|
|
|
|
let suggestions: Suggestion[] = [];
|
|
let suggestions: Suggestion[] = [];
|
|
|
if (
|
|
if (
|
|
|
suggestFunctions.types &&
|
|
suggestFunctions.types &&
|
|
@@ -587,7 +547,6 @@ class AutocompleteResults {
|
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.loadingFunctions = false;
|
|
|
|
|
return suggestions;
|
|
return suggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -596,7 +555,6 @@ class AutocompleteResults {
|
|
|
if (!suggestDatabases) {
|
|
if (!suggestDatabases) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- this.loadingDatabases = true;
|
|
|
|
|
const databaseSuggestions: Suggestion[] = [];
|
|
const databaseSuggestions: Suggestion[] = [];
|
|
|
try {
|
|
try {
|
|
|
let prefix = suggestDatabases.prependQuestionMark ? '? ' : '';
|
|
let prefix = suggestDatabases.prependQuestionMark ? '? ' : '';
|
|
@@ -625,7 +583,6 @@ class AutocompleteResults {
|
|
|
}
|
|
}
|
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
|
|
|
|
|
|
- this.loadingDatabases = false;
|
|
|
|
|
return databaseSuggestions;
|
|
return databaseSuggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -634,7 +591,6 @@ class AutocompleteResults {
|
|
|
if (!suggestTables) {
|
|
if (!suggestTables) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- this.loadingTables = true;
|
|
|
|
|
|
|
|
|
|
const getTableSuggestions = async (): Promise<Suggestion[]> => {
|
|
const getTableSuggestions = async (): Promise<Suggestion[]> => {
|
|
|
let prefix = suggestTables.prependQuestionMark ? '? ' : '';
|
|
let prefix = suggestTables.prependQuestionMark ? '? ' : '';
|
|
@@ -726,7 +682,6 @@ class AutocompleteResults {
|
|
|
tableSuggestions = await getTableSuggestions();
|
|
tableSuggestions = await getTableSuggestions();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.loadingTables = false;
|
|
|
|
|
return tableSuggestions;
|
|
return tableSuggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -742,7 +697,6 @@ class AutocompleteResults {
|
|
|
if (!suggestColumns) {
|
|
if (!suggestColumns) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- this.loadingColumns = true;
|
|
|
|
|
|
|
|
|
|
const columnSuggestions: Suggestion[] = [];
|
|
const columnSuggestions: Suggestion[] = [];
|
|
|
// For multiple tables we need to merge and make sure identifiers are unique
|
|
// For multiple tables we need to merge and make sure identifiers are unique
|
|
@@ -789,7 +743,6 @@ class AutocompleteResults {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.loadingColumns = false;
|
|
|
|
|
return columnSuggestions;
|
|
return columnSuggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1078,7 +1031,6 @@ class AutocompleteResults {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.loadingValues = true;
|
|
|
|
|
const colRef = await colRefPromise;
|
|
const colRef = await colRefPromise;
|
|
|
|
|
|
|
|
if (colRef.samples) {
|
|
if (colRef.samples) {
|
|
@@ -1098,7 +1050,6 @@ class AutocompleteResults {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.loadingValues = false;
|
|
|
|
|
return valueSuggestions;
|
|
return valueSuggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1107,7 +1058,6 @@ class AutocompleteResults {
|
|
|
if (!suggestHdfs) {
|
|
if (!suggestHdfs) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- this.loadingPaths = true;
|
|
|
|
|
|
|
|
|
|
let suggestions: Suggestion[] = [];
|
|
let suggestions: Suggestion[] = [];
|
|
|
|
|
|
|
@@ -1174,7 +1124,6 @@ class AutocompleteResults {
|
|
|
weightAdjust: 0,
|
|
weightAdjust: 0,
|
|
|
popular: false
|
|
popular: false
|
|
|
});
|
|
});
|
|
|
- this.loadingPaths = false;
|
|
|
|
|
return suggestions;
|
|
return suggestions;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1218,7 +1167,6 @@ class AutocompleteResults {
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- this.loadingPaths = false;
|
|
|
|
|
return suggestions;
|
|
return suggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1245,7 +1193,6 @@ class AutocompleteResults {
|
|
|
if (!(<hueWindow>window).HAS_OPTIMIZER || !suggestJoins) {
|
|
if (!(<hueWindow>window).HAS_OPTIMIZER || !suggestJoins) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- this.loadingJoins = true;
|
|
|
|
|
|
|
|
|
|
const paths = this.tableIdentifierChainsToPaths(suggestJoins.tables);
|
|
const paths = this.tableIdentifierChainsToPaths(suggestJoins.tables);
|
|
|
if (!paths.length) {
|
|
if (!paths.length) {
|
|
@@ -1358,7 +1305,6 @@ class AutocompleteResults {
|
|
|
}
|
|
}
|
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
|
|
|
|
|
|
- this.loadingJoins = false;
|
|
|
|
|
return joinSuggestions;
|
|
return joinSuggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1367,7 +1313,6 @@ class AutocompleteResults {
|
|
|
if (!(<hueWindow>window).HAS_OPTIMIZER || !suggestJoinConditions) {
|
|
if (!(<hueWindow>window).HAS_OPTIMIZER || !suggestJoinConditions) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- this.loadingJoinConditions = true;
|
|
|
|
|
|
|
|
|
|
const paths = this.tableIdentifierChainsToPaths(suggestJoinConditions.tables);
|
|
const paths = this.tableIdentifierChainsToPaths(suggestJoinConditions.tables);
|
|
|
if (!paths.length) {
|
|
if (!paths.length) {
|
|
@@ -1447,7 +1392,6 @@ class AutocompleteResults {
|
|
|
}
|
|
}
|
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
|
|
|
|
|
|
- this.loadingJoinConditions = true;
|
|
|
|
|
return joinConditionSuggestions;
|
|
return joinConditionSuggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1461,8 +1405,6 @@ class AutocompleteResults {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.loadingAggregateFunctions = true;
|
|
|
|
|
-
|
|
|
|
|
const paths = this.tableIdentifierChainsToPaths(suggestAggregateFunctions.tables);
|
|
const paths = this.tableIdentifierChainsToPaths(suggestAggregateFunctions.tables);
|
|
|
if (!paths.length) {
|
|
if (!paths.length) {
|
|
|
return [];
|
|
return [];
|
|
@@ -1575,7 +1517,6 @@ class AutocompleteResults {
|
|
|
});
|
|
});
|
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
|
|
|
|
|
|
- this.loadingAggregateFunctions = false;
|
|
|
|
|
return aggregateFunctionsSuggestions;
|
|
return aggregateFunctionsSuggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1682,14 +1623,12 @@ class AutocompleteResults {
|
|
|
if (!(<hueWindow>window).HAS_OPTIMIZER || !suggestGroupBys) {
|
|
if (!(<hueWindow>window).HAS_OPTIMIZER || !suggestGroupBys) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- this.loadingGroupBys = true;
|
|
|
|
|
- const suggestions = await this.handlePopularGroupByOrOrderBy(
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return await this.handlePopularGroupByOrOrderBy(
|
|
|
'groupByColumn',
|
|
'groupByColumn',
|
|
|
suggestGroupBys,
|
|
suggestGroupBys,
|
|
|
columnsPromise
|
|
columnsPromise
|
|
|
);
|
|
);
|
|
|
- this.loadingGroupBys = false;
|
|
|
|
|
- return suggestions;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async handleOrderBys(columnsPromise: Promise<Suggestion[]>): Promise<Suggestion[]> {
|
|
async handleOrderBys(columnsPromise: Promise<Suggestion[]>): Promise<Suggestion[]> {
|
|
@@ -1697,14 +1636,11 @@ class AutocompleteResults {
|
|
|
if (!(<hueWindow>window).HAS_OPTIMIZER || !suggestOrderBys) {
|
|
if (!(<hueWindow>window).HAS_OPTIMIZER || !suggestOrderBys) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- this.loadingOrderBys = true;
|
|
|
|
|
- const suggestions = await this.handlePopularGroupByOrOrderBy(
|
|
|
|
|
|
|
+ return await this.handlePopularGroupByOrOrderBy(
|
|
|
'orderByColumn',
|
|
'orderByColumn',
|
|
|
suggestOrderBys,
|
|
suggestOrderBys,
|
|
|
columnsPromise
|
|
columnsPromise
|
|
|
);
|
|
);
|
|
|
- this.loadingOrderBys = false;
|
|
|
|
|
- return suggestions;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async handleFilters(): Promise<Suggestion[]> {
|
|
async handleFilters(): Promise<Suggestion[]> {
|
|
@@ -1712,7 +1648,6 @@ class AutocompleteResults {
|
|
|
if (!(<hueWindow>window).HAS_OPTIMIZER || !suggestFilters) {
|
|
if (!(<hueWindow>window).HAS_OPTIMIZER || !suggestFilters) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- this.loadingFilters = true;
|
|
|
|
|
|
|
|
|
|
const paths = this.tableIdentifierChainsToPaths(suggestFilters.tables);
|
|
const paths = this.tableIdentifierChainsToPaths(suggestFilters.tables);
|
|
|
if (!paths.length) {
|
|
if (!paths.length) {
|
|
@@ -1792,7 +1727,6 @@ class AutocompleteResults {
|
|
|
});
|
|
});
|
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
|
|
|
|
|
|
- this.loadingFilters = false;
|
|
|
|
|
return filterSuggestions;
|
|
return filterSuggestions;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1802,8 +1736,6 @@ class AutocompleteResults {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.loadingPopularTables = true;
|
|
|
|
|
-
|
|
|
|
|
const db =
|
|
const db =
|
|
|
suggestTables.identifierChain &&
|
|
suggestTables.identifierChain &&
|
|
|
suggestTables.identifierChain.length === 1 &&
|
|
suggestTables.identifierChain.length === 1 &&
|
|
@@ -1863,7 +1795,6 @@ class AutocompleteResults {
|
|
|
}
|
|
}
|
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
|
|
|
|
|
|
- this.loadingPopularTables = false;
|
|
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1883,8 +1814,6 @@ class AutocompleteResults {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.loadingPopularColumns = true;
|
|
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
const paths: string[][] = [];
|
|
const paths: string[][] = [];
|
|
|
suggestColumns.tables.forEach(table => {
|
|
suggestColumns.tables.forEach(table => {
|
|
@@ -1966,7 +1895,6 @@ class AutocompleteResults {
|
|
|
}
|
|
}
|
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
|
|
|
|
|
|
- this.loadingPopularColumns = false;
|
|
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
|
|
|