Bläddra i källkod

HUE-9429 [editor] Extract INSERT, UPSERT and SET into separate grammar files for Impala

Johan Ahlen 5 år sedan
förälder
incheckning
7506957ace

+ 27 - 0
desktop/core/src/desktop/js/parse/jison/sql/impala/insert/cte_insert.jison

@@ -0,0 +1,27 @@
+// 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.
+
+DataManipulation
+ : CommonTableExpression InsertStatement
+ ;
+
+DataManipulation_EDIT
+ : CommonTableExpression InsertStatement_EDIT
+   {
+     parser.addCommonTableExpressions($1);
+   }
+ | CommonTableExpression_EDIT InsertStatement
+ ;

+ 103 - 0
desktop/core/src/desktop/js/parse/jison/sql/impala/insert/insert.jison

@@ -0,0 +1,103 @@
+// 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.
+
+DataManipulation
+ : InsertStatement
+ ;
+
+DataManipulation_EDIT
+ : InsertStatement_EDIT
+ ;
+
+InsertStatement
+ : InsertLeftPart OptionalShuffleOrNoShuffle SelectStatement OptionalUnions
+ | InsertLeftPart 'VALUES' RowValuesLists
+ ;
+
+InsertStatement_EDIT
+ : InsertLeftPart_EDIT
+ | InsertLeftPart OptionalShuffleOrNoShuffle 'CURSOR'
+   {
+     var keywords = $1.suggestKeywords && !$2 ? parser.createWeightedKeywords($1.suggestKeywords, 2) : [];
+     if (!$2) {
+       keywords = keywords.concat(['[NOSHUFFLE]', '[SHUFFLE]', 'SELECT', 'VALUES'])
+     } else {
+       keywords = keywords.concat(['SELECT'])
+     }
+     parser.suggestKeywords(keywords);
+   }
+ | InsertLeftPart_EDIT OptionalShuffleOrNoShuffle SelectStatement OptionalUnions
+ | InsertLeftPart OptionalShuffleOrNoShuffle SelectStatement_EDIT OptionalUnions
+ | InsertLeftPart OptionalShuffleOrNoShuffle SelectStatement OptionalUnions_EDIT
+ | InsertLeftPart_EDIT 'VALUES' RowValuesLists
+ | InsertLeftPart 'VALUES' RowValuesLists_EDIT
+ ;
+
+InsertLeftPart
+ : 'INSERT' IntoOrOverwrite OptionalTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalPartitionSpec
+   {
+     $4.owner = 'insert';
+     parser.addTablePrimary($4);
+     if (!$6) {
+       $$ = { suggestKeywords: ['PARTITION'] };
+     }
+   }
+ ;
+
+InsertLeftPart_EDIT
+ : 'INSERT' 'CURSOR'
+   {
+     parser.suggestKeywords(['INTO', 'OVERWRITE']);
+   }
+ | 'INSERT' IntoOrOverwrite OptionalTable 'CURSOR'
+   {
+     if (!$3) {
+       parser.suggestKeywords(['TABLE']);
+     }
+     parser.suggestTables();
+     parser.suggestDatabases({ appendDot: true });
+   }
+ | 'INSERT' IntoOrOverwrite OptionalTable 'CURSOR' SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalPartitionSpec
+   {
+     if (!$3) {
+       parser.suggestKeywords(['TABLE']);
+     }
+     $5.owner = 'insert';
+     parser.addTablePrimary($5);
+   }
+ | 'INSERT' IntoOrOverwrite OptionalTable SchemaQualifiedTableIdentifier_EDIT OptionalParenthesizedColumnList OptionalPartitionSpec
+ | 'INSERT' IntoOrOverwrite OptionalTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList_EDIT OptionalPartitionSpec
+   {
+     $4.owner = 'insert';
+     parser.addTablePrimary($4);
+     if (parser.yy.result.suggestColumns) {
+       parser.yy.result.suggestColumns.owner = 'insert';
+     }
+   }
+ | 'INSERT' IntoOrOverwrite OptionalTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalPartitionSpec_EDIT
+   {
+     $4.owner = 'insert';
+     parser.addTablePrimary($4);
+     if (parser.yy.result.suggestColumns) {
+       parser.yy.result.suggestColumns.owner = 'insert';
+     }
+   }
+ ;
+
+IntoOrOverwrite
+ : 'INTO'
+ | 'OVERWRITE'
+ ;

+ 51 - 0
desktop/core/src/desktop/js/parse/jison/sql/impala/insert/insert_common.jison

@@ -0,0 +1,51 @@
+// 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.
+
+OptionalTable
+ :
+ | 'TABLE'
+ ;
+
+OptionalShuffleOrNoShuffle
+ :
+ | 'SHUFFLE'
+ | 'NOSHUFFLE'
+ ;
+
+RowValuesLists
+ : ParenthesizedValueExpressionList
+ | RowValuesLists ',' ParenthesizedValueExpressionList
+ ;
+
+RowValuesLists_EDIT
+ : ParenthesizedValueExpressionList_EDIT
+ | RowValuesLists ',' ParenthesizedValueExpressionList_EDIT
+ | RowValuesLists ',' ParenthesizedValueExpressionList_EDIT ',' RowValuesLists
+ | ParenthesizedValueExpressionList_EDIT ',' RowValuesLists
+ ;
+
+ParenthesizedValueExpressionList
+ : '(' ValueExpressionList ')'
+ ;
+
+ParenthesizedValueExpressionList_EDIT
+ : '(' AnyCursor RightParenthesisOrError
+   {
+     parser.suggestFunctions();
+   }
+ | '(' ValueExpressionList_EDIT RightParenthesisOrError
+ ;
+

+ 0 - 0
desktop/core/src/desktop/js/parse/jison/sql/impala/sql_set.jison → desktop/core/src/desktop/js/parse/jison/sql/impala/set/set.jison


+ 0 - 241
desktop/core/src/desktop/js/parse/jison/sql/impala/sql_insert.jison

@@ -1,241 +0,0 @@
-// 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.
-
-DataManipulation
- : InsertStatement
- ;
-
-InsertStatement
- : InsertOrUpsertStatement
- | CommonTableExpression InsertOrUpsertStatement
- ;
-
-DataManipulation_EDIT
- : InsertOrUpsertStatement_EDIT
- | CommonTableExpression InsertOrUpsertStatement_EDIT
-   {
-     parser.addCommonTableExpressions($1);
-   }
- | CommonTableExpression_EDIT InsertOrUpsertStatement
- ;
-
-OptionalTable
- :
- | 'TABLE'
- ;
-
-SelectWithoutTableExpression
- : 'SELECT' OptionalAllOrDistinct OptionalStraightJoin SelectList  -> { selectList: $4 }
- ;
-
-SelectWithoutTableExpression_EDIT
- : 'SELECT' OptionalAllOrDistinct OptionalStraightJoin SelectList 'CURSOR'
-   {
-     $$ = $4;
-     $$.cursorAtEnd = true;
-   }
- | 'SELECT' OptionalAllOrDistinct OptionalStraightJoin SelectList_EDIT
-   {
-     parser.selectListNoTableSuggest($4, $2);
-   }
- | 'SELECT' OptionalAllOrDistinct OptionalStraightJoin 'CURSOR'
-   {
-     var keywords = parser.getSelectListKeywords();
-     if (!$2 || $2 === 'ALL') {
-       parser.suggestAggregateFunctions();
-       parser.suggestAnalyticFunctions();
-     }
-     if (!$3 && !$2) {
-       keywords.push({ value: 'ALL', weight: 2 });
-       keywords.push({ value: 'DISTINCT', weight: 2 });
-     }
-     if (!$3) {
-       keywords.push({ value: 'STRAIGHT_JOIN', weight: 1 });
-     }
-     parser.suggestKeywords(keywords);
-     parser.suggestFunctions();
-     parser.suggestColumns();
-   }
- ;
-
-InsertOrUpsertStatement
- : InsertOrUpsertStatementWithoutCTE
- ;
-
-InsertOrUpsertStatement_EDIT
- : InsertOrUpsertStatementWithoutCTE_EDIT
- ;
-
-InsertOrUpsertStatementWithoutCTE
- : InsertOrUpsertLeftPart OptionalShuffleOrNoShuffle SelectStatement OptionalUnions
- | InsertOrUpsertLeftPart 'VALUES' RowValuesLists
- ;
-
-InsertOrUpsertStatementWithoutCTE_EDIT
- : InsertOrUpsertLeftPart_EDIT
- | InsertOrUpsertLeftPart OptionalShuffleOrNoShuffle 'CURSOR'
-   {
-     var keywords = $1.suggestKeywords && !$2 ? parser.createWeightedKeywords($1.suggestKeywords, 2) : [];
-     if (!$2) {
-       keywords = keywords.concat(['[NOSHUFFLE]', '[SHUFFLE]', 'SELECT', 'VALUES'])
-     } else {
-       keywords = keywords.concat(['SELECT'])
-     }
-     parser.suggestKeywords(keywords);
-   }
- | InsertOrUpsertLeftPart_EDIT OptionalShuffleOrNoShuffle SelectStatement OptionalUnions
- | InsertOrUpsertLeftPart OptionalShuffleOrNoShuffle SelectStatement_EDIT OptionalUnions
- | InsertOrUpsertLeftPart OptionalShuffleOrNoShuffle SelectStatement OptionalUnions_EDIT
- | InsertOrUpsertLeftPart_EDIT 'VALUES' RowValuesLists
- | InsertOrUpsertLeftPart 'VALUES' RowValuesLists_EDIT
- ;
-
-InsertOrUpsertLeftPart
- : UpsertStatementLeftPart
- | InsertLeftPart
- ;
-
-InsertOrUpsertLeftPart_EDIT
- : UpsertStatementLeftPart_EDIT
- | InsertLeftPart_EDIT
- ;
-
-UpsertStatementLeftPart
- : 'UPSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList
-   {
-     $4.owner = 'upsert';
-     parser.addTablePrimary($4);
-   }
- ;
-
-UpsertStatementLeftPart_EDIT
- : 'UPSERT' 'CURSOR'
-   {
-     parser.suggestKeywords(['INTO']);
-   }
- | 'UPSERT' 'INTO' OptionalTable 'CURSOR'
-   {
-     if (!$3) {
-       parser.suggestKeywords(['TABLE']);
-     }
-     parser.suggestTables();
-     parser.suggestDatabases({ appendDot: true });
-   }
- | 'UPSERT' 'INTO' OptionalTable 'CURSOR' SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList
-   {
-     if (!$3) {
-       parser.suggestKeywords(['TABLE']);
-     }
-     $5.owner = 'upsert';
-     parser.addTablePrimary($5);
-   }
- | 'UPSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT OptionalParenthesizedColumnList
- | 'UPSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList_EDIT
-   {
-     $4.owner = 'upsert';
-     parser.addTablePrimary($4);
-     if (parser.yy.result.suggestColumns) {
-       parser.yy.result.suggestColumns.owner = 'upsert';
-     }
-   }
- ;
-
-InsertLeftPart
- : 'INSERT' IntoOrOverwrite OptionalTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalPartitionSpec
-   {
-     $4.owner = 'insert';
-     parser.addTablePrimary($4);
-     if (!$6) {
-       $$ = { suggestKeywords: ['PARTITION'] };
-     }
-   }
- ;
-
-InsertLeftPart_EDIT
- : 'INSERT' 'CURSOR'
-   {
-     parser.suggestKeywords(['INTO', 'OVERWRITE']);
-   }
- | 'INSERT' IntoOrOverwrite OptionalTable 'CURSOR'
-   {
-     if (!$3) {
-       parser.suggestKeywords(['TABLE']);
-     }
-     parser.suggestTables();
-     parser.suggestDatabases({ appendDot: true });
-   }
- | 'INSERT' IntoOrOverwrite OptionalTable 'CURSOR' SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalPartitionSpec
-   {
-     if (!$3) {
-       parser.suggestKeywords(['TABLE']);
-     }
-     $5.owner = 'insert';
-     parser.addTablePrimary($5);
-   }
- | 'INSERT' IntoOrOverwrite OptionalTable SchemaQualifiedTableIdentifier_EDIT OptionalParenthesizedColumnList OptionalPartitionSpec
- | 'INSERT' IntoOrOverwrite OptionalTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList_EDIT OptionalPartitionSpec
-   {
-     $4.owner = 'insert';
-     parser.addTablePrimary($4);
-     if (parser.yy.result.suggestColumns) {
-       parser.yy.result.suggestColumns.owner = 'insert';
-     }
-   }
- | 'INSERT' IntoOrOverwrite OptionalTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList OptionalPartitionSpec_EDIT
-   {
-     $4.owner = 'insert';
-     parser.addTablePrimary($4);
-     if (parser.yy.result.suggestColumns) {
-       parser.yy.result.suggestColumns.owner = 'insert';
-     }
-   }
- ;
-
-IntoOrOverwrite
- : 'INTO'
- | 'OVERWRITE'
- ;
-
-OptionalShuffleOrNoShuffle
- :
- | 'SHUFFLE'
- | 'NOSHUFFLE'
- ;
-
-RowValuesLists
- : ParenthesizedValueExpressionList
- | RowValuesLists ',' ParenthesizedValueExpressionList
- ;
-
-RowValuesLists_EDIT
- : ParenthesizedValueExpressionList_EDIT
- | RowValuesLists ',' ParenthesizedValueExpressionList_EDIT
- | RowValuesLists ',' ParenthesizedValueExpressionList_EDIT ',' RowValuesLists
- | ParenthesizedValueExpressionList_EDIT ',' RowValuesLists
- ;
-
-ParenthesizedValueExpressionList
- : '(' ValueExpressionList ')'
- ;
-
-ParenthesizedValueExpressionList_EDIT
- : '(' AnyCursor RightParenthesisOrError
-   {
-     parser.suggestFunctions();
-   }
- | '(' ValueExpressionList_EDIT RightParenthesisOrError
- ;
-

+ 12 - 4
desktop/core/src/desktop/js/parse/jison/sql/impala/structure.json

@@ -28,17 +28,21 @@
     "grant/grant_common.jison",
     "grant/grant_on.jison",
     "grant/grant_role.jison",
+    "insert/cte_insert.jison",
+    "insert/insert.jison",
+    "insert/insert_common.jison",
     "invalidate/invalidate_metadata.jison",
     "load/load_data.jison",
     "refresh/refresh.jison",
     "revoke/revoke_common.jison",
     "revoke/revoke_on.jison",
     "revoke/revoke_role.jison",
+    "set/set.jison",
     "truncate/truncate_table.jison",
+    "upsert/cte_upsert.jison",
+    "upsert/upsert.jison",
     "sql_error.jison",
-    "sql_insert.jison",
     "sql_main.jison",
-    "sql_set.jison",
     "sql_show.jison",
     "sql_udf.jison",
     "sql_update.jison",
@@ -74,16 +78,20 @@
     "grant/grant_common.jison",
     "grant/grant_on.jison",
     "grant/grant_role.jison",
+    "insert/cte_insert.jison",
+    "insert/insert.jison",
+    "insert/insert_common.jison",
     "invalidate/invalidate_metadata.jison",
     "load/load_data.jison",
     "refresh/refresh.jison",
     "revoke/revoke_common.jison",
     "revoke/revoke_on.jison",
     "revoke/revoke_role.jison",
+    "set/set.jison",
     "truncate/truncate_table.jison",
-    "sql_insert.jison",
+    "upsert/cte_upsert.jison",
+    "upsert/upsert.jison",
     "sql_main.jison",
-    "sql_set.jison",
     "sql_show.jison",
     "sql_udf.jison",
     "sql_update.jison",

+ 27 - 0
desktop/core/src/desktop/js/parse/jison/sql/impala/upsert/cte_upsert.jison

@@ -0,0 +1,27 @@
+// 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.
+
+DataManipulation
+ : CommonTableExpression UpsertStatement
+ ;
+
+DataManipulation_EDIT
+ : CommonTableExpression UpsertStatement_EDIT
+   {
+     parser.addCommonTableExpressions($1);
+   }
+ | CommonTableExpression_EDIT UpsertStatement
+ ;

+ 87 - 0
desktop/core/src/desktop/js/parse/jison/sql/impala/upsert/upsert.jison

@@ -0,0 +1,87 @@
+// 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.
+
+DataManipulation
+ : UpsertStatement
+ ;
+
+DataManipulation_EDIT
+ : UpsertStatement_EDIT
+ ;
+
+UpsertStatement
+ : UpsertStatementLeftPart OptionalShuffleOrNoShuffle SelectStatement OptionalUnions
+ | UpsertStatementLeftPart 'VALUES' RowValuesLists
+ ;
+
+UpsertStatement_EDIT
+ : UpsertStatementLeftPart_EDIT
+ | UpsertStatementLeftPart OptionalShuffleOrNoShuffle 'CURSOR'
+   {
+     var keywords = $1.suggestKeywords && !$2 ? parser.createWeightedKeywords($1.suggestKeywords, 2) : [];
+     if (!$2) {
+       keywords = keywords.concat(['[NOSHUFFLE]', '[SHUFFLE]', 'SELECT', 'VALUES'])
+     } else {
+       keywords = keywords.concat(['SELECT'])
+     }
+     parser.suggestKeywords(keywords);
+   }
+ | UpsertStatementLeftPart_EDIT OptionalShuffleOrNoShuffle SelectStatement OptionalUnions
+ | UpsertStatementLeftPart OptionalShuffleOrNoShuffle SelectStatement_EDIT OptionalUnions
+ | UpsertStatementLeftPart OptionalShuffleOrNoShuffle SelectStatement OptionalUnions_EDIT
+ | UpsertStatementLeftPart_EDIT 'VALUES' RowValuesLists
+ | UpsertStatementLeftPart 'VALUES' RowValuesLists_EDIT
+ ;
+
+UpsertStatementLeftPart
+ : 'UPSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList
+   {
+     $4.owner = 'upsert';
+     parser.addTablePrimary($4);
+   }
+ ;
+
+UpsertStatementLeftPart_EDIT
+ : 'UPSERT' 'CURSOR'
+   {
+     parser.suggestKeywords(['INTO']);
+   }
+ | 'UPSERT' 'INTO' OptionalTable 'CURSOR'
+   {
+     if (!$3) {
+       parser.suggestKeywords(['TABLE']);
+     }
+     parser.suggestTables();
+     parser.suggestDatabases({ appendDot: true });
+   }
+ | 'UPSERT' 'INTO' OptionalTable 'CURSOR' SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList
+   {
+     if (!$3) {
+       parser.suggestKeywords(['TABLE']);
+     }
+     $5.owner = 'upsert';
+     parser.addTablePrimary($5);
+   }
+ | 'UPSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier_EDIT OptionalParenthesizedColumnList
+ | 'UPSERT' 'INTO' OptionalTable SchemaQualifiedTableIdentifier OptionalParenthesizedColumnList_EDIT
+   {
+     $4.owner = 'upsert';
+     parser.addTablePrimary($4);
+     if (parser.yy.result.suggestColumns) {
+       parser.yy.result.suggestColumns.owner = 'upsert';
+     }
+   }
+ ;

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/impala/impalaAutocompleteParser.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/impala/impalaSyntaxParser.js


Vissa filer visades inte eftersom för många filer har ändrats