Эх сурвалжийг харах

HUE-5227 [editor] Put exact type match suggestions on top in the autocompleter

Johan Ahlen 9 жил өмнө
parent
commit
008f74c

+ 12 - 9
desktop/core/src/desktop/static/desktop/js/sqlAutocompleter2.js

@@ -32,13 +32,14 @@ var SqlAutocompleter2 = (function () {
 
   // Keyword weights come from the parser
   var DEFAULT_WEIGHTS = {
-    COLUMN: 700,
-    VIRTUAL_COLUMN: 600,
-    SAMPLE: 500,
-    IDENTIFIER: 400,
-    CTE: 300,
-    TABLE: 200,
-    DATABASE: 100,
+    COLUMN: 800,
+    VIRTUAL_COLUMN: 700,
+    SAMPLE: 600,
+    IDENTIFIER: 500,
+    CTE: 400,
+    TABLE: 300,
+    DATABASE: 200,
+    UDF: 100,
     HDFS: 1,
     COLREF_KEYWORD: -1
   };
@@ -118,9 +119,9 @@ var SqlAutocompleter2 = (function () {
       if (parseResult.suggestFunctions.types && parseResult.suggestFunctions.types[0] === 'COLREF') {
         colRefDeferral.done(function () {
           if (colRef !== null && colRef.type) {
-            SqlFunctions.suggestFunctions(self.snippet.type(), [colRef.type.toUpperCase()], parseResult.suggestAggregateFunctions || false, parseResult.suggestAnalyticFunctions || false, completions);
+            SqlFunctions.suggestFunctions(self.snippet.type(), [colRef.type.toUpperCase()], parseResult.suggestAggregateFunctions || false, parseResult.suggestAnalyticFunctions || false, completions, DEFAULT_WEIGHTS.UDF);
           } else {
-            SqlFunctions.suggestFunctions(self.snippet.type(), ['T'], parseResult.suggestAggregateFunctions || false, parseResult.suggestAnalyticFunctions || false, completions);
+            SqlFunctions.suggestFunctions(self.snippet.type(), ['T'], parseResult.suggestAggregateFunctions || false, parseResult.suggestAnalyticFunctions || false, completions, DEFAULT_WEIGHTS.UDF);
           }
           suggestFunctionsDeferral.resolve();
         });
@@ -482,6 +483,8 @@ var SqlAutocompleter2 = (function () {
               columnSuggestions.push({value: self.backTickIfNeeded(column.name) + '[]', meta: 'array', weight: DEFAULT_WEIGHTS.COLUMN, table: table })
             } else if (column.type.indexOf('array') === 0) {
               columnSuggestions.push({value: self.backTickIfNeeded(column.name), meta: 'array', weight: DEFAULT_WEIGHTS.COLUMN, table: table })
+            } else if (types[0].toUpperCase() !== 'T' && types.filter(function (type) { return type.toUpperCase() === column.type.toUpperCase() }).length > 0) {
+              columnSuggestions.push({value: self.backTickIfNeeded(column.name), meta: column.type, weight: DEFAULT_WEIGHTS.COLUMN + 1, table: table })
             } else if (SqlFunctions.matchesType(self.snippet.type(), types, [column.type.toUpperCase()]) ||
                 SqlFunctions.matchesType(self.snippet.type(), [column.type.toUpperCase()], types)) {
               columnSuggestions.push({value: self.backTickIfNeeded(column.name), meta: column.type, weight: DEFAULT_WEIGHTS.COLUMN, table: table })

+ 8 - 3
desktop/core/src/desktop/static/desktop/js/sqlFunctions.js

@@ -1073,7 +1073,7 @@ var SqlFunctions = (function () {
         returnTypes: ['TIMESTAMP'],
         arguments: [[{type: 'TIMESTAMP'}], [{type: 'INT'}]],
         signature: 'date_sub(TIMESTAMP startdate, INT days), date_sub(TIMESTAMP startdate, interval_expression)',
-        description: 'ubtracts a specified number of days from a TIMESTAMP value. The first argument can be a string, which is automatically cast to TIMESTAMP if it uses the recognized format. With an INTERVAL expression as the second argument, you can calculate a delta value using other units such as weeks, years, hours, seconds, and so on.'
+        description: 'Subtracts a specified number of days from a TIMESTAMP value. The first argument can be a string, which is automatically cast to TIMESTAMP if it uses the recognized format. With an INTERVAL expression as the second argument, you can calculate a delta value using other units such as weeks, years, hours, seconds, and so on.'
       },
       datediff: {
         returnTypes: ['INT'],
@@ -2347,7 +2347,7 @@ var SqlFunctions = (function () {
     }
   };
 
-  var suggestFunctions = function (dialect, returnTypes, includeAggregate, includeAnalytic, completions) {
+  var suggestFunctions = function (dialect, returnTypes, includeAggregate, includeAnalytic, completions, weight) {
     var functionsToSuggest = {};
     addFunctions(COLLECTION_FUNCTIONS, dialect, returnTypes, functionsToSuggest);
     addFunctions(CONDITIONAL_FUNCTIONS, dialect, returnTypes, functionsToSuggest);
@@ -2368,7 +2368,12 @@ var SqlFunctions = (function () {
       completions.push({
         value: name === 'current_date' || name === 'current_timestamp' ? name : name + '()',
         meta: functionsToSuggest[name].returnTypes.join('|'),
-        weight: -2,
+        weight: returnTypes.filter(function (type) {
+          return functionsToSuggest[name].returnTypes.filter(
+              function (otherType) {
+                return otherType === type;
+              }).length > 0
+        }).length > 0 ? weight + 1 : weight,
         docHTML: createDocHtml(functionsToSuggest[name])
       })
     });