فهرست منبع

HUE-8001 [autocomplete] Improve ranking and select list suggestions

- Added CASE etc. to select list suggestions
- Improved UDF suggestion to not include type in the weight when the expected type can be any type
Johan Ahlen 7 سال پیش
والد
کامیت
670a55f

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_insert.jison

@@ -344,7 +344,7 @@ SelectWithoutTableExpression_EDIT
    }
  | 'SELECT' OptionalAllOrDistinct OptionalStraightJoin 'CURSOR'
    {
-     var keywords = [{ value: '*', weight: 10000 }];
+     var keywords = parser.getSelectListKeywords();
      if (!$2 || $2 === 'ALL') {
        parser.suggestAggregateFunctions();
        parser.suggestAnalyticFunctions();

+ 49 - 34
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_main.jison

@@ -1399,7 +1399,7 @@ SelectStatement_EDIT
    {
      parser.addClauseLocation('selectList', parser.firstDefined($3, @3, $2, @2, $1, @1), @4);
      if ($4.cursorAtStart) {
-       var keywords = [{ value: '*', weight: 10000 }];
+       var keywords = parser.getSelectListKeywords();
        if (!$3 && !$2) {
          keywords.push({ value: 'ALL', weight: 2 });
          keywords.push({ value: 'DISTINCT', weight: 2 });
@@ -1431,7 +1431,7 @@ SelectStatement_EDIT
  | 'SELECT' OptionalAllOrDistinct OptionalStraightJoin 'CURSOR'
    {
      parser.addClauseLocation('selectList', parser.firstDefined($3, @3, $2, @2, $1, @1), @4, true);
-     var keywords = [{ value: '*', weight: 10000 }];
+     var keywords = parser.getSelectListKeywords();
      if (!$2 || $2 === 'ALL') {
        parser.suggestAggregateFunctions();
        parser.suggestAnalyticFunctions();
@@ -1464,7 +1464,7 @@ SelectStatement_EDIT
  | 'SELECT' OptionalAllOrDistinct OptionalStraightJoin 'CURSOR' TableExpression
    {
      parser.addClauseLocation('selectList', parser.firstDefined($3, @3, $2, @2, $1, @1), @4, true);
-     var keywords = [{ value: '*', weight: 10000 }];
+     var keywords = parser.getSelectListKeywords();
      if (!$2 || $2 === 'ALL') {
        parser.suggestAggregateFunctions();
        parser.suggestAnalyticFunctions();
@@ -2676,21 +2676,21 @@ SelectList_EDIT
    }
  | SelectList ',' AnyCursor
    {
-     $$ = { suggestKeywords: [{ value: '*', weight: 10000 }], suggestTables: true, suggestDatabases: true, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
+     $$ = { suggestKeywords: parser.getSelectListKeywords(), suggestTables: true, suggestDatabases: true, suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true };
    }
  | SelectList ',' SelectSpecification_EDIT                 -> $3
  | SelectList ',' AnyCursor SelectList
    {
-     $$ = { suggestKeywords: [{ value: '*', weight: 10000 }], suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true,  };
+     $$ = { suggestKeywords: parser.getSelectListKeywords(), suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true,  };
    }
  | SelectList ',' AnyCursor ','
    {
-     $$ = { suggestKeywords: [{ value: '*', weight: 10000 }], suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true,  };
+     $$ = { suggestKeywords: parser.getSelectListKeywords(), suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true,  };
    }
  | SelectList ',' SelectSpecification_EDIT ','             -> $3
  | SelectList ',' AnyCursor ',' SelectList
    {
-     $$ = { suggestKeywords: [{ value: '*', weight: 10000 }], suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true,  };
+     $$ = { suggestKeywords: parser.getSelectListKeywords(), suggestFunctions: true, suggestColumns: true, suggestAggregateFunctions: true,  };
    }
  | SelectList ',' SelectSpecification_EDIT ',' SelectList  -> $3
  ;
@@ -3684,13 +3684,17 @@ CountFunction_EDIT
  : 'COUNT' '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
    {
      parser.valueExpressionSuggest();
+     var keywords = parser.getSelectListKeywords();
      if (!$3) {
-       var keywords = parser.isImpala() ? [{ value: '*', weight: 10000 }, 'ALL', 'DISTINCT'] : [{ value: '*', weight: 10000 }, 'DISTINCT'];
+       keywords.push('DISTINCT');
+       if (parser.isImpala()) {
+         keywords.push('ALL');
+       }
        if (parser.yy.result.suggestKeywords) {
          keywords = parser.yy.result.suggestKeywords.concat(keywords);
        }
-       parser.suggestKeywords(keywords);
      }
+     parser.suggestKeywords(keywords);
      $$ = { types: parser.findReturnTypes($1) };
    }
  | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList 'CURSOR' RightParenthesisOrError
@@ -3700,12 +3704,15 @@ CountFunction_EDIT
    }
  | 'COUNT' '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
    {
-     if ($4.cursorAtStart && !$3) {
-       if (parser.isImpala()) {
-         parser.suggestKeywords(['ALL', 'DISTINCT']);
-       } else {
-         parser.suggestKeywords(['DISTINCT']);
+     if ($4.cursorAtStart) {
+       var keywords = parser.getSelectListKeywords();
+       if (!$3) {
+         keywords.push('DISTINCT');
+         if (parser.isImpala()) {
+           keywords.push('ALL');
+         }
        }
+       parser.suggestKeywords(keywords);
      }
      $$ = { types: parser.findReturnTypes($1) };
    }
@@ -3765,20 +3772,21 @@ OtherAggregateFunction_EDIT
  : OtherAggregateFunction_Type '(' OptionalAllOrDistinct AnyCursor RightParenthesisOrError
    {
      parser.valueExpressionSuggest();
+     var keywords = parser.getSelectListKeywords(true);
      if (!$3) {
-       var keywords = [];
        if ($1.toLowerCase() === 'group_concat') {
-         keywords = ['ALL'];
+         keywords.push('ALL');
        } else if (parser.isImpala()) {
-         keywords = ['ALL', 'DISTINCT'];
+         keywords.push('ALL');
+         keywords.push('DISTINCT');
        } else {
-         keywords = ['DISTINCT'];
-       }
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
+         keywords.push('DISTINCT');
        }
-       parser.suggestKeywords(keywords);
      }
+     if (parser.yy.result.suggestKeywords) {
+       keywords = parser.yy.result.suggestKeywords.concat(keywords);
+     }
+     parser.suggestKeywords(keywords);
      parser.applyArgumentTypesToSuggestions($1, 1);
      $$ = { types: parser.findReturnTypes($1) };
    }
@@ -3789,14 +3797,17 @@ OtherAggregateFunction_EDIT
    }
  | OtherAggregateFunction_Type '(' OptionalAllOrDistinct ValueExpressionList_EDIT RightParenthesisOrError
    {
-     if ($4.cursorAtStart && !$3) {
-       var keywords = [];
-       if ($1.toLowerCase() === 'group_concat') {
-         keywords = ['ALL'];
-       } else if (parser.isImpala()) {
-         keywords = ['ALL', 'DISTINCT'];
-       } else {
-         keywords = ['DISTINCT'];
+     if ($4.cursorAtStart) {
+       var keywords = parser.getSelectListKeywords(true);
+       if (!$3) {
+         if ($1.toLowerCase() === 'group_concat') {
+           keywords.push('ALL');
+         } else if (parser.isImpala()) {
+           keywords.push('ALL');
+           keywords.push('DISTINCT');
+         } else {
+           keywords.push('DISTINCT');
+         }
        }
        if (parser.yy.result.suggestKeywords) {
          keywords = parser.yy.result.suggestKeywords.concat(keywords);
@@ -3931,13 +3942,17 @@ SumFunction_EDIT
    {
      parser.valueExpressionSuggest();
      parser.applyArgumentTypesToSuggestions($1, 1);
+     var keywords = parser.getSelectListKeywords(true);
      if (!$3) {
-       var keywords = parser.isImpala() ? ['ALL', 'DISTINCT'] : ['DISTINCT'];
-       if (parser.yy.result.suggestKeywords) {
-         keywords = parser.yy.result.suggestKeywords.concat(keywords);
+       keywords.push('DISTINCT');
+       if (parser.isImpala()) {
+         keywords.push('ALL');
        }
-       parser.suggestKeywords(keywords);
      }
+     if (parser.yy.result.suggestKeywords) {
+       keywords = parser.yy.result.suggestKeywords.concat(keywords);
+     }
+     parser.suggestKeywords(keywords);
      $$ = { types: parser.findReturnTypes($1) };
    }
  | 'SUM' '(' OptionalAllOrDistinct ValueExpression 'CURSOR' RightParenthesisOrError

+ 4 - 4
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecCreate.js

@@ -2936,13 +2936,13 @@
           beforeCursor: 'CREATE VIEW foo AS SELECT a, ',
           afterCursor: ' FROM tableOne',
           hasLocations:true,
+          containsKeywords: ['*', 'CASE'],
           expectedResult: {
             lowerCase: false,
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'tableOne' }] }] },
             suggestAnalyticFunctions: true,
             suggestFunctions: {},
-            suggestColumns:  { source: 'select', tables: [{ identifierChain: [{ name: 'tableOne' }] }] },
-            suggestKeywords: ['*']
+            suggestColumns:  { source: 'select', tables: [{ identifierChain: [{ name: 'tableOne' }] }] }
           }
         });
       });
@@ -3021,13 +3021,13 @@
             afterCursor: ' FROM tableOne',
             dialect: 'hive',
             hasLocations:true,
+            containsKeywords: ['*', 'CASE'],
             expectedResult: {
               lowerCase: false,
               suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'tableOne' }] }] },
               suggestAnalyticFunctions: true,
               suggestFunctions: {},
-              suggestColumns: { source: 'select', tables: [{ identifierChain: [{ name: 'tableOne' }] }] },
-              suggestKeywords: ['*']
+              suggestColumns: { source: 'select', tables: [{ identifierChain: [{ name: 'tableOne' }] }] }
             }
           });
         });

+ 6 - 6
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecInsert.js

@@ -373,7 +373,7 @@
             afterCursor: '',
             dialect: 'hive',
             noErrors: true,
-            containsKeywords: ['*'],
+            containsKeywords: ['*', 'CASE'],
             expectedResult: {
               lowerCase: false,
               suggestFunctions: {},
@@ -496,7 +496,7 @@
             afterCursor: '',
             dialect: 'hive',
             noErrors: true,
-            containsKeywords: ['*'],
+            containsKeywords: ['*', 'CASE'],
             expectedResult: {
               lowerCase: false,
               suggestFunctions: {},
@@ -545,7 +545,7 @@
             afterCursor: '',
             dialect: 'hive',
             noErrors: true,
-            containsKeywords: ['*'],
+            containsKeywords: ['*', 'CASE'],
             expectedResult: {
               lowerCase: false,
               suggestFunctions: {},
@@ -669,7 +669,7 @@
             afterCursor: '',
             dialect: 'hive',
             noErrors: true,
-            containsKeywords: ['*'],
+            containsKeywords: ['*', 'CASE'],
             expectedResult: {
               lowerCase: false,
               suggestFunctions: {},
@@ -863,7 +863,7 @@
             afterCursor: '',
             dialect: 'hive',
             noErrors: true,
-            containsKeywords: ['*'],
+            containsKeywords: ['*', 'CASE'],
             expectedResult: {
               lowerCase: false,
               suggestFunctions: {},
@@ -1438,11 +1438,11 @@
           afterCursor: '',
           dialect: 'hive',
           noErrors: true,
+          containsKeywords: ['CASE', 'EXISTS', 'NOT', 'NULL'],
           expectedResult: {
             lowerCase: false,
             suggestColumns: { tables: [{ identifierChain: [{ name: 'db' }, { name: 'tbl2' }], alias: 'S' }, { identifierChain: [{ name: 'tbl' }], alias: 'T' }] },
             suggestFunctions: {},
-            suggestKeywords: ['CASE', 'EXISTS', 'NOT', 'NULL'],
             suggestIdentifiers: [{ name: 'S.', type: 'alias' }, { name: 'T.', type: 'alias' }]
           }
         });

+ 28 - 29
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecSelect.js

@@ -342,13 +342,13 @@
         assertAutoComplete({
           beforeCursor: 'SELECT IF(baa, boo, bee) AS b, ',
           afterCursor: ' FROM testTable',
+          containsKeywords: ['*', 'CASE'],
           expectedResult: {
             lowerCase: false,
             suggestFunctions: {},
             suggestAnalyticFunctions: true,
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }] }] },
-            suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] },
-            suggestKeywords: ['*']
+            suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] }
           }
         });
       });
@@ -357,13 +357,13 @@
         assertAutoComplete({
           beforeCursor: 'SELECT IF(baa > 2, boo, bee) AS b, ',
           afterCursor: ' FROM testTable',
+          containsKeywords: ['*', 'CASE'],
           expectedResult: {
             lowerCase: false,
             suggestFunctions: {},
             suggestAnalyticFunctions: true,
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }] }] },
-            suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] },
-            suggestKeywords: ['*']
+            suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] }
           }
         });
       });
@@ -559,7 +559,7 @@
         assertAutoComplete({
           beforeCursor: 'SELECT ALL ',
           afterCursor: '',
-          containsKeywords: ['*'],
+          containsKeywords: ['*', 'CASE'],
           doesNotContainKeywords: ['ALL', 'DISTINCT'],
           expectedResult: {
             lowerCase: false,
@@ -584,7 +584,7 @@
           beforeCursor: 'SELECT STRAIGHT_JOIN ',
           afterCursor: '',
           dialect: 'impala',
-          containsKeywords: ['*'],
+          containsKeywords: ['*', 'CASE'],
           doesNotContainKeywords: ['ALL', 'DISTINCT'],
           expectedResult: {
             lowerCase: false,
@@ -915,10 +915,10 @@
           afterCursor: ' FROM testTableA tta, (SELECT SUM(A*B) total FROM tta.arr) ttaSum, testTableB ttb',
           ignoreErrors: true,
           dialect: 'hive',
+          containsKeywords: ['*', 'ALL', 'DISTINCT'],
           expectedResult: {
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTableA' }], alias: 'tta' }, { identifierChain: [{ name: 'testTableB' }], alias: 'ttb' }] },
             suggestAnalyticFunctions: true,
-            suggestKeywords: ['*', 'ALL', 'DISTINCT'],
             suggestFunctions: {},
             suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTableA' }], alias: 'tta' }, { identifierChain: [{ subQuery: 'ttaSum'}] }, { identifierChain: [{ name: 'testTableB' }], alias: 'ttb' }] },
             subQueries: [{
@@ -935,9 +935,9 @@
         assertAutoComplete({
           beforeCursor: 'SELECT a, ',
           afterCursor: ' FROM tableA;',
+          containsKeywords: ['*', 'CASE'],
           expectedResult: {
             lowerCase: false,
-            suggestKeywords: ['*'],
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'tableA' }] }] },
             suggestAnalyticFunctions: true,
             suggestFunctions: {},
@@ -950,9 +950,9 @@
         assertAutoComplete({
           beforeCursor: 'SELECT a,',
           afterCursor: ' FROM testTable',
+          containsKeywords: ['*', 'CASE'],
           expectedResult: {
             lowerCase: false,
-            suggestKeywords: ['*'],
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }] }] },
             suggestAnalyticFunctions: true,
             suggestFunctions: {},
@@ -965,9 +965,9 @@
         assertAutoComplete({
           beforeCursor: 'SELECT *, ',
           afterCursor: ' FROM tableA;',
+          containsKeywords: ['*', 'CASE'],
           expectedResult: {
             lowerCase: false,
-            suggestKeywords: ['*'],
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'tableA' }] }] },
             suggestAnalyticFunctions: true,
             suggestFunctions: {},
@@ -1047,9 +1047,9 @@
         assertAutoComplete({
           beforeCursor: 'SELECT a, b, ',
           afterCursor: ',c, d FROM testTable WHERE a = \'US\' AND b >= 998 ORDER BY c DESC LIMIT 15',
+          containsKeywords: ['*', 'CASE'],
           expectedResult: {
             lowerCase: false,
-            suggestKeywords: ['*'],
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }] }] },
             suggestAnalyticFunctions: true,
             suggestFunctions: {},
@@ -3020,6 +3020,7 @@
             beforeCursor: 'SELECT ',
             afterCursor: ' FROM testTable LATERAL VIEW explode(testArray) explodedTable AS testItem',
             dialect: 'hive',
+            containsKeywords: ['*', 'ALL', 'DISTINCT'],
             expectedResult: {
               locations: [
                 { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 81 } },
@@ -3032,7 +3033,6 @@
               ],
               suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }] }] },
               suggestAnalyticFunctions: true,
-              suggestKeywords: ['*', 'ALL', 'DISTINCT'],
               suggestFunctions: {},
               suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] },
               suggestIdentifiers: [{ name: 'explodedTable.', type: 'alias' }, { name: 'testItem', type: 'alias' }],
@@ -3082,13 +3082,13 @@
             beforeCursor: 'SELECT ',
             afterCursor: ' FROM testTable LATERAL VIEW explode(',
             dialect: 'hive',
+            containsKeywords: ['*','ALL','DISTINCT'],
             expectedResult: {
               lowerCase: false,
               suggestFunctions: {},
               suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }] }] },
               suggestAnalyticFunctions: true,
-              suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] },
-              suggestKeywords: ['*','ALL','DISTINCT']
+              suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] }
             }
           });
         });
@@ -3138,9 +3138,9 @@
             beforeCursor: 'SELECT ',
             afterCursor: ' FROM testTable LATERAL VIEW explode(testMap) explodedTable AS testKey, testValue',
             dialect: 'hive',
+            containsKeywords: ['*', 'ALL', 'DISTINCT'],
             expectedResult: {
               lowerCase: false,
-              suggestKeywords: ['*', 'ALL', 'DISTINCT'],
               suggestColumns: { source: 'select', tables: [{ identifierChain: [{ name: 'testTable' }] }] },
               suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }] }] },
               suggestAnalyticFunctions: true,
@@ -3310,9 +3310,9 @@
             beforeCursor: 'SELECT ',
             afterCursor: ' FROM testTable LATERAL VIEW explode(testMap) explodedMap AS testMapKey, testMapValue',
             dialect: 'hive',
+            containsKeywords: ['*', 'ALL', 'DISTINCT'],
             expectedResult: {
               lowerCase: false,
-              suggestKeywords: ['*', 'ALL', 'DISTINCT'],
               suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }] }] },
               suggestAnalyticFunctions: true,
               suggestFunctions: {},
@@ -3467,9 +3467,9 @@
           beforeCursor: 'SELECT ',
           afterCursor: ' FROM testTable t, t.testMap tm;',
           dialect: 'impala',
+          containsKeywords: ['*', 'ALL', 'DISTINCT', 'STRAIGHT_JOIN'],
           expectedResult: {
             lowerCase: false,
-            suggestKeywords: ['*', 'ALL', 'DISTINCT', 'STRAIGHT_JOIN'],
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }], alias: 't' }] },
             suggestAnalyticFunctions: true,
             suggestFunctions: {},
@@ -4868,12 +4868,11 @@
             afterCursor: ' FROM tbl',
             dialect: 'impala',
             noErrors: true,
+            containsKeywords: ['CASE', 'NULL'],
             expectedResult: {
               lowerCase: false,
-              suggestKeywords: ['FROM'],
               suggestColumns: { types: ['NUMBER'], source: 'select', tables: [{ identifierChain: [{ name: 'tbl' }] }] },
-              suggestFunctions: { types: ['NUMBER'] },
-              suggestKeywords: ['CASE', 'NULL']
+              suggestFunctions: { types: ['NUMBER'] }
             }
           });
         });
@@ -4955,11 +4954,11 @@
         assertAutoComplete({
           beforeCursor: 'SELECT * FROM testTable WHERE baa = 1 AND ',
           afterCursor: '',
+          containsKeywords: ['CASE', 'EXISTS', 'NOT', 'NULL'],
           expectedResult: {
             lowerCase: false,
             suggestColumns: { source: 'where',  tables: [{ identifierChain: [{ name: 'testTable' }] }] },
             suggestFunctions: {},
-            suggestKeywords: ['CASE', 'EXISTS', 'NOT', 'NULL'],
             suggestFilters: { tables: [{ identifierChain: [{ name: 'testTable' }] }] }
           }
         });
@@ -4969,11 +4968,11 @@
         assertAutoComplete({
           beforeCursor: 'SELECT * FROM testTable WHERE ',
           afterCursor: ' AND baa = 1',
+          containsKeywords: ['CASE', 'EXISTS', 'NOT', 'NULL'],
           expectedResult: {
             lowerCase: false,
             suggestColumns: { source: 'where',  tables: [{ identifierChain: [{ name: 'testTable' }] }] },
             suggestFunctions: {},
-            suggestKeywords: ['CASE', 'EXISTS', 'NOT', 'NULL'],
             suggestFilters: { tables: [{ identifierChain: [{ name: 'testTable' }] }] }
           }
         });
@@ -4983,11 +4982,11 @@
         assertAutoComplete({
           beforeCursor: 'SELECT * FROM testTable WHERE baa = 1 OR ',
           afterCursor: '',
+          containsKeywords: ['CASE', 'EXISTS', 'NOT', 'NULL'],
           expectedResult: {
             lowerCase: false,
             suggestColumns: { source: 'where',  tables: [{ identifierChain: [{ name: 'testTable' }] }] },
             suggestFunctions: {},
-            suggestKeywords: ['CASE', 'EXISTS', 'NOT', 'NULL'],
             suggestFilters: { tables: [{ identifierChain: [{ name: 'testTable' }] }] }
           }
         });
@@ -4997,11 +4996,11 @@
         assertAutoComplete({
           beforeCursor: 'SELECT * FROM testTable WHERE ',
           afterCursor: ' OR baa = 1',
+          containsKeywords: ['CASE', 'EXISTS', 'NOT', 'NULL'],
           expectedResult: {
             lowerCase: false,
             suggestColumns: { source: 'where',  tables: [{ identifierChain: [{ name: 'testTable' }] }] },
             suggestFunctions: {},
-            suggestKeywords: ['CASE', 'EXISTS', 'NOT', 'NULL'],
             suggestFilters: { tables: [{ identifierChain: [{ name: 'testTable' }] }] }
           }
         });
@@ -5064,28 +5063,28 @@
         assertAutoComplete({
           beforeCursor: 'SELECT a, b, \nc,\nd, ',
           afterCursor: '\ng,\nf\nFROM testTable WHERE a > 1 AND b = \'b\' ORDER BY c;',
+          containsKeywords: ['*', 'CASE'],
           expectedResult: {
             lowerCase: false,
             suggestFunctions: {},
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }] }] },
             suggestAnalyticFunctions: true,
-            suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] },
-            suggestKeywords: ['*']
+            suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] }
           }
         });
       });
 
-      it('should suggest columns for "SELECT a, b, | c FROM testTable"', function() {
+      it('should suggest columns for "SELECT a,b, | c FROM testTable"', function() {
         assertAutoComplete({
           beforeCursor: 'SELECT a,b, ',
           afterCursor: ' c FROM testTable',
+          containsKeywords: ['*'],
           expectedResult: {
             lowerCase: false,
             suggestFunctions: {},
             suggestAggregateFunctions: { tables: [{ identifierChain: [{ name: 'testTable' }] }] },
             suggestAnalyticFunctions: true,
-            suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] },
-            suggestKeywords: ['*']
+            suggestColumns: { source: 'select',  tables: [{ identifierChain: [{ name: 'testTable' }] }] }
           }
         });
       });

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlAutocompleteParser.js


+ 16 - 7
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlParseSupport.js

@@ -212,6 +212,17 @@ var SqlParseSupport = (function () {
       }
     };
 
+    parser.getSelectListKeywords = function (excludeAsterisk) {
+      var keywords = [{ value: 'CASE', weight: 450 }, 'FALSE', 'TRUE', 'NULL'];
+      if (!excludeAsterisk) {
+        keywords.push({ value: '*', weight: 10000 });
+      }
+      if (parser.isHive()) {
+        keywords = keywords.concat(['EXISTS', 'NOT']);
+      }
+      return keywords;
+    };
+
     parser.getValueExpressionKeywords = function (valueExpression, extras) {
       var types = valueExpression.lastType ? valueExpression.lastType.types : valueExpression.types;
       // We could have valueExpression.columnReference to suggest based on column type
@@ -275,11 +286,9 @@ var SqlParseSupport = (function () {
 
     parser.selectListNoTableSuggest = function (selectListEdit, hasDistinctOrAll) {
       if (selectListEdit.cursorAtStart) {
-        var keywords = [];
-        if (hasDistinctOrAll) {
-          keywords = [{value: '*', weight: 1000}];
-        } else {
-          keywords = [{value: '*', weight: 1000}, 'ALL', 'DISTINCT'];
+        var keywords = parser.getSelectListKeywords();
+        if (!hasDistinctOrAll) {
+          keywords = keywords.concat([{ value: 'ALL', weight: 2 }, { value: 'DISTINCT', weight: 2 }]);
         }
         if (parser.isImpala()) {
           keywords.push('STRAIGHT_JOIN');
@@ -318,7 +327,7 @@ var SqlParseSupport = (function () {
       }
       parser.suggestColumns();
       parser.suggestFunctions();
-      var keywords = ['CASE', 'NULL'];
+      var keywords = [{ value: 'CASE', weight: 450 }, { value: 'FALSE', weight: 450 }, { value: 'NULL', weight: 450 }, { value: 'TRUE', weight: 450 }];
       if (parser.isHive() || typeof oppositeValueExpression === 'undefined' || typeof operator === 'undefined') {
         keywords = keywords.concat(['EXISTS', 'NOT']);
       }
@@ -1842,7 +1851,7 @@ var SqlParseSupport = (function () {
   };
 
   var SYNTAX_PARSER_NOOP_FUNCTIONS = ['prepareNewStatement', 'addCommonTableExpressions', 'pushQueryState', 'popQueryState', 'suggestSelectListAliases',
-    'suggestValueExpressionKeywords', 'getValueExpressionKeywords', 'addColRefIfExists', 'selectListNoTableSuggest', 'suggestJoinConditions',
+    'suggestValueExpressionKeywords', 'getSelectListKeywords', 'getValueExpressionKeywords', 'addColRefIfExists', 'selectListNoTableSuggest', 'suggestJoinConditions',
     'suggestJoins', 'valueExpressionSuggest', 'applyTypeToSuggestions', 'applyArgumentTypesToSuggestions', 'commitLocations', 'identifyPartials',
     'getSubQuery', 'addTablePrimary', 'suggestFileFormats', 'suggestDdlAndDmlKeywords', 'checkForSelectListKeywords', 'checkForKeywords',
     'suggestKeywords', 'suggestColRefKeywords', 'suggestTablesOrColumns', 'suggestFunctions', 'suggestAggregateFunctions', 'suggestAnalyticFunctions',

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlSyntaxParser.js


+ 4 - 4
desktop/core/src/desktop/static/desktop/js/sqlAutocompleter3.js

@@ -466,9 +466,9 @@ var AutocompleteResults = (function () {
               category: CATEGORIES.UDF,
               value: name + '()',
               meta: functionsToSuggest[name].returnTypes.join('|'),
-              weightAdjust: functionsToSuggest[name].returnTypes.filter(function (otherType) {
+              weightAdjust: colRef.type.toUpperCase() !== 'T' && functionsToSuggest[name].returnTypes.some(function (otherType) {
                   return otherType === colRef.type.toUpperCase();
-              }).length > 0 ? 1 : 0,
+              }) ? 1 : 0,
               popular: ko.observable(false),
               details: functionsToSuggest[name]
             })
@@ -485,9 +485,9 @@ var AutocompleteResults = (function () {
             category: CATEGORIES.UDF,
             value: name + '()',
             meta: functionsToSuggest[name].returnTypes.join('|'),
-            weightAdjust: functionsToSuggest[name].returnTypes.filter(function (otherType) {
+            weightAdjust: types[0].toUpperCase() !== 'T' && functionsToSuggest[name].returnTypes.some(function (otherType) {
               return otherType === types[0].toUpperCase();
-            }).length > 0 ? 1 : 0,
+            }) ? 1 : 0,
             popular: ko.observable(false),
             details: functionsToSuggest[name]
           })

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است