Browse Source

HUE-4643 [editor] Autocompleter is silent for the second argument of concat

This also improves the resiliency of the autocompleter on the right side of FROM
Johan Ahlen 9 years ago
parent
commit
00e77ecaeb

+ 103 - 7
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_error.jison

@@ -21,29 +21,52 @@ SqlStatements
 
 SelectStatement
  : 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression
+ | 'SELECT' OptionalAllOrDistinct SelectList TableExpression_ERROR
+ ;
+
+SelectStatement_EDIT
+ : 'SELECT' OptionalAllOrDistinct SelectList_ERROR_EDIT TableExpression
  | 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression_EDIT
  ;
 
 SelectList_ERROR
- : SelectList ',' error ',' SelectList
- | error ',' SelectList
- | SelectList ',' error
- | error
- | error ',' AnyCursor
+ : ErrorList
+ | SelectList ',' ErrorList
+ | ErrorList ',' SelectList ',' ErrorList
+ | ErrorList ',' SelectList
+ | SelectList ',' ErrorList ',' SelectList
+ ;
+
+SelectList_ERROR_EDIT
+ : ErrorList ',' SelectList_EDIT
+ | SelectList ',' ErrorList ',' SelectList_EDIT
+ | ErrorList ',' SelectList ',' ErrorList ',' SelectList_EDIT
+ | ErrorList ',' AnyCursor
    {
      suggestFunctions();
      suggestColumns();
      suggestFunctions();
      $$ = { cursorAtStart : false, suggestAggregateFunctions: true };
    }
- | SelectList ',' error ',' SelectList_EDIT
- | SelectList ',' error ',' AnyCursor
+ | SelectList ',' ErrorList ',' AnyCursor
    {
      suggestFunctions();
      suggestColumns();
      suggestFunctions();
      $$ = { cursorAtStart : false, suggestAggregateFunctions: true };
    }
+ | ErrorList ',' SelectList ',' Errors ',' AnyCursor
+   {
+     suggestFunctions();
+     suggestColumns();
+     suggestFunctions();
+     $$ = { cursorAtStart : false, suggestAggregateFunctions: true };
+   }
+ ;
+
+ErrorList
+ : error
+ | Errors ',' error
  ;
 
 LateralView
@@ -78,6 +101,79 @@ JoinTypes_EDIT
    }
  ;
 
+OptionalSelectConditions_EDIT
+ : WhereClause error 'CURSOR' OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+   {
+     $$ = {
+       suggestKeywords: getKeywordsForOptionalsLR([$4, $5, $6, $7, $8, $9, $10], [{ value: 'GROUP BY', weight: 8 }, { value: 'HAVING', weight: 7 }, { value: 'WINDOW', weight: 6 }, { value: 'ORDER BY', weight: 5 }, [{ value: 'CLUSTER BY', weight: 4 }, { value: 'DISTRIBUTE BY', weight: 4 }, { value: 'SORT BY', weight: 4 }], { value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [true, true, isHive(), true, isHive(), true, isImpala()]),
+       cursorAtEnd: !$4 && !$5 && !$6 && !$7 && !$8 && !$9 && !$10
+     };
+   }
+ | OptionalWhereClause OptionalGroupByClause HavingClause error 'CURSOR' OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+   {
+     $$ = {
+       suggestKeywords: getKeywordsForOptionalsLR([$6, $7, $8, $9, $10], [{ value: 'WINDOW', weight: 6 }, { value: 'ORDER BY', weight: 5 }, [{ value: 'CLUSTER BY', weight: 4 }, { value: 'DISTRIBUTE BY', weight: 4 }, { value: 'SORT BY', weight: 4 }], { value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [isHive(), true, isHive(), true, isImpala()]),
+       cursorAtEnd: !$6 && !$7 && !$8 && !$9 && !$10
+     }
+   }
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause WindowClause error 'CURSOR' OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+   {
+     $$ = {
+       suggestKeywords: getKeywordsForOptionalsLR([$7, $8, $9, $10], [{ value: 'ORDER BY', weight: 5 }, [{ value: 'CLUSTER BY', weight: 4 }, { value: 'DISTRIBUTE BY', weight: 4 }, { value: 'SORT BY', weight: 4 }], { value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [true, isHive(), true, isImpala()]),
+       cursorAtEnd: !$7 && !$8 && !$9 && !$10
+     }
+   }
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OrderByClause error 'CURSOR' OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+   {
+     $$ = {
+       suggestKeywords: getKeywordsForOptionalsLR([$8, $9, $10], [[{ value: 'CLUSTER BY', weight: 4 }, { value: 'DISTRIBUTE BY', weight: 4 }, { value: 'SORT BY', weight: 4 }], { value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [isHive(), true, isImpala()]),
+       cursorAtEnd: !$8 && !$9 && !$10
+     }
+   }
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause ClusterOrDistributeBy error 'CURSOR' OptionalLimitClause OptionalOffsetClause
+   {
+     $$ = {
+       suggestKeywords: getKeywordsForOptionalsLR([$9, $10], [{ value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [true, isImpala()]),
+       cursorAtEnd: !$9 && !$10
+     }
+   }
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy LimitClause error 'CURSOR' OptionalOffsetClause
+   {
+     $$ = {
+       suggestKeywords: getKeywordsForOptionalsLR([$10], [{ value: 'OFFSET', weight: 2 }], [isImpala()]),
+       cursorAtEnd: !$10
+     }
+   }
+ ;
+
+OptionalSelectConditions_EDIT
+ : WhereClause error GroupByClause_EDIT OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+ | WhereClause error OptionalGroupByClause HavingClause_EDIT OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+ | WhereClause error OptionalGroupByClause OptionalHavingClause WindowClause_EDIT OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+ | WhereClause error OptionalGroupByClause OptionalHavingClause OptionalWindowClause OrderByClause_EDIT OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+ | WhereClause error OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause ClusterOrDistributeBy_EDIT OptionalLimitClause OptionalOffsetClause
+ | WhereClause error OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy LimitClause_EDIT OptionalOffsetClause
+ | WhereClause error OptionalGroupByClause OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OffsetClause_EDIT
+ | OptionalWhereClause GroupByClause error HavingClause_EDIT OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+ | OptionalWhereClause GroupByClause error OptionalHavingClause WindowClause_EDIT OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+ | OptionalWhereClause GroupByClause error OptionalHavingClause OptionalWindowClause OrderByClause_EDIT OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+ | OptionalWhereClause GroupByClause error OptionalHavingClause OptionalWindowClause OptionalOrderByClause ClusterOrDistributeBy_EDIT OptionalLimitClause OptionalOffsetClause
+ | OptionalWhereClause GroupByClause error OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy LimitClause_EDIT OptionalOffsetClause
+ | OptionalWhereClause GroupByClause error OptionalHavingClause OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OffsetClause_EDIT
+ | OptionalWhereClause OptionalGroupByClause HavingClause error WindowClause_EDIT OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+ | OptionalWhereClause OptionalGroupByClause HavingClause error OptionalWindowClause OrderByClause_EDIT OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+ | OptionalWhereClause OptionalGroupByClause HavingClause error OptionalWindowClause OptionalOrderByClause ClusterOrDistributeBy_EDIT OptionalLimitClause OptionalOffsetClause
+ | OptionalWhereClause OptionalGroupByClause HavingClause error OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy LimitClause_EDIT OptionalOffsetClause
+ | OptionalWhereClause OptionalGroupByClause HavingClause error OptionalWindowClause OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OffsetClause_EDIT
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause WindowClause error OrderByClause_EDIT OptionalClusterOrDistributeBy OptionalLimitClause OptionalOffsetClause
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause WindowClause error OptionalOrderByClause ClusterOrDistributeBy_EDIT OptionalLimitClause OptionalOffsetClause
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause WindowClause error OptionalOrderByClause OptionalClusterOrDistributeBy LimitClause_EDIT OptionalOffsetClause
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause WindowClause error OptionalOrderByClause OptionalClusterOrDistributeBy OptionalLimitClause OffsetClause_EDIT
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OrderByClause error ClusterOrDistributeBy_EDIT OptionalLimitClause OptionalOffsetClause
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OrderByClause error OptionalClusterOrDistributeBy LimitClause_EDIT OptionalOffsetClause
+ | OptionalWhereClause OptionalGroupByClause OptionalHavingClause OptionalWindowClause OrderByClause error OptionalClusterOrDistributeBy OptionalLimitClause OffsetClause_EDIT
+ ;
+
 DatabaseDefinition_EDIT
  : AnyCreate DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals_EDIT error
  ;

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

@@ -1412,7 +1412,7 @@ OptionalSelectConditions_EDIT
    {
      var keywords = getKeywordsForOptionalsLR([$3, $4, $5, $6, $7, $8, $9], [{ value: 'GROUP BY', weight: 8 }, { value: 'HAVING', weight: 7 }, { value: 'WINDOW', weight: 6 }, { value: 'ORDER BY', weight: 5 }, [{ value: 'CLUSTER BY', weight: 4 }, { value: 'DISTRIBUTE BY', weight: 4 }, { value: 'SORT BY', weight: 4 }], { value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [true, true, isHive(), true, isHive(), true, isImpala()]);
      if ($1.suggestKeywords) {
-       keywords = createWeightedKeywords($1.suggestKeywords, 1);
+       keywords = keywords.concat(createWeightedKeywords($1.suggestKeywords, 1));
      }
      $$ = getValueExpressionKeywords($1, keywords);
      $$.cursorAtEnd = !$3 && !$4 && !$5 && !$6 && !$7 && !$8 && !$9;
@@ -1424,7 +1424,7 @@ OptionalSelectConditions_EDIT
    {
      var keywords = getKeywordsForOptionalsLR([$4, $5, $6, $7, $8, $9], [{ value: 'HAVING', weight: 7 }, { value: 'WINDOW', weight: 6 }, { value: 'ORDER BY', weight: 5 }, [{ value: 'CLUSTER BY', weight: 4 }, { value: 'DISTRIBUTE BY', weight: 4 }, { value: 'SORT BY', weight: 4 }], { value: 'LIMIT', weight: 3 }, { value: 'OFFSET', weight: 2 }], [true, isHive(), true, isHive(), true, isImpala()]);
      if ($2.suggestKeywords) {
-       keywords = createWeightedKeywords($2.suggestKeywords, 8);
+       keywords = keywords.concat(createWeightedKeywords($2.suggestKeywords, 8));
      }
      $$ = getValueExpressionKeywords($2, keywords);
      if ($2.columnReference) {
@@ -2126,7 +2126,6 @@ TableReferenceList
 TableReferenceList_EDIT
  : TableReference_EDIT
  | TableReference_EDIT ',' TableReference
-// | TableReferenceList 'CURSOR' ',' TableReferenceList   // TODO: Causes conflict for some reason
  | TableReferenceList ',' TableReference_EDIT
  | TableReferenceList ',' TableReference_EDIT ',' TableReferenceList
  | TableReferenceList ',' AnyCursor
@@ -2180,6 +2179,7 @@ Joins_INVALID
  : JoinTypes OptionalImpalaBroadcastOrShuffle                                           -> { joinType: $1 }
  | JoinTypes OptionalImpalaBroadcastOrShuffle Joins                                     -> { joinType: $1 }
  ;
+
 OptionalImpalaBroadcastOrShuffle
  :
  | '<impala>BROADCAST'

File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sql.js


+ 1 - 1
desktop/core/src/desktop/static/desktop/js/sqlFunctions.js

@@ -1438,7 +1438,7 @@
       },
       concat: {
         returnTypes: ['STRING'],
-        arguments: [[{type: 'STRING'}, {type: 'BINARY'}]],
+        arguments: [[{type: 'STRING', multiple: true}, {type: 'BINARY', multiple: true}]],
         signature: 'concat(STRING|BINARY a, STRING|BINARY b...)',
         description: 'Returns the string or bytes resulting from concatenating the strings or bytes passed in as parameters in order. For example, concat(\'foo\', \'bar\') results in \'foobar\'. Note that this function can take any number of input strings.'
       },

+ 86 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecError.js

@@ -42,5 +42,91 @@ define([
         }
       });
     });
+
+    it('should suggest columns for "SELECT foo, bar, SELECT, | FROM testTable"', function() {
+      assertAutoComplete({
+        beforeCursor: 'SELECT foo, bar, SELECT, ',
+        afterCursor: ' FROM testTable',
+        hasLocations: true,
+        expectedResult: {
+          lowerCase: false,
+          suggestFunctions: {},
+          suggestColumns: { table: 'testTable' }
+        }
+      });
+    });
+
+    it('should suggest columns for "SELECT foo, baa baa baa baa, SELECT, | FROM testTable"', function() {
+      assertAutoComplete({
+        beforeCursor: 'SELECT foo, baa baa baa baa, SELECT, ',
+        afterCursor: ' FROM testTable',
+        hasLocations: true,
+        expectedResult: {
+          lowerCase: false,
+          suggestFunctions: {},
+          suggestColumns: { table: 'testTable' }
+        }
+      });
+    });
+
+    it('should suggest columns for "SELECT * FROM testTable WHERE baa baaa booo |"', function() {
+      assertAutoComplete({
+        beforeCursor: 'SELECT * FROM testTable WHERE baa baaa boo',
+        afterCursor: '',
+        hasLocations: true,
+        containsKeywords: ['GROUP BY', 'ORDER BY'],
+        expectedResult: {
+          lowerCase: false
+        }
+      });
+    });
+
+    it('should suggest columns for "SELECT * FROM testTable WHERE baa baaa booo GROUP |"', function() {
+      assertAutoComplete({
+        beforeCursor: 'SELECT * FROM testTable WHERE baa baaa boo GROUP ',
+        afterCursor: '',
+        hasLocations: true,
+        expectedResult: {
+          lowerCase: false,
+          suggestKeywords: ['BY']
+        }
+      });
+    });
+
+    it('should suggest columns for "SELECT * FROM testTable WHERE baa baaa booo ORDER |"', function() {
+      assertAutoComplete({
+        beforeCursor: 'SELECT * FROM testTable WHERE baa baaa boo ORDER ',
+        afterCursor: '',
+        hasLocations: true,
+        expectedResult: {
+          lowerCase: false,
+          suggestKeywords: ['BY']
+        }
+      });
+    });
+
+    it('should suggest columns for "SELECT * FROM testTable ORDER BY bla bla bla boo |"', function() {
+      assertAutoComplete({
+        beforeCursor: 'SELECT * FROM testTable ORDER BY bla bla bla boo ',
+        afterCursor: '',
+        hasLocations: true,
+        containsKeywords: ['LIMIT', 'UNION'],
+        expectedResult: {
+          lowerCase: false
+        }
+      });
+    });
+
+    it('should suggest columns for "SELECT * FROM testTable GROUP BY boo hoo hoo ORDER BY bla bla bla boo |"', function() {
+      assertAutoComplete({
+        beforeCursor: 'SELECT * FROM testTable ORDER BY bla bla bla boo ',
+        afterCursor: '',
+        hasLocations: true,
+        containsKeywords: ['LIMIT', 'UNION'],
+        expectedResult: {
+          lowerCase: false
+        }
+      });
+    });
   });
 });

+ 5 - 2
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecSelect.js

@@ -392,6 +392,7 @@ define([
           beforeCursor: 'SELECT testTableB.a, cos(1), tta.abcdefg',
           afterCursor: 'hijk, tta.bla, cos(1) FROM testTableA tta, testTableB;',
           dialect: 'hive',
+          noErrors: true,
           expectedResult: {
             lowerCase: false,
             suggestColumns: { table: 'testTableA' },
@@ -5151,15 +5152,17 @@ define([
     });
 
     describe('ORDER BY Clause', function () {
-      xit('should suggest keywords for "SELECT * FROM testTable GROUP BY a | LIMIT 10"', function () {
+      it('should suggest keywords for "SELECT * FROM testTable GROUP BY a | LIMIT 10"', function () {
         assertAutoComplete({
           beforeCursor: 'SELECT * FROM testTable GROUP BY a ',
           afterCursor: ' LIMIT 10',
           hasLocations: true,
           doesNotContainKeywords: ['LIMIT'],
           containsKeywords: ['ORDER BY'],
+          containsColRefKeywords: true,
           expectedResult: {
-            lowerCase: false
+            lowerCase: false,
+            colRef: { identifierChain: [{ name: 'a' }], table: 'testTable' }
           }
         });
       });

+ 3 - 0
desktop/core/src/desktop/static/desktop/spec/sqlFunctionsSpec.js

@@ -136,6 +136,9 @@ define([
       expect(sqlFunctions.getArgumentTypes('impala', 'strleft', 3)).toEqual([]);
       expect(sqlFunctions.getArgumentTypes('impala', 'strleft', 200)).toEqual([]);
 
+      expect(sqlFunctions.getArgumentTypes('hive', 'concat', 10)).toEqual(['BINARY', 'STRING']);
+      expect(sqlFunctions.getArgumentTypes('impala', 'concat', 10)).toEqual(['STRING']);
+
       expect(sqlFunctions.getArgumentTypes('hive', 'substring_index', 1)).toEqual(['STRING']);
       expect(sqlFunctions.getArgumentTypes('hive', 'substring_index', 2)).toEqual(['STRING']);
       expect(sqlFunctions.getArgumentTypes('hive', 'substring_index', 3)).toEqual(['INT']);

Some files were not shown because too many files changed in this diff