// 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 : DropStatement | HiveAbortStatement ; DataDefinition_EDIT : DropStatement_EDIT | HiveAbortStatement_EDIT ; DataManipulation : HiveDeleteStatement | ImpalaDeleteStatement ; DataManipulation_EDIT : HiveDeleteStatement_EDIT | ImpalaDeleteStatement_EDIT ; DropStatement : DropDatabaseStatement | DropFunctionStatement | DropRoleStatement | DropStatsStatement | DropTableStatement | DropIndexStatement | DropMacroStatement | DropViewStatement | TruncateTableStatement ; DropStatement_EDIT : DropDatabaseStatement_EDIT | DropFunctionStatement_EDIT | DropStatsStatement_EDIT | DropTableStatement_EDIT | DropIndexStatement_EDIT | DropMacroStatement_EDIT | DropViewStatement_EDIT | TruncateTableStatement_EDIT | 'DROP' 'CURSOR' { if (parser.isHive()) { parser.suggestKeywords(['DATABASE', 'FUNCTION', 'INDEX', 'ROLE', 'SCHEMA', 'TABLE', 'TEMPORARY FUNCTION', 'TEMPORARY MACRO', 'VIEW']); } else if (parser.isImpala()) { parser.suggestKeywords(['AGGREGATE FUNCTION', 'DATABASE', 'FUNCTION', 'INCREMENTAL STATS', 'ROLE', 'SCHEMA', 'STATS', 'TABLE', 'VIEW']); } else { parser.suggestKeywords(['ROLE', 'SCHEMA', 'TABLE', 'VIEW']); } } ; DropDatabaseStatement : 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier OptionalCascadeOrRestrict ; DropDatabaseStatement_EDIT : 'DROP' DatabaseOrSchema OptionalIfExists | 'DROP' DatabaseOrSchema OptionalIfExists_EDIT | 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR' { if (!$3) { parser.suggestKeywords(['IF EXISTS']); } parser.suggestDatabases(); } | 'DROP' DatabaseOrSchema OptionalIfExists RegularOrBacktickedIdentifier 'CURSOR' { if (parser.isHive() || parser.isImpala()) { parser.suggestKeywords(['CASCADE', 'RESTRICT']); } } | 'DROP' DatabaseOrSchema OptionalIfExists_EDIT RegularOrBacktickedIdentifier OptionalCascadeOrRestrict | 'DROP' DatabaseOrSchema OptionalIfExists 'CURSOR' RegularOrBacktickedIdentifier OptionalCascadeOrRestrict { if (!$3) { parser.suggestKeywords(['IF EXISTS']); } } ; DropFunctionStatement : DropImpalaFunction | DropHiveFunction ; DropFunctionStatement_EDIT : DropImpalaFunction_EDIT | DropHiveFunction_EDIT ; // OptionalAggregate is no go for look ahead reasons DropImpalaFunction : 'DROP' 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList | 'DROP' 'AGGREGATE' 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList ; DropImpalaFunction_EDIT : 'DROP' 'FUNCTION' OptionalIfExists 'CURSOR' { if (!$3) { parser.suggestKeywords(['IF EXISTS']); } parser.suggestDatabases({ appendDot: true }); } | 'DROP' 'AGGREGATE' 'FUNCTION' OptionalIfExists 'CURSOR' { if (!$4) { parser.suggestKeywords(['IF EXISTS']); } parser.suggestDatabases({ appendDot: true }); } | 'DROP' 'FUNCTION' OptionalIfExists 'CURSOR' SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList { if (!$3) { parser.suggestKeywords(['IF EXISTS']); } } | 'DROP' 'FUNCTION' OptionalIfExists_EDIT | 'DROP' 'CURSOR' 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList { parser.suggestKeywords(['AGGREGATE']); } | 'DROP' 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList_EDIT | 'DROP' 'AGGREGATE' 'CURSOR' { parser.suggestKeywords(['FUNCTION']); } | 'DROP' 'AGGREGATE' 'FUNCTION' OptionalIfExists 'CURSOR' SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList { if (!$4) { parser.suggestKeywords(['IF EXISTS']); } } | 'DROP' 'AGGREGATE' 'FUNCTION' OptionalIfExists_EDIT | 'DROP' 'AGGREGATE' 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier ParenthesizedImpalaArgumentList_EDIT | 'DROP' 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier_EDIT ParenthesizedImpalaArgumentList | 'DROP' 'AGGREGATE' 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier_EDIT ParenthesizedImpalaArgumentList ; DropHiveFunction : 'DROP' 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier | 'DROP' 'TEMPORARY' 'FUNCTION' OptionalIfExists RegularIdentifier ; DropHiveFunction_EDIT : 'DROP' 'FUNCTION' OptionalIfExists 'CURSOR' { if (!$3) { parser.suggestKeywords(['IF EXISTS']); } } | 'DROP' 'FUNCTION' OptionalIfExists 'CURSOR' SchemaQualifiedIdentifier { if (!$3) { parser.suggestKeywords(['IF EXISTS']); } } | 'DROP' 'FUNCTION' OptionalIfExists_EDIT | 'DROP' 'FUNCTION' OptionalIfExists_EDIT SchemaQualifiedIdentifier | 'DROP' 'FUNCTION' OptionalIfExists SchemaQualifiedIdentifier_EDIT | 'DROP' 'TEMPORARY' 'FUNCTION' OptionalIfExists 'CURSOR' { if (!$4) { parser.suggestKeywords(['IF EXISTS']); } } | 'DROP' 'TEMPORARY' 'FUNCTION' OptionalIfExists_EDIT ; DropRoleStatement : 'DROP' AnyRole RegularIdentifier ; DropStatsStatement : 'DROP' 'STATS' SchemaQualifiedTableIdentifier { parser.addTablePrimary($3); } | 'DROP' 'INCREMENTAL' 'STATS' SchemaQualifiedTableIdentifier PartitionSpec { parser.addTablePrimary($4); } ; DropStatsStatement_EDIT : 'DROP' 'STATS' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | 'DROP' 'STATS' SchemaQualifiedTableIdentifier_EDIT | 'DROP' 'CURSOR' 'STATS' SchemaQualifiedTableIdentifier { parser.addTablePrimary($4); parser.suggestKeywords(['INCREMENTAL']); } | 'DROP' 'CURSOR' 'STATS' SchemaQualifiedTableIdentifier PartitionSpec { parser.addTablePrimary($4); parser.suggestKeywords(['INCREMENTAL']); } | 'DROP' 'INCREMENTAL' 'CURSOR' { parser.suggestKeywords(['STATS']); } | 'DROP' 'INCREMENTAL' 'STATS' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | 'DROP' 'INCREMENTAL' 'STATS' SchemaQualifiedTableIdentifier_EDIT | 'DROP' 'INCREMENTAL' 'STATS' SchemaQualifiedTableIdentifier_EDIT PartitionSpec | 'DROP' 'INCREMENTAL' 'STATS' SchemaQualifiedTableIdentifier 'CURSOR' { parser.addTablePrimary($4); parser.suggestKeywords(['PARTITION']); } | 'DROP' 'INCREMENTAL' 'STATS' SchemaQualifiedTableIdentifier PartitionSpec_EDIT { parser.addTablePrimary($4); } ; DropTableStatement : 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge { parser.addTablePrimary($4); } ; DropTableStatement_EDIT : 'DROP' AnyTable OptionalIfExists_EDIT | 'DROP' AnyTable OptionalIfExists 'CURSOR' { if (!$3) { parser.suggestKeywords(['IF EXISTS']); } parser.suggestTables({ onlyTables: true }); parser.suggestDatabases({ appendDot: true }); } | 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPurge { if (parser.yy.result.suggestTables) { parser.yy.result.suggestTables.onlyTables = true; } } | 'DROP' AnyTable OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPurge | 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPurge 'CURSOR' { parser.addTablePrimary($4); if (!$5) { parser.suggestKeywords(['PURGE']); } } ; OptionalPurge : | 'PURGE' | 'PURGE' ; DropIndexStatement : 'DROP' 'INDEX' OptionalIfExists RegularOrBacktickedIdentifier 'ON' SchemaQualifiedTableIdentifier { parser.addTablePrimary($6); } ; DropIndexStatement_EDIT : 'DROP' 'INDEX' OptionalIfExists 'CURSOR' { parser.suggestKeywords(['IF EXISTS']); } | 'DROP' 'INDEX' OptionalIfExists_EDIT | 'DROP' 'INDEX' OptionalIfExists RegularOrBacktickedIdentifier 'CURSOR' { parser.suggestKeywords(['ON']); } | 'DROP' 'INDEX' OptionalIfExists RegularOrBacktickedIdentifier 'ON' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | 'DROP' 'INDEX' OptionalIfExists RegularOrBacktickedIdentifier 'ON' SchemaQualifiedTableIdentifier_EDIT ; DropMacroStatement : 'DROP' 'TEMPORARY' 'MACRO' OptionalIfExists RegularIdentifier ; DropMacroStatement_EDIT : 'DROP' 'TEMPORARY' 'CURSOR' { parser.suggestKeywords(['FUNCTION', 'MACRO']); } | 'DROP' 'TEMPORARY' 'MACRO' OptionalIfExists 'CURSOR' { if (!$4) { parser.suggestKeywords(['IF EXISTS']); } } | 'DROP' 'TEMPORARY' 'MACRO' OptionalIfExists_EDIT ; DropViewStatement : 'DROP' AnyView OptionalIfExists SchemaQualifiedTableIdentifier { parser.addTablePrimary($4); } ; DropViewStatement_EDIT : 'DROP' AnyView OptionalIfExists 'CURSOR' { if (!$3) { parser.suggestKeywords(['IF EXISTS']); } parser.suggestTables({ onlyViews: true }); parser.suggestDatabases({ appendDot: true }); } | 'DROP' AnyView OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier { parser.addTablePrimary($5); if (!$3) { parser.suggestKeywords(['IF EXISTS']); } } | 'DROP' AnyView OptionalIfExists_EDIT | 'DROP' AnyView OptionalIfExists_EDIT SchemaQualifiedTableIdentifier { parser.addTablePrimary($4); } | 'DROP' AnyView OptionalIfExists SchemaQualifiedTableIdentifier_EDIT { if (parser.yy.result.suggestTables) { parser.yy.result.suggestTables.onlyViews = true; } } ; TruncateTableStatement : 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPartitionSpec { parser.addTablePrimary($4); } ; TruncateTableStatement_EDIT : 'TRUNCATE' 'CURSOR' { parser.suggestKeywords(['TABLE']); } | 'TRUNCATE' AnyTable OptionalIfExists 'CURSOR' OptionalPartitionSpec { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); if (parser.isImpala() && !$3) { parser.suggestKeywords(['IF EXISTS']); } } | 'TRUNCATE' AnyTable OptionalIfExists_EDIT OptionalPartitionSpec | 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier_EDIT OptionalPartitionSpec | 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPartitionSpec 'CURSOR' { parser.addTablePrimary($4); if (parser.isHive() && !$5) { parser.suggestKeywords(['PARTITION']); } } | 'TRUNCATE' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier OptionalPartitionSpec_EDIT { parser.addTablePrimary($4); } | 'TRUNCATE' AnyTable OptionalIfExists 'CURSOR' SchemaQualifiedTableIdentifier OptionalPartitionSpec { parser.addTablePrimary($4); if (parser.isImpala() && !$3) { parser.suggestKeywords(['IF EXISTS']); } } | 'TRUNCATE' AnyTable OptionalIfExists_EDIT SchemaQualifiedTableIdentifier OptionalPartitionSpec ; HiveDeleteStatement : 'DELETE' 'FROM' SchemaQualifiedTableIdentifier OptionalWhereClause { parser.addTablePrimary($3); } ; HiveDeleteStatement_EDIT : 'DELETE' 'CURSOR' { parser.suggestKeywords(['FROM']); } | 'DELETE' 'FROM' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | 'DELETE' 'FROM' SchemaQualifiedTableIdentifier 'CURSOR' OptionalWhereClause { parser.addTablePrimary($3); if (!$5) { parser.suggestKeywords(['WHERE']); } } | 'DELETE' 'FROM' SchemaQualifiedTableIdentifier_EDIT OptionalWhereClause | 'DELETE' 'FROM' SchemaQualifiedTableIdentifier WhereClause_EDIT { parser.addTablePrimary($3); } ; ImpalaDeleteStatement : 'DELETE' OptionalImpalaDeleteTableRef 'FROM' TableReference OptionalWhereClause ; ImpalaDeleteStatement_EDIT : 'DELETE' OptionalImpalaDeleteTableRef 'CURSOR' { parser.suggestKeywords(['FROM']); if (parser.isImpala() && !$2) { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } } | 'DELETE' ImpalaDeleteTableRef_EDIT | 'DELETE' OptionalImpalaDeleteTableRef 'FROM' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | 'DELETE' OptionalImpalaDeleteTableRef 'FROM' TableReference 'CURSOR' OptionalWhereClause { var keywords = [{ value: 'FULL JOIN', weight: 1 }, { value: 'FULL OUTER JOIN', weight: 1 }, { value: 'JOIN', weight: 1 }, { value: 'LEFT JOIN', weight: 1 }, { value: 'LEFT OUTER JOIN', weight: 1 }, { value: 'RIGHT JOIN', weight: 1 }, { value: 'RIGHT OUTER JOIN', weight: 1 }, { value: 'INNER JOIN', weight: 1 }, { value: 'LEFT ANTI JOIN', weight: 1 }, { value: 'LEFT SEMI JOIN', weight: 1 }, { value: 'RIGHT ANTI JOIN', weight: 1 }, { value: 'RIGHT SEMI JOIN', weight: 1 }]; if (!$6) { keywords.push({ value: 'WHERE', weight: 3 }); } if ($4.suggestJoinConditions) { parser.suggestJoinConditions($4.suggestJoinConditions); } if ($4.suggestJoins) { parser.suggestJoins($4.suggestJoins); } if ($4.suggestKeywords) { keywords = keywords.concat(parser.createWeightedKeywords($4.suggestKeywords, 2)); } if (keywords.length > 0) { parser.suggestKeywords(keywords); } } | 'DELETE' ImpalaDeleteTableRef_EDIT 'FROM' | 'DELETE' ImpalaDeleteTableRef_EDIT 'FROM' TableReference OptionalWhereClause | 'DELETE' OptionalImpalaDeleteTableRef 'FROM' TableReference_EDIT OptionalWhereClause | 'DELETE' OptionalImpalaDeleteTableRef 'FROM' TableReference WhereClause_EDIT ; OptionalImpalaDeleteTableRef : | TableReference ; ImpalaDeleteTableRef_EDIT : TableReference_EDIT ; HiveAbortStatement : 'ABORT' 'TRANSACTIONS' TransactionIdList ; HiveAbortStatement_EDIT : 'ABORT' 'CURSOR' { parser.suggestKeywords(['TRANSACTIONS']); } ; TransactionIdList : UnsignedNumericLiteral | TransactionIdList ',' UnsignedNumericLiteral ;