Przeglądaj źródła

HUE-4634 [editor] The autocompleter should allow some errors in the select list

This also takes care of an issue with incorrect columns types for structs.
Johan Ahlen 10 lat temu
rodzic
commit
5fced5e814

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

@@ -77,7 +77,6 @@ DatabaseDefinition_EDIT
      }
    }
  | AnyCreate DatabaseOrSchema OptionalIfNotExists_EDIT RegularIdentifier
- | AnyCreate DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals_EDIT error
  | AnyCreate DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals 'CURSOR'
  ;
 

+ 83 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_error.jison

@@ -0,0 +1,83 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+SqlStatements
+ : error
+ | NonStartingToken error // Having just ': error' does not work for some reason, jison bug?
+ ;
+
+SelectStatement
+ : 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression
+ | 'SELECT' OptionalAllOrDistinct SelectList_ERROR TableExpression_EDIT
+ ;
+
+SelectList_ERROR
+ : SelectList ',' error ',' SelectList
+ | error ',' SelectList
+ | SelectList ',' error
+ | error
+ | error ',' AnyCursor
+   {
+     suggestFunctions();
+     suggestColumns();
+     suggestFunctions();
+     $$ = { cursorAtStart : false, suggestAggregateFunctions: true };
+   }
+ | SelectList ',' error ',' SelectList_EDIT
+ | SelectList ',' error ',' AnyCursor
+   {
+     suggestFunctions();
+     suggestColumns();
+     suggestFunctions();
+     $$ = { cursorAtStart : false, suggestAggregateFunctions: true };
+   }
+ ;
+
+LateralView
+ : '<hive>LATERAL' '<hive>VIEW' OptionalOuter UserDefinedFunction RegularIdentifier error  -> []
+ | '<hive>LATERAL' '<hive>VIEW' OptionalOuter UserDefinedFunction error                    -> []
+ | '<hive>LATERAL' '<hive>VIEW' OptionalOuter error                                        -> []
+ | '<hive>LATERAL' error                                                                   -> []
+ ;
+
+JoinTypes_EDIT
+ : 'FULL' 'CURSOR' error
+   {
+     suggestKeywords(['JOIN', 'OUTER JOIN']);
+   }
+ | 'LEFT' 'CURSOR' error
+   {
+     if (isHive()) {
+       suggestKeywords(['JOIN', 'OUTER JOIN', 'SEMI JOIN']);
+     } else if (isImpala()) {
+       suggestKeywords(['ANTI JOIN', 'JOIN', 'OUTER JOIN', 'SEMI JOIN']);
+     } else {
+       suggestKeywords(['JOIN', 'OUTER JOIN']);
+     }
+   }
+ | 'RIGHT' 'CURSOR' error
+   {
+     if (isImpala()) {
+       suggestKeywords(['ANTI JOIN', 'JOIN', 'OUTER JOIN', 'SEMI JOIN']);
+     } else {
+       suggestKeywords(['JOIN', 'OUTER JOIN']);
+     }
+   }
+ ;
+
+DatabaseDefinition_EDIT
+ : AnyCreate DatabaseOrSchema OptionalIfNotExists RegularIdentifier DatabaseDefinitionOptionals_EDIT error
+ ;

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

@@ -169,7 +169,6 @@ Sql
 
 SqlStatements
  :
- | ErrorStatement
  | DataDefinition
  | DataManipulation
  | QuerySpecification
@@ -183,11 +182,6 @@ SqlStatements_EDIT
  | SqlStatements ';' NewStatement SqlStatement_EDIT ';' NewStatement SqlStatements
  ;
 
-ErrorStatement
- : error
- | NonStartingToken error // Having just ': error' does not work for some reason, jison bug?
- ;
-
 SqlStatement_EDIT
  : AnyCursor
    {
@@ -1191,7 +1185,6 @@ SelectStatement_EDIT
      suggestDatabases({ prependQuestionMark: true, prependFrom: true, appendDot: true });
    }
  | 'SELECT' OptionalAllOrDistinct SelectList TableExpression_EDIT
- | 'SELECT' OptionalAllOrDistinct SelectList_EDIT error TableExpression
  | 'SELECT' OptionalAllOrDistinct SelectList_EDIT TableExpression
    {
      if ($3.cursorAtStart) {
@@ -1237,10 +1230,6 @@ SelectStatement_EDIT
      suggestTables({ prependQuestionMark: true, prependFrom: true });
      suggestDatabases({ prependQuestionMark: true, prependFrom: true, appendDot: true });
    }
- | 'SELECT' OptionalAllOrDistinct error TableExpression
- | 'SELECT' OptionalAllOrDistinct error TableExpression_EDIT
- | 'SELECT' OptionalAllOrDistinct SelectList error TableExpression        // Causes conflict but solves issue
- | 'SELECT' OptionalAllOrDistinct SelectList error TableExpression_EDIT   // with SELECT a, b, cos(| c AS d
  | 'SELECT' OptionalAllOrDistinct SelectList 'CURSOR' TableExpression
    {
      checkForSelectListKeywords($3);
@@ -1249,10 +1238,6 @@ SelectStatement_EDIT
    {
      checkForSelectListKeywords($3);
    }
- | 'SELECT' OptionalAllOrDistinct SelectList 'CURSOR' ',' error TableExpression
-   {
-     checkForSelectListKeywords($3);
-   }
  | 'SELECT' OptionalAllOrDistinct SelectList 'CURSOR'
    {
      checkForSelectListKeywords($3);
@@ -2043,6 +2028,17 @@ SelectList
 SelectList_EDIT
  : SelectSubList_EDIT
  | SelectSubList_EDIT ',' SelectList
+ | SelectList 'CURSOR' ',' SelectList
+   {
+     checkForSelectListKeywords($1);
+   }
+ | 'CURSOR' ',' SelectList
+   {
+     suggestFunctions();
+     suggestColumns();
+     suggestFunctions();
+     $$ = { cursorAtStart : true, suggestAggregateFunctions: true };
+   }
  | 'CURSOR' SelectList
    {
      suggestFunctions();
@@ -2239,10 +2235,6 @@ JoinTypes_EDIT
    {
      suggestKeywords(['JOIN']);
    }
- | 'FULL' 'CURSOR' error
-   {
-     suggestKeywords(['JOIN', 'OUTER JOIN']);
-   }
  | 'FULL' 'OUTER' 'CURSOR'
    {
      suggestKeywords(['JOIN']);
@@ -2251,16 +2243,6 @@ JoinTypes_EDIT
    {
      suggestKeywords(['OUTER']);
    }
- | 'LEFT' 'CURSOR' error
-   {
-     if (isHive()) {
-       suggestKeywords(['JOIN', 'OUTER JOIN', 'SEMI JOIN']);
-     } else if (isImpala()) {
-       suggestKeywords(['ANTI JOIN', 'JOIN', 'OUTER JOIN', 'SEMI JOIN']);
-     } else {
-       suggestKeywords(['JOIN', 'OUTER JOIN']);
-     }
-   }
  | 'LEFT' 'SEMI' 'CURSOR'
    {
      suggestKeywords(['JOIN']);
@@ -2283,14 +2265,6 @@ JoinTypes_EDIT
        suggestKeywords(['OUTER']);
      }
    }
- | 'RIGHT' 'CURSOR' error
-   {
-     if (isImpala()) {
-       suggestKeywords(['ANTI JOIN', 'JOIN', 'OUTER JOIN', 'SEMI JOIN']);
-     } else {
-       suggestKeywords(['JOIN', 'OUTER JOIN']);
-     }
-   }
  | 'RIGHT' '<impala>ANTI' 'CURSOR'
    {
      suggestKeywords(['JOIN']);
@@ -3199,14 +3173,6 @@ SumFunction_EDIT
 LateralView
  : '<hive>LATERAL' '<hive>VIEW' OptionalOuter UserDefinedFunction RegularIdentifier LateralViewColumnAliases  -> [{ udtf: $4, tableAlias: $5, columnAliases: $6 }]
  | '<hive>LATERAL' '<hive>VIEW' OptionalOuter UserDefinedFunction LateralViewColumnAliases                    -> [{ udtf: $4, columnAliases: $5 }]
- | LateralView_INVALID
- ;
-
-LateralView_INVALID
- : '<hive>LATERAL' '<hive>VIEW' OptionalOuter UserDefinedFunction RegularIdentifier error  -> []
- | '<hive>LATERAL' '<hive>VIEW' OptionalOuter UserDefinedFunction error                    -> []
- | '<hive>LATERAL' '<hive>VIEW' OptionalOuter error                                        -> []
- | '<hive>LATERAL' error                                                                   -> []
  ;
 
 LateralView_EDIT

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sql.js


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

@@ -359,7 +359,7 @@
         }
         if (data.type === 'struct') {
           data.fields.forEach(function (field) {
-            completions.push({value: self.backTickIfNeeded(field.name), meta: 'struct', weight: DEFAULT_WEIGHTS.COLUMN})
+            completions.push({value: self.backTickIfNeeded(field.name), meta: field.type, weight: DEFAULT_WEIGHTS.COLUMN})
           });
         } else if (data.type === 'map' && (data.value && data.value.fields)) {
           data.value.fields.forEach(function (field) {

+ 1 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpec.js

@@ -22,6 +22,7 @@ define([
   'desktop/spec/autocomplete/sqlSpecCreate',
   'desktop/spec/autocomplete/sqlSpecDescribe',
   'desktop/spec/autocomplete/sqlSpecDrop',
+  'desktop/spec/autocomplete/sqlSpecError',
   'desktop/spec/autocomplete/sqlSpecLoad',
   'desktop/spec/autocomplete/sqlSpecSelect',
   'desktop/spec/autocomplete/sqlSpecShow',

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

@@ -0,0 +1,46 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// 'License'); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+define([
+  'knockout',
+  'desktop/js/autocomplete/sql',
+  'desktop/spec/autocompleterTestUtils'
+], function(ko, sql, testUtils) {
+
+  describe('sql.js Error statements', function() {
+
+    beforeAll(function () {
+      sql.yy.parseError = function (msg) {
+        throw Error(msg);
+      };
+      jasmine.addMatchers(testUtils.testDefinitionMatcher);
+    });
+
+    var assertAutoComplete = testUtils.assertAutocomplete;
+
+    it('should suggest columns for "SELECT BAABO BOOAA BLARGH, | FROM testTable"', function() {
+      assertAutoComplete({
+        beforeCursor: 'SELECT BAABO BOOAA BLARGH, ',
+        afterCursor: ' FROM testTable',
+        hasLocations: true,
+        expectedResult: {
+          lowerCase: false,
+          suggestFunctions: {},
+          suggestColumns: { table: 'testTable' }
+        }
+      });
+    });
+  });
+});

+ 1 - 3
tools/jison/hue-jison.sh

@@ -17,8 +17,6 @@
 
 echo "Make sure you install jison first (npm install jison -g)"
 echo ""
-echo "Note: There's supposed to be one conflict when generating for token 'error' (reduce by rule: SelectStatement_EDIT -> SELECT OptionalAllOrDistinct SelectList_EDIT)"
-echo ""
 echo "Generating parser..."
 
 pushd ../../desktop/core/src/desktop/static/desktop/js/autocomplete/jison
@@ -32,7 +30,7 @@ echo "%%" > sql_end.jison
 # With this all create tests will pass
 # cat sql_main.jison sql_create.jison sql_end.jison ../sql_support.js > sql.jison
 
-cat sql_main.jison sql_valueExpression.jison sql_alter.jison sql_analyze.jison sql_create.jison sql_drop.jison sql_show.jison sql_update.jison sql_use.jison sql_end.jison ../sql_support.js > sql.jison
+cat sql_main.jison sql_valueExpression.jison sql_error.jison sql_alter.jison sql_analyze.jison sql_create.jison sql_drop.jison sql_show.jison sql_update.jison sql_use.jison sql_end.jison ../sql_support.js > sql.jison
 
 jison sql.jison sql.jisonlex -m amd
 cat license.txt sql.js > ../sql.js

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików