Browse Source

HUE-9429 [editor] Extract and split DESCRIBE, INSERT, MERGE, SET and UPDATE for Hive and Presto

Johan Ahlen 5 years ago
parent
commit
07f1909a8f

+ 80 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/describe/describe.jison

@@ -0,0 +1,80 @@
+// 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.
+
+DataDefinition
+ : DescribeStatement
+ ;
+
+DataDefinition_EDIT
+ : DescribeStatement_EDIT
+ ;
+
+DescribeStatement
+ : 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain OptionalPartitionSpec
+   {
+     parser.addTablePrimary($3);
+     parser.addColumnLocation(@4, $4);
+   }
+ | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier OptionalPartitionSpec
+   {
+     parser.addTablePrimary($3);
+   }
+ ;
+
+DescribeStatement_EDIT
+ : 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
+ | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain_EDIT OptionalPartitionSpec
+   {
+     parser.addTablePrimary($3);
+   }
+ | 'DESCRIBE' OptionalExtendedOrFormatted 'CURSOR' SchemaQualifiedTableIdentifier DerivedColumnChain OptionalPartitionSpec
+   {
+     if (!$2) {
+       parser.suggestKeywords(['EXTENDED', 'FORMATTED']);
+     }
+   }
+ | 'DESCRIBE' OptionalExtendedOrFormatted 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
+   {
+     if (!$2) {
+       parser.suggestKeywords(['EXTENDED', 'FORMATTED']);
+     }
+   }
+ | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier 'CURSOR' OptionalPartitionSpec
+   {
+     parser.addTablePrimary($3);
+     parser.suggestColumns();
+     if (!$5) {
+       parser.suggestKeywords(['PARTITION']);
+     }
+   }
+ | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain 'CURSOR' OptionalPartitionSpec
+   {
+     if (!$6) {
+       parser.suggestKeywords(['PARTITION']);
+     }
+   }
+ | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain OptionalPartitionSpec_EDIT
+ | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
+
+ | 'DESCRIBE' OptionalExtendedOrFormatted 'CURSOR'
+   {
+     if (!$2) {
+       parser.suggestKeywords(['DATABASE', 'EXTENDED', 'FORMATTED', 'FUNCTION', 'SCHEMA']);
+     }
+     parser.suggestTables();
+     parser.suggestDatabases({ appendDot: true });
+    }
+ ;

+ 45 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/describe/describe_database.jison

@@ -0,0 +1,45 @@
+// 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.
+
+DataDefinition
+ : DescribeDatabaseStatement
+ ;
+
+DataDefinition_EDIT
+ : DescribeDatabaseStatement_EDIT
+ ;
+
+DescribeDatabaseStatement
+ : 'DESCRIBE' DatabaseOrSchema OptionalExtended DatabaseIdentifier
+   {
+     parser.addDatabaseLocation(@4, [{ name: $4 }]);
+   }
+ ;
+
+DescribeDatabaseStatement_EDIT
+ : 'DESCRIBE' DatabaseOrSchema OptionalExtended DatabaseIdentifier_EDIT
+   {
+     if (!$3) {
+       parser.suggestKeywords(['EXTENDED']);
+     }
+   }
+ | 'DESCRIBE' DatabaseOrSchema OptionalExtended 'CURSOR' DatabaseIdentifier
+   {
+     if (!$3) {
+       parser.suggestKeywords(['EXTENDED']);
+     }
+   }
+ ;

+ 42 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/describe/describe_function.jison

@@ -0,0 +1,42 @@
+// 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.
+
+DataDefinition
+ : DescribeFunctionStatement
+ ;
+
+DataDefinition_EDIT
+ : DescribeFunctionStatement_EDIT
+ ;
+
+DescribeFunctionStatement
+ : 'DESCRIBE' 'FUNCTION' OptionalExtended RegularIdentifier
+ ;
+
+DescribeFunctionStatement_EDIT
+ : 'DESCRIBE' 'FUNCTION' OptionalExtended 'CURSOR'
+   {
+     if (!$3) {
+       parser.suggestKeywords(['EXTENDED']);
+     }
+   }
+ | 'DESCRIBE' 'FUNCTION' OptionalExtended 'CURSOR' RegularIdentifier
+   {
+     if (!$3) {
+       parser.suggestKeywords(['EXTENDED']);
+     }
+   }
+ ;

+ 3 - 240
desktop/core/src/desktop/js/parse/jison/sql/hive/sql_insert.jison → desktop/core/src/desktop/js/parse/jison/sql/hive/insert/insert.jison

@@ -16,18 +16,10 @@
 
 DataManipulation
  : InsertStatement
- | CommonTableExpression InsertStatement
- | MergeStatement
  ;
 
 DataManipulation_EDIT
  : InsertStatement_EDIT
- | CommonTableExpression InsertStatement_EDIT
-   {
-     parser.addCommonTableExpressions($1);
-   }
- | CommonTableExpression_EDIT InsertStatement
- | MergeStatement_EDIT
  ;
 
 InsertStatement
@@ -173,10 +165,10 @@ InsertWithoutQuery_EDIT
      parser.suggestKeywords(['DIRECTORY']);
    }
  | 'INSERT' 'OVERWRITE' 'LOCAL' 'DIRECTORY' HdfsPath_EDIT OptionalInsertRowFormat OptionalStoredAs
- | 'INSERT' 'OVERWRITE' 'LOCAL' 'DIRECTORY' HdfsPath OptionalInsertRowFormat_EDIT OptionalStoredAs
+ | 'INSERT' 'OVERWRITE' 'LOCAL' 'DIRECTORY' HdfsPath InsertRowFormat_EDIT OptionalStoredAs
  | 'INSERT' 'OVERWRITE' 'LOCAL' 'DIRECTORY' HdfsPath OptionalInsertRowFormat OptionalStoredAs_EDIT
  | 'INSERT' 'OVERWRITE_DIRECTORY' HdfsPath_EDIT OptionalInsertRowFormat OptionalStoredAs  // DIRECTORY is a non-reserved keyword
- | 'INSERT' 'OVERWRITE_DIRECTORY' HdfsPath OptionalInsertRowFormat_EDIT OptionalStoredAs
+ | 'INSERT' 'OVERWRITE_DIRECTORY' HdfsPath InsertRowFormat_EDIT OptionalStoredAs
  | 'INSERT' 'OVERWRITE_DIRECTORY' HdfsPath OptionalInsertRowFormat OptionalStoredAs_EDIT
  | 'INSERT' 'INTO' OptionalTable 'CURSOR'
    {
@@ -253,15 +245,6 @@ GenericInsert_EDIT
  | InsertWithoutQuery SelectWithoutTableExpression OptionalSelectConditions_EDIT
  ;
 
-InsertValuesList
- : ParenthesizedRowValuesList
- | InsertValuesList ',' ParenthesizedRowValuesList
- ;
-
-ParenthesizedRowValuesList
- : '(' InValueList ')'
- ;
-
 OptionalTable
  :
  | 'TABLE'
@@ -272,7 +255,7 @@ OptionalInsertRowFormat
  | 'ROW' 'FORMAT' DelimitedRowFormat
  ;
 
-OptionalInsertRowFormat_EDIT
+InsertRowFormat_EDIT
  : 'ROW' 'CURSOR'
    {
      parser.suggestKeywords(['FORMAT DELIMITED']);
@@ -314,223 +297,3 @@ SelectWithoutTableExpression_EDIT
      parser.suggestColumns();
    }
  ;
-
-MergeStatement
- : MergeStatementLeftPart 'ON' ValueExpression WhenList
- ;
-
-MergeStatement_EDIT
- : MergeStatementLeftPart_EDIT
- | MergeStatementLeftPart 'CURSOR'
-   {
-     parser.suggestKeywords(['ON']);
-   }
- | MergeStatementLeftPart 'ON' 'CURSOR'
-   {
-     parser.valueExpressionSuggest();
-   }
- | MergeStatementLeftPart 'ON' ValueExpression_EDIT
- | MergeStatementLeftPart 'ON' ValueExpression 'CURSOR'
-   {
-     parser.suggestValueExpressionKeywords($3, [{ value: 'WHEN', weight: 2 }]);
-   }
- | MergeStatementLeftPart 'ON' ValueExpression WhenList_EDIT
- ;
-
-MergeStatementLeftPart
- : 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'USING' MergeSource 'AS' RegularIdentifier
-   {
-     $3.alias = $5;
-     parser.addTablePrimary($3);
-     if ($7.subQuery) {
-       parser.addTablePrimary({ subQueryAlias: $9 });
-     } else {
-       $7.alias = $9;
-     }
-   }
- ;
-
-MergeStatementLeftPart_EDIT
- : 'MERGE' 'CURSOR'
-   {
-     parser.suggestKeywords(['INTO']);
-   }
- | 'MERGE' 'INTO' 'CURSOR'
-   {
-     parser.suggestDatabases({ appendDot: true });
-     parser.suggestTables();
-   }
- | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier_EDIT
- | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'CURSOR'
-   {
-     parser.addTablePrimary($3);
-     parser.suggestKeywords(['AS T USING']);
-   }
- | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' 'CURSOR'
-   {
-     parser.addTablePrimary($3);
-     parser.suggestKeywords(['T USING']);
-   }
- | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'CURSOR'
-   {
-     $3.alias = $5;
-     parser.addTablePrimary($3);
-     parser.suggestKeywords(['USING']);
-   }
- | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'USING' 'CURSOR'
-   {
-     $3.alias = $5;
-     parser.addTablePrimary($3);
-     parser.suggestDatabases({ appendDot: true });
-     parser.suggestTables();
-   }
- | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'USING' MergeSource_EDIT
-   {
-     $3.alias = $5;
-     parser.addTablePrimary($3);
-   }
- | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'USING' MergeSource 'CURSOR'
-   {
-     $3.alias = $5;
-     parser.addTablePrimary($3);
-     parser.suggestKeywords(['AS S ON']);
-   }
- | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'USING' MergeSource 'AS' 'CURSOR'
-   {
-     $3.alias = $5;
-     parser.addTablePrimary($3);
-     parser.suggestKeywords(['S ON']);
-   }
- ;
-
-MergeSource
- : '(' TableSubQueryInner ')'  -> $2
- | SchemaQualifiedTableIdentifier
-   {
-     parser.addTablePrimary($1);
-   }
- ;
-
-MergeSource_EDIT
- : '(' 'CURSOR' RightParenthesisOrError
-   {
-     parser.suggestKeywords(['SELECT']);
-   }
- | '(' TableSubQueryInner_EDIT RightParenthesisOrError
- | SchemaQualifiedTableIdentifier_EDIT
- ;
-
-WhenList
- : WhenClause
- | WhenClause WhenClause
- | WhenClause WhenClause WhenClause
- ;
-
-WhenList_EDIT
- : WhenClause_EDIT
-   {
-     if ($1.suggestThenKeywords) {
-       parser.suggestKeywords(['DELETE', 'INSERT VALUES', 'UPDATE SET']);
-     }
-   }
- | WhenClause 'CURSOR'
-   {
-     if (!$1.notPresent) {
-       parser.suggestKeywords(['WHEN']);
-     }
-   }
- | WhenClause WhenClause_EDIT
-  {
-     if (!$1.notPresent && $2.suggestThenKeywords) {
-       var keywords = [];
-       if (!$1.isDelete) {
-         keywords.push('DELETE');
-       }
-       if (!$1.isInsert) {
-         keywords.push('INSERT VALUES');
-       }
-       if (!$1.isUpdate) {
-         keywords.push('UPDATE SET');
-       }
-       parser.suggestKeywords(keywords);
-     }
-   }
- | WhenClause WhenClause 'CURSOR'
-   {
-     if (!$2.notPresent) {
-       parser.suggestKeywords(['WHEN']);
-     }
-   }
- | WhenClause WhenClause WhenClause_EDIT
-   {
-     if (!$2.notPresent && $3.suggestThenKeywords) {
-       var keywords = [];
-       if (!$1.isDelete && !$2.isDelete) {
-         keywords.push('DELETE');
-       }
-       if (!$1.isInsert && !$2.isInsert) {
-         keywords.push('INSERT VALUES');
-       }
-       if (!$1.isUpdate && !$2.isUpdate) {
-         keywords.push('UPDATE SET');
-       }
-       parser.suggestKeywords(keywords);
-     }
-   }
- ;
-
-WhenClause
- : 'WHEN' OptionalNot 'MATCHED' OptionalMatchCondition 'THEN' UpdateDeleteOrInsert  -> { notPresent: !!$2, isDelete: $6.isDelete, isInsert: $6.isInsert, isUpdate: $6.isUpdate }
- ;
-
-WhenClause_EDIT
- : 'WHEN' OptionalNot 'CURSOR'
-   {
-     if (!$2) {
-       parser.suggestKeywords(['NOT MATCHED', 'MATCHED']);
-     } else {
-       parser.suggestKeywords(['MATCHED']);
-     }
-   }
- | 'WHEN' OptionalNot 'MATCHED' OptionalMatchCondition 'CURSOR'
-   {
-     if (!$4) {
-       parser.suggestKeywords(['AND', 'THEN']);
-     } else {
-       parser.suggestValueExpressionKeywords($4, [{ value: 'THEN', weight: 2 }]);
-     }
-   }
- | 'WHEN' OptionalNot 'MATCHED' MatchCondition_EDIT
- | 'WHEN' OptionalNot 'MATCHED' OptionalMatchCondition 'THEN' 'CURSOR' -> { suggestThenKeywords: true }
- | 'WHEN' OptionalNot 'MATCHED' OptionalMatchCondition 'THEN' UpdateDeleteOrInsert_EDIT
- ;
-
-OptionalMatchCondition
- :
- | 'AND' ValueExpression -> $2
- ;
-
-MatchCondition_EDIT
- : 'AND' 'CURSOR'
-   {
-     parser.valueExpressionSuggest();
-   }
- ;
-
-UpdateDeleteOrInsert
- : 'UPDATE' 'SET' SetClauseList        -> { isUpdate: true }
- | 'DELETE'                            -> { isDelete: true }
- | 'INSERT' 'VALUES' InsertValuesList  -> { isInsert: true }
- ;
-
-UpdateDeleteOrInsert_EDIT
- : 'UPDATE' 'CURSOR'
-   {
-     parser.suggestKeywords(['SET']);
-   }
- | 'UPDATE' 'SET' SetClauseList_EDIT
- | 'INSERT' 'CURSOR'
-   {
-     parser.suggestKeywords(['VALUES']);
-   }
- ;

+ 24 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/insert/insert_common.jison

@@ -0,0 +1,24 @@
+// 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.
+
+InsertValuesList
+ : ParenthesizedRowValuesList
+ | InsertValuesList ',' ParenthesizedRowValuesList
+ ;
+
+ParenthesizedRowValuesList
+ : '(' InValueList ')'
+ ;

+ 243 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/merge/merge.jison

@@ -0,0 +1,243 @@
+// 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
+ : MergeStatement
+ ;
+
+DataManipulation_EDIT
+ : MergeStatement_EDIT
+ ;
+
+MergeStatement
+ : MergeStatementLeftPart 'ON' ValueExpression WhenList
+ ;
+
+MergeStatement_EDIT
+ : MergeStatementLeftPart_EDIT
+ | MergeStatementLeftPart 'CURSOR'
+   {
+     parser.suggestKeywords(['ON']);
+   }
+ | MergeStatementLeftPart 'ON' 'CURSOR'
+   {
+     parser.valueExpressionSuggest();
+   }
+ | MergeStatementLeftPart 'ON' ValueExpression_EDIT
+ | MergeStatementLeftPart 'ON' ValueExpression 'CURSOR'
+   {
+     parser.suggestValueExpressionKeywords($3, [{ value: 'WHEN', weight: 2 }]);
+   }
+ | MergeStatementLeftPart 'ON' ValueExpression WhenList_EDIT
+ ;
+
+MergeStatementLeftPart
+ : 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'USING' MergeSource 'AS' RegularIdentifier
+   {
+     $3.alias = $5;
+     parser.addTablePrimary($3);
+     if ($7.subQuery) {
+       parser.addTablePrimary({ subQueryAlias: $9 });
+     } else {
+       $7.alias = $9;
+     }
+   }
+ ;
+
+MergeStatementLeftPart_EDIT
+ : 'MERGE' 'CURSOR'
+   {
+     parser.suggestKeywords(['INTO']);
+   }
+ | 'MERGE' 'INTO' 'CURSOR'
+   {
+     parser.suggestDatabases({ appendDot: true });
+     parser.suggestTables();
+   }
+ | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier_EDIT
+ | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'CURSOR'
+   {
+     parser.addTablePrimary($3);
+     parser.suggestKeywords(['AS T USING']);
+   }
+ | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' 'CURSOR'
+   {
+     parser.addTablePrimary($3);
+     parser.suggestKeywords(['T USING']);
+   }
+ | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'CURSOR'
+   {
+     $3.alias = $5;
+     parser.addTablePrimary($3);
+     parser.suggestKeywords(['USING']);
+   }
+ | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'USING' 'CURSOR'
+   {
+     $3.alias = $5;
+     parser.addTablePrimary($3);
+     parser.suggestDatabases({ appendDot: true });
+     parser.suggestTables();
+   }
+ | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'USING' MergeSource_EDIT
+   {
+     $3.alias = $5;
+     parser.addTablePrimary($3);
+   }
+ | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'USING' MergeSource 'CURSOR'
+   {
+     $3.alias = $5;
+     parser.addTablePrimary($3);
+     parser.suggestKeywords(['AS S ON']);
+   }
+ | 'MERGE' 'INTO' SchemaQualifiedTableIdentifier 'AS' RegularIdentifier 'USING' MergeSource 'AS' 'CURSOR'
+   {
+     $3.alias = $5;
+     parser.addTablePrimary($3);
+     parser.suggestKeywords(['S ON']);
+   }
+ ;
+
+MergeSource
+ : '(' TableSubQueryInner ')'  -> $2
+ | SchemaQualifiedTableIdentifier
+   {
+     parser.addTablePrimary($1);
+   }
+ ;
+
+MergeSource_EDIT
+ : '(' 'CURSOR' RightParenthesisOrError
+   {
+     parser.suggestKeywords(['SELECT']);
+   }
+ | '(' TableSubQueryInner_EDIT RightParenthesisOrError
+ | SchemaQualifiedTableIdentifier_EDIT
+ ;
+
+WhenList
+ : WhenClause
+ | WhenClause WhenClause
+ | WhenClause WhenClause WhenClause
+ ;
+
+WhenList_EDIT
+ : WhenClause_EDIT
+   {
+     if ($1.suggestThenKeywords) {
+       parser.suggestKeywords(['DELETE', 'INSERT VALUES', 'UPDATE SET']);
+     }
+   }
+ | WhenClause 'CURSOR'
+   {
+     if (!$1.notPresent) {
+       parser.suggestKeywords(['WHEN']);
+     }
+   }
+ | WhenClause WhenClause_EDIT
+  {
+     if (!$1.notPresent && $2.suggestThenKeywords) {
+       var keywords = [];
+       if (!$1.isDelete) {
+         keywords.push('DELETE');
+       }
+       if (!$1.isInsert) {
+         keywords.push('INSERT VALUES');
+       }
+       if (!$1.isUpdate) {
+         keywords.push('UPDATE SET');
+       }
+       parser.suggestKeywords(keywords);
+     }
+   }
+ | WhenClause WhenClause 'CURSOR'
+   {
+     if (!$2.notPresent) {
+       parser.suggestKeywords(['WHEN']);
+     }
+   }
+ | WhenClause WhenClause WhenClause_EDIT
+   {
+     if (!$2.notPresent && $3.suggestThenKeywords) {
+       var keywords = [];
+       if (!$1.isDelete && !$2.isDelete) {
+         keywords.push('DELETE');
+       }
+       if (!$1.isInsert && !$2.isInsert) {
+         keywords.push('INSERT VALUES');
+       }
+       if (!$1.isUpdate && !$2.isUpdate) {
+         keywords.push('UPDATE SET');
+       }
+       parser.suggestKeywords(keywords);
+     }
+   }
+ ;
+
+WhenClause
+ : 'WHEN' OptionalNot 'MATCHED' OptionalMatchCondition 'THEN' UpdateDeleteOrInsert  -> { notPresent: !!$2, isDelete: $6.isDelete, isInsert: $6.isInsert, isUpdate: $6.isUpdate }
+ ;
+
+WhenClause_EDIT
+ : 'WHEN' OptionalNot 'CURSOR'
+   {
+     if (!$2) {
+       parser.suggestKeywords(['NOT MATCHED', 'MATCHED']);
+     } else {
+       parser.suggestKeywords(['MATCHED']);
+     }
+   }
+ | 'WHEN' OptionalNot 'MATCHED' OptionalMatchCondition 'CURSOR'
+   {
+     if (!$4) {
+       parser.suggestKeywords(['AND', 'THEN']);
+     } else {
+       parser.suggestValueExpressionKeywords($4, [{ value: 'THEN', weight: 2 }]);
+     }
+   }
+ | 'WHEN' OptionalNot 'MATCHED' MatchCondition_EDIT
+ | 'WHEN' OptionalNot 'MATCHED' OptionalMatchCondition 'THEN' 'CURSOR' -> { suggestThenKeywords: true }
+ | 'WHEN' OptionalNot 'MATCHED' OptionalMatchCondition 'THEN' UpdateDeleteOrInsert_EDIT
+ ;
+
+OptionalMatchCondition
+ :
+ | 'AND' ValueExpression -> $2
+ ;
+
+MatchCondition_EDIT
+ : 'AND' 'CURSOR'
+   {
+     parser.valueExpressionSuggest();
+   }
+ ;
+
+UpdateDeleteOrInsert
+ : 'UPDATE' 'SET' SetClauseList        -> { isUpdate: true }
+ | 'DELETE'                            -> { isDelete: true }
+ | 'INSERT' 'VALUES' InsertValuesList  -> { isInsert: true }
+ ;
+
+UpdateDeleteOrInsert_EDIT
+ : 'UPDATE' 'CURSOR'
+   {
+     parser.suggestKeywords(['SET']);
+   }
+ | 'UPDATE' 'SET' SetClauseList_EDIT
+ | 'INSERT' 'CURSOR'
+   {
+     parser.suggestKeywords(['VALUES']);
+   }
+ ;

+ 23 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/set/set_common.jison

@@ -0,0 +1,23 @@
+// 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.
+
+DataDefinition_EDIT
+ : 'SET' 'CURSOR'
+   {
+     parser.suggestSetOptions();
+     parser.suggestKeywords(['ROLE']);
+   }
+ ;

+ 0 - 26
desktop/core/src/desktop/js/parse/jison/sql/hive/sql_set.jison → desktop/core/src/desktop/js/parse/jison/sql/hive/set/set_role.jison

@@ -16,36 +16,10 @@
 
 DataDefinition
  : SetRoleStatement
- | SetSpecification
  ;
 
 DataDefinition_EDIT
  : SetRoleStatement_EDIT
- | 'SET' 'CURSOR'
-   {
-     parser.suggestSetOptions();
-     parser.suggestKeywords(['ROLE']);
-   }
- ;
-
-SetSpecification
- : 'SET' SetOption '=' SetValue
- | 'SET' 'ALL'
- ;
-
-SetOption
- : RegularIdentifier
- | SetOption '.' RegularIdentifier
- ;
-
-SetValue
- : RegularIdentifier
- | SignedInteger
- | SignedInteger RegularIdentifier
- | QuotedValue
- | 'TRUE'
- | 'FALSE'
- | 'NULL'
  ;
 
 SetRoleStatement

+ 0 - 96
desktop/core/src/desktop/js/parse/jison/sql/hive/sql_main.jison

@@ -497,14 +497,6 @@ NonStartingToken
  | '~'
  ;
 
-DataDefinition
- : DescribeStatement
- ;
-
-DataDefinition_EDIT
- : DescribeStatement_EDIT
- ;
-
 // ===================================== Commonly used constructs =====================================
 
 Commas
@@ -1137,94 +1129,6 @@ OptionalTypePrecision
  | '(' 'UNSIGNED_INTEGER' ',' 'UNSIGNED_INTEGER' ')'
  ;
 
-// ===================================== DESCRIBE statement =====================================
-
-DescribeStatement
- : 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain OptionalPartitionSpec
-   {
-     parser.addTablePrimary($3);
-     parser.addColumnLocation(@4, $4);
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier OptionalPartitionSpec
-   {
-     parser.addTablePrimary($3);
-   }
- | 'DESCRIBE' DatabaseOrSchema OptionalExtended DatabaseIdentifier
-   {
-     parser.addDatabaseLocation(@4, [{ name: $4 }]);
-   }
- | 'DESCRIBE' 'FUNCTION' OptionalExtended RegularIdentifier
- ;
-
-DescribeStatement_EDIT
- : 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain_EDIT OptionalPartitionSpec
-   {
-     parser.addTablePrimary($3);
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted 'CURSOR' SchemaQualifiedTableIdentifier DerivedColumnChain OptionalPartitionSpec
-   {
-     if (!$2) {
-       parser.suggestKeywords(['EXTENDED', 'FORMATTED']);
-     }
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
-   {
-     if (!$2) {
-       parser.suggestKeywords(['EXTENDED', 'FORMATTED']);
-     }
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier 'CURSOR' OptionalPartitionSpec
-   {
-     parser.addTablePrimary($3);
-     parser.suggestColumns();
-     if (!$5) {
-       parser.suggestKeywords(['PARTITION']);
-     }
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain 'CURSOR' OptionalPartitionSpec
-   {
-     if (!$6) {
-       parser.suggestKeywords(['PARTITION']);
-     }
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain OptionalPartitionSpec_EDIT
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
-
- | 'DESCRIBE' OptionalExtendedOrFormatted 'CURSOR'
-   {
-     if (!$2) {
-       parser.suggestKeywords(['DATABASE', 'EXTENDED', 'FORMATTED', 'FUNCTION', 'SCHEMA']);
-     }
-     parser.suggestTables();
-     parser.suggestDatabases({ appendDot: true });
-    }
- | 'DESCRIBE' DatabaseOrSchema OptionalExtended DatabaseIdentifier_EDIT
-   {
-     if (!$3) {
-       parser.suggestKeywords(['EXTENDED']);
-     }
-   }
- | 'DESCRIBE' DatabaseOrSchema OptionalExtended 'CURSOR' DatabaseIdentifier
-    {
-      if (!$3) {
-        parser.suggestKeywords(['EXTENDED']);
-      }
-    }
- | 'DESCRIBE' 'FUNCTION' OptionalExtended 'CURSOR'
-   {
-     if (!$3) {
-       parser.suggestKeywords(['EXTENDED']);
-     }
-   }
- | 'DESCRIBE' 'FUNCTION' OptionalExtended 'CURSOR' RegularIdentifier
-    {
-      if (!$3) {
-        parser.suggestKeywords(['EXTENDED']);
-      }
-    }
- ;
-
 // ===================================== SELECT statement =====================================
 
 QuerySpecification

+ 24 - 6
desktop/core/src/desktop/js/parse/jison/sql/hive/structure.json

@@ -22,6 +22,9 @@
     "create/create_temporary_macro.jison",
     "create/create_view.jison",
     "delete/delete.jison",
+    "describe/describe.jison",
+    "describe/describe_database.jison",
+    "describe/describe_function.jison",
     "drop/drop_common.jison",
     "drop/drop_database.jison",
     "drop/drop_function.jison",
@@ -40,7 +43,11 @@
     "grant/grant_user.jison",
     "grant/privilege_type.jison",
     "import/import.jison",
+    "../impala/insert/cte_insert.jison",
+    "insert/insert.jison",
+    "insert/insert_common.jison",
     "load/load_data.jison",
+    "merge/merge.jison",
     "msck/msck.jison",
     "reload/reload.jison",
     "revoke/revoke_admin_option_for.jison",
@@ -50,6 +57,10 @@
     "revoke/revoke_privilege.jison",
     "revoke/revoke_role.jison",
     "revoke/revoke_user.jison",
+    "../generic/set/set_all.jison",
+    "set/set_common.jison",
+    "../generic/set/set_option.jison",
+    "set/set_role.jison",
     "show/show_columns.jison",
     "show/show_common.jison",
     "show/show_compactions.jison",
@@ -89,16 +100,14 @@
     "../generic/udf/function/map.jison",
     "../generic/udf/function/truncate.jison",
     "../generic/udf/udf_common.jison",
+    "update/update.jison",
     "udf/sql_aggregate.jison",
     "udf/sql_arbitrary.jison",
     "udf/sql_extract.jison",
     "../generic/use/use.jison",
     "../generic/sql_valueExpression.jison",
     "sql_error.jison",
-    "sql_insert.jison",
     "sql_main.jison",
-    "sql_set.jison",
-    "sql_update.jison",
     "../generic/autocomplete_footer.jison"
   ],
   "syntax": [
@@ -123,6 +132,9 @@
     "create/create_temporary_macro.jison",
     "create/create_view.jison",
     "delete/delete.jison",
+    "describe/describe.jison",
+    "describe/describe_database.jison",
+    "describe/describe_function.jison",
     "drop/drop_common.jison",
     "drop/drop_database.jison",
     "drop/drop_function.jison",
@@ -141,7 +153,11 @@
     "grant/grant_user.jison",
     "grant/privilege_type.jison",
     "import/import.jison",
+    "../impala/insert/cte_insert.jison",
+    "insert/insert.jison",
+    "insert/insert_common.jison",
     "load/load_data.jison",
+    "merge/merge.jison",
     "msck/msck.jison",
     "reload/reload.jison",
     "revoke/revoke_admin_option_for.jison",
@@ -151,6 +167,10 @@
     "revoke/revoke_privilege.jison",
     "revoke/revoke_role.jison",
     "revoke/revoke_user.jison",
+    "../generic/set/set_all.jison",
+    "set/set_common.jison",
+    "../generic/set/set_option.jison",
+    "set/set_role.jison",
     "show/show_columns.jison",
     "show/show_common.jison",
     "show/show_compactions.jison",
@@ -190,15 +210,13 @@
     "../generic/udf/function/map.jison",
     "../generic/udf/function/truncate.jison",
     "../generic/udf/udf_common.jison",
+    "update/update.jison",
     "udf/sql_aggregate.jison",
     "udf/sql_arbitrary.jison",
     "udf/sql_extract.jison",
     "../generic/use/use.jison",
     "../generic/sql_valueExpression.jison",
-    "sql_insert.jison",
     "sql_main.jison",
-    "sql_set.jison",
-    "sql_update.jison",
     "../generic/syntax_footer.jison"
   ]
 }

+ 0 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/sql_update.jison → desktop/core/src/desktop/js/parse/jison/sql/hive/update/update.jison


+ 0 - 96
desktop/core/src/desktop/js/parse/jison/sql/presto/sql_main.jison

@@ -501,14 +501,6 @@ NonStartingToken
  | '~'
  ;
 
-DataDefinition
- : DescribeStatement
- ;
-
-DataDefinition_EDIT
- : DescribeStatement_EDIT
- ;
-
 // ===================================== Commonly used constructs =====================================
 
 Commas
@@ -1141,94 +1133,6 @@ OptionalTypePrecision
  | '(' 'UNSIGNED_INTEGER' ',' 'UNSIGNED_INTEGER' ')'
  ;
 
-// ===================================== DESCRIBE statement =====================================
-
-DescribeStatement
- : 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain OptionalPartitionSpec
-   {
-     parser.addTablePrimary($3);
-     parser.addColumnLocation(@4, $4);
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier OptionalPartitionSpec
-   {
-     parser.addTablePrimary($3);
-   }
- | 'DESCRIBE' DatabaseOrSchema OptionalExtended DatabaseIdentifier
-   {
-     parser.addDatabaseLocation(@4, [{ name: $4 }]);
-   }
- | 'DESCRIBE' 'FUNCTION' OptionalExtended RegularIdentifier
- ;
-
-DescribeStatement_EDIT
- : 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain_EDIT OptionalPartitionSpec
-   {
-     parser.addTablePrimary($3);
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted 'CURSOR' SchemaQualifiedTableIdentifier DerivedColumnChain OptionalPartitionSpec
-   {
-     if (!$2) {
-       parser.suggestKeywords(['EXTENDED', 'FORMATTED']);
-     }
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec
-   {
-     if (!$2) {
-       parser.suggestKeywords(['EXTENDED', 'FORMATTED']);
-     }
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier 'CURSOR' OptionalPartitionSpec
-   {
-     parser.addTablePrimary($3);
-     parser.suggestColumns();
-     if (!$5) {
-       parser.suggestKeywords(['PARTITION']);
-     }
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain 'CURSOR' OptionalPartitionSpec
-   {
-     if (!$6) {
-       parser.suggestKeywords(['PARTITION']);
-     }
-   }
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier DerivedColumnChain OptionalPartitionSpec_EDIT
- | 'DESCRIBE' OptionalExtendedOrFormatted SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT
-
- | 'DESCRIBE' OptionalExtendedOrFormatted 'CURSOR'
-   {
-     if (!$2) {
-       parser.suggestKeywords(['DATABASE', 'EXTENDED', 'FORMATTED', 'FUNCTION', 'SCHEMA']);
-     }
-     parser.suggestTables();
-     parser.suggestDatabases({ appendDot: true });
-    }
- | 'DESCRIBE' DatabaseOrSchema OptionalExtended DatabaseIdentifier_EDIT
-   {
-     if (!$3) {
-       parser.suggestKeywords(['EXTENDED']);
-     }
-   }
- | 'DESCRIBE' DatabaseOrSchema OptionalExtended 'CURSOR' DatabaseIdentifier
-    {
-      if (!$3) {
-        parser.suggestKeywords(['EXTENDED']);
-      }
-    }
- | 'DESCRIBE' 'FUNCTION' OptionalExtended 'CURSOR'
-   {
-     if (!$3) {
-       parser.suggestKeywords(['EXTENDED']);
-     }
-   }
- | 'DESCRIBE' 'FUNCTION' OptionalExtended 'CURSOR' RegularIdentifier
-    {
-      if (!$3) {
-        parser.suggestKeywords(['EXTENDED']);
-      }
-    }
- ;
-
 // ===================================== SELECT statement =====================================
 
 QuerySpecification

+ 24 - 6
desktop/core/src/desktop/js/parse/jison/sql/presto/structure.json

@@ -22,6 +22,9 @@
     "../hive/create/create_temporary_macro.jison",
     "../hive/create/create_view.jison",
     "../hive/delete/delete.jison",
+    "../hive/describe/describe.jison",
+    "../hive/describe/describe_database.jison",
+    "../hive/describe/describe_function.jison",
     "../hive/drop/drop_common.jison",
     "../hive/drop/drop_database.jison",
     "../hive/drop/drop_function.jison",
@@ -39,7 +42,11 @@
     "../hive/grant/grant_user.jison",
     "../hive/grant/privilege_type.jison",
     "../hive/import/import.jison",
+    "../impala/insert/cte_insert.jison",
+    "../hive/insert/insert.jison",
+    "../hive/insert/insert_common.jison",
     "load/load_data.jison",
+    "../hive/merge/merge.jison",
     "msck/msck.jison",
     "../hive/reload/reload.jison",
     "../hive/revoke/revoke_admin_option_for.jison",
@@ -49,6 +56,10 @@
     "../hive/revoke/revoke_privilege.jison",
     "../hive/revoke/revoke_role.jison",
     "../hive/revoke/revoke_user.jison",
+    "../generic/set/set_all.jison",
+    "../hive/set/set_common.jison",
+    "../generic/set/set_option.jison",
+    "../hive/set/set_role.jison",
     "../hive/show/show_columns.jison",
     "../hive/show/show_common.jison",
     "../hive/show/show_compactions.jison",
@@ -91,13 +102,11 @@
     "../hive/udf/sql_aggregate.jison",
     "../hive/udf/sql_arbitrary.jison",
     "../hive/udf/sql_extract.jison",
+    "../hive/update/update.jison",
     "../generic/use/use.jison",
     "../generic/sql_valueExpression.jison",
     "../hive/sql_error.jison",
-    "../hive/sql_insert.jison",
     "sql_main.jison",
-    "../hive/sql_set.jison",
-    "../hive/sql_update.jison",
     "../generic/autocomplete_footer.jison"
   ],
   "syntax": [
@@ -122,6 +131,9 @@
     "../hive/create/create_temporary_macro.jison",
     "../hive/create/create_view.jison",
     "../hive/delete/delete.jison",
+    "../hive/describe/describe.jison",
+    "../hive/describe/describe_database.jison",
+    "../hive/describe/describe_function.jison",
     "../hive/drop/drop_common.jison",
     "../hive/drop/drop_database.jison",
     "../hive/drop/drop_function.jison",
@@ -139,7 +151,11 @@
     "../hive/grant/grant_user.jison",
     "../hive/grant/privilege_type.jison",
     "../hive/import/import.jison",
+    "../impala/insert/cte_insert.jison",
+    "../hive/insert/insert.jison",
+    "../hive/insert/insert_common.jison",
     "load/load_data.jison",
+    "../hive/merge/merge.jison",
     "msck/msck.jison",
     "../hive/reload/reload.jison",
     "../hive/revoke/revoke_admin_option_for.jison",
@@ -149,6 +165,10 @@
     "../hive/revoke/revoke_privilege.jison",
     "../hive/revoke/revoke_role.jison",
     "../hive/revoke/revoke_user.jison",
+    "../generic/set/set_all.jison",
+    "../hive/set/set_common.jison",
+    "../generic/set/set_option.jison",
+    "../hive/set/set_role.jison",
     "../hive/show/show_columns.jison",
     "../hive/show/show_common.jison",
     "../hive/show/show_compactions.jison",
@@ -191,12 +211,10 @@
     "../hive/udf/sql_aggregate.jison",
     "../hive/udf/sql_arbitrary.jison",
     "../hive/udf/sql_extract.jison",
+    "../hive/update/update.jison",
     "../generic/use/use.jison",
     "../generic/sql_valueExpression.jison",
-    "../hive/sql_insert.jison",
     "sql_main.jison",
-    "../hive/sql_set.jison",
-    "../hive/sql_update.jison",
     "../generic/syntax_footer.jison"
   ]
 }

File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js


File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js


File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/presto/prestoAutocompleteParser.js


File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/presto/prestoSyntaxParser.js


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