|
|
@@ -29,7 +29,7 @@ import { matchesType } from 'sql/reference/typeUtils';
|
|
|
import { DIALECT } from 'apps/notebook2/snippet';
|
|
|
import { cancelActiveRequest } from 'api/apiUtils';
|
|
|
import { findBrowserConnector, getRootFilePath } from 'utils/hueConfig';
|
|
|
-import { getArgumentTypes } from './reference/sqlReferenceRepository';
|
|
|
+import { getArgumentTypes, getFunctionsWithReturnTypes } from './reference/sqlReferenceRepository';
|
|
|
|
|
|
const normalizedColors = HueColors.getNormalizedColors();
|
|
|
|
|
|
@@ -476,7 +476,7 @@ class AutocompleteResults {
|
|
|
self.handleColumnAliases();
|
|
|
self.handleCommonTableExpressions();
|
|
|
self.handleOptions();
|
|
|
- self.handleFunctions(colRefDeferred);
|
|
|
+ self.activeDeferrals.push(self.handleFunctions(colRefDeferred));
|
|
|
self.handleDatabases(databasesDeferred);
|
|
|
const tablesDeferred = self.handleTables(databasesDeferred);
|
|
|
self.activeDeferrals.push(tablesDeferred);
|
|
|
@@ -721,6 +721,7 @@ class AutocompleteResults {
|
|
|
|
|
|
handleFunctions(colRefDeferred) {
|
|
|
const self = this;
|
|
|
+ const functionsDeferred = $.Deferred();
|
|
|
if (self.parseResult.suggestFunctions) {
|
|
|
const functionSuggestions = [];
|
|
|
if (
|
|
|
@@ -729,61 +730,71 @@ class AutocompleteResults {
|
|
|
) {
|
|
|
initLoading(self.loadingFunctions, colRefDeferred);
|
|
|
|
|
|
- colRefDeferred.done(colRef => {
|
|
|
- const functionsToSuggest = SqlFunctions.getFunctionsWithReturnTypes(
|
|
|
- self.dialect(),
|
|
|
- [colRef.type.toUpperCase()],
|
|
|
- self.parseResult.suggestAggregateFunctions || false,
|
|
|
- self.parseResult.suggestAnalyticFunctions || false
|
|
|
- );
|
|
|
+ colRefDeferred
|
|
|
+ .done(async colRef => {
|
|
|
+ const functionsToSuggest = await getFunctionsWithReturnTypes(
|
|
|
+ self.snippet.connector(),
|
|
|
+ [colRef.type.toUpperCase()],
|
|
|
+ self.parseResult.suggestAggregateFunctions || false,
|
|
|
+ self.parseResult.suggestAnalyticFunctions || false
|
|
|
+ );
|
|
|
|
|
|
- Object.keys(functionsToSuggest).forEach(name => {
|
|
|
- functionSuggestions.push({
|
|
|
- category: CATEGORIES.UDF,
|
|
|
- value: name + '()',
|
|
|
- meta: functionsToSuggest[name].returnTypes.join('|'),
|
|
|
- weightAdjust:
|
|
|
- colRef.type.toUpperCase() !== 'T' &&
|
|
|
- functionsToSuggest[name].returnTypes.some(otherType => {
|
|
|
- return otherType === colRef.type.toUpperCase();
|
|
|
- })
|
|
|
- ? 1
|
|
|
- : 0,
|
|
|
- popular: ko.observable(false),
|
|
|
- details: functionsToSuggest[name]
|
|
|
+ Object.keys(functionsToSuggest).forEach(name => {
|
|
|
+ functionSuggestions.push({
|
|
|
+ category: CATEGORIES.UDF,
|
|
|
+ value: name + '()',
|
|
|
+ meta: functionsToSuggest[name].returnTypes.join('|'),
|
|
|
+ weightAdjust:
|
|
|
+ colRef.type.toUpperCase() !== 'T' &&
|
|
|
+ functionsToSuggest[name].returnTypes.some(otherType => {
|
|
|
+ return otherType === colRef.type.toUpperCase();
|
|
|
+ })
|
|
|
+ ? 1
|
|
|
+ : 0,
|
|
|
+ popular: ko.observable(false),
|
|
|
+ details: functionsToSuggest[name]
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
|
|
|
- self.appendEntries(functionSuggestions);
|
|
|
- });
|
|
|
+ self.appendEntries(functionSuggestions);
|
|
|
+ functionsDeferred.resolve();
|
|
|
+ })
|
|
|
+ .fail(functionsDeferred.reject);
|
|
|
} else {
|
|
|
const types = self.parseResult.suggestFunctions.types || ['T'];
|
|
|
- const functionsToSuggest = SqlFunctions.getFunctionsWithReturnTypes(
|
|
|
- self.dialect(),
|
|
|
+
|
|
|
+ getFunctionsWithReturnTypes(
|
|
|
+ self.snippet.connector(),
|
|
|
types,
|
|
|
self.parseResult.suggestAggregateFunctions || false,
|
|
|
self.parseResult.suggestAnalyticFunctions || false
|
|
|
- );
|
|
|
-
|
|
|
- Object.keys(functionsToSuggest).forEach(name => {
|
|
|
- functionSuggestions.push({
|
|
|
- category: CATEGORIES.UDF,
|
|
|
- value: name + '()',
|
|
|
- meta: functionsToSuggest[name].returnTypes.join('|'),
|
|
|
- weightAdjust:
|
|
|
- types[0].toUpperCase() !== 'T' &&
|
|
|
- functionsToSuggest[name].returnTypes.some(otherType => {
|
|
|
- return otherType === types[0].toUpperCase();
|
|
|
- })
|
|
|
- ? 1
|
|
|
- : 0,
|
|
|
- popular: ko.observable(false),
|
|
|
- details: functionsToSuggest[name]
|
|
|
- });
|
|
|
- });
|
|
|
- self.appendEntries(functionSuggestions);
|
|
|
+ )
|
|
|
+ .then(functionsToSuggest => {
|
|
|
+ Object.keys(functionsToSuggest).forEach(name => {
|
|
|
+ functionSuggestions.push({
|
|
|
+ category: CATEGORIES.UDF,
|
|
|
+ value: name + '()',
|
|
|
+ meta: functionsToSuggest[name].returnTypes.join('|'),
|
|
|
+ weightAdjust:
|
|
|
+ types[0].toUpperCase() !== 'T' &&
|
|
|
+ functionsToSuggest[name].returnTypes.some(otherType => {
|
|
|
+ return otherType === types[0].toUpperCase();
|
|
|
+ })
|
|
|
+ ? 1
|
|
|
+ : 0,
|
|
|
+ popular: ko.observable(false),
|
|
|
+ details: functionsToSuggest[name]
|
|
|
+ });
|
|
|
+ });
|
|
|
+ self.appendEntries(functionSuggestions);
|
|
|
+ functionsDeferred.resolve();
|
|
|
+ })
|
|
|
+ .catch(functionsDeferred.reject);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ functionsDeferred.resolve();
|
|
|
}
|
|
|
+ return functionsDeferred;
|
|
|
}
|
|
|
|
|
|
handleDatabases(databasesDeferred) {
|