// 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 : ShowStatement ; DataDefinition_EDIT : ShowStatement_EDIT ; ShowStatement : ShowColumnStatsStatement | ShowColumnsStatement | ShowCompactionsStatement | ShowConfStatement | ShowCreateTableStatement | ShowCurrentRolesStatement | ShowDatabasesStatement | ShowFilesStatement | ShowFunctionsStatement | ShowGrantStatement | ShowIndexStatement | ShowLocksStatement | ShowPartitionsStatement | ShowRoleStatement | ShowRolesStatement | ShowTableStatement | ShowTablesStatement | ShowTblPropertiesStatement | ShowTransactionsStatement | ShowViewsStatement ; AnyShow : 'SHOW' | 'SHOW' ; ShowStatement_EDIT : AnyShow 'CURSOR' { if (parser.isHive()) { parser.suggestKeywords(['COLUMNS', 'COMPACTIONS', 'CONF', 'CREATE TABLE', 'CURRENT ROLES', 'DATABASES', 'FORMATTED', 'FUNCTIONS', 'GRANT', 'INDEX', 'INDEXES', 'LOCKS', 'PARTITIONS', 'PRINCIPALS', 'ROLE GRANT', 'ROLES', 'SCHEMAS', 'TABLE EXTENDED', 'TABLES', 'TBLPROPERTIES', 'TRANSACTIONS', 'VIEWS']); } else if (parser.isImpala()) { parser.suggestKeywords(['AGGREGATE FUNCTIONS', 'ANALYTIC FUNCTIONS', 'COLUMN STATS', 'CREATE TABLE', 'CURRENT ROLES', 'DATABASES', 'FILES IN', 'FUNCTIONS', 'GRANT ROLE', 'PARTITIONS', 'RANGE PARTITIONS', 'ROLE GRANT GROUP', 'ROLES', 'SCHEMAS', 'TABLE STATS', 'TABLES']); } else { parser.suggestKeywords(['COLUMNS', 'DATABASES', 'TABLES']); } } | AnyShow 'CURSOR' RegularOrBackTickedSchemaQualifiedName { // ROLES is considered a non-reserved keywords so we can't match it in ShowCurrentRolesStatement_EDIT if ($3.identifierChain && $3.identifierChain.length === 1 && $3.identifierChain[0].name.toLowerCase() === 'roles') { parser.suggestKeywords(['CURRENT']); parser.yy.locations.pop(); } else { parser.addTablePrimary($3); if (parser.isImpala()) { parser.suggestKeywords(['COLUMN STATS', 'CREATE TABLE', 'FILES IN', 'PARTITIONS', 'RANGE PARTITIONS', 'TABLE STATS']); } } } | AnyShow 'CURSOR' LIKE SingleQuotedValue { if (parser.isImpala()) { parser.suggestKeywords(['AGGREGATE FUNCTIONS', 'ANALYTIC FUNCTIONS', 'DATABASES', 'FUNCTIONS', 'SCHEMAS', 'TABLES']); } else if (parser.isHive()) { parser.suggestKeywords(['DATABASES', 'SCHEMAS', 'TABLE EXTENDED']); } } | ShowColumnStatsStatement_EDIT | ShowColumnsStatement_EDIT | ShowCreateTableStatement_EDIT | ShowCurrentRolesStatement_EDIT | ShowDatabasesStatement_EDIT | ShowFilesStatement_EDIT | ShowFunctionsStatement_EDIT | ShowGrantStatement_EDIT | ShowIndexStatement_EDIT | ShowLocksStatement_EDIT | ShowPartitionsStatement_EDIT | ShowRoleStatement_EDIT | ShowTableStatement_EDIT | ShowTablesStatement_EDIT | ShowTblPropertiesStatement_EDIT | ShowViewsStatement_EDIT ; ShowColumnStatsStatement : AnyShow 'COLUMN' 'STATS' RegularOrBackTickedSchemaQualifiedName { parser.addTablePrimary($4); } ; ShowColumnStatsStatement_EDIT : AnyShow 'COLUMN' 'CURSOR' { parser.suggestKeywords(['STATS']); } | AnyShow 'COLUMN' 'STATS' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | AnyShow 'COLUMN' 'STATS' RegularOrBackTickedSchemaQualifiedName_EDIT ; ShowColumnsStatement : AnyShow 'COLUMNS' AnyFromOrIn RegularOrBacktickedIdentifier | AnyShow 'COLUMNS' AnyFromOrIn RegularOrBacktickedIdentifier AnyFromOrIn RegularOrBacktickedIdentifier ; ShowColumnsStatement_EDIT : AnyShow 'COLUMNS' 'CURSOR' { parser.suggestKeywords(['FROM', 'IN']); } | AnyShow 'COLUMNS' 'CURSOR' RegularOrBacktickedIdentifier { parser.suggestKeywords(['FROM', 'IN']); } | AnyShow 'COLUMNS' AnyFromOrIn 'CURSOR' { parser.suggestTables(); } | AnyShow 'COLUMNS' AnyFromOrIn 'CURSOR' AnyFromOrIn { parser.suggestTables(); } | AnyShow 'COLUMNS' AnyFromOrIn 'CURSOR' AnyFromOrIn RegularOrBacktickedIdentifier { parser.suggestTables(); } | AnyShow 'COLUMNS' AnyFromOrIn RegularOrBacktickedIdentifier 'CURSOR' { parser.suggestKeywords(['FROM', 'IN']); } | AnyShow 'COLUMNS' AnyFromOrIn RegularOrBacktickedIdentifier 'CURSOR' RegularOrBacktickedIdentifier { parser.suggestKeywords(['FROM', 'IN']); } | AnyShow 'COLUMNS' AnyFromOrIn RegularOrBacktickedIdentifier AnyFromOrIn 'CURSOR' { parser.suggestDatabases(); } ; ShowCompactionsStatement : AnyShow 'COMPACTIONS' ; ShowConfStatement : AnyShow 'CONF' ConfigurationName ; ShowCreateTableStatement : AnyShow HiveOrImpalaCreate AnyTableOrView RegularOrBackTickedSchemaQualifiedName { parser.addTablePrimary($4); } ; ShowCreateTableStatement_EDIT : AnyShow HiveOrImpalaCreate 'CURSOR' { if (parser.isImpala()) { parser.suggestKeywords(['TABLE', 'VIEW']); } else { parser.suggestKeywords(['TABLE']); } } | AnyShow HiveOrImpalaCreate AnyTableOrView 'CURSOR' { if ($3.isView && parser.isImpala()) { parser.suggestTables({ onlyViews: true }); } else { parser.suggestTables(); } parser.suggestDatabases({ appendDot: true }); } | AnyShow HiveOrImpalaCreate AnyTableOrView RegularOrBackTickedSchemaQualifiedName_EDIT { if (parser.yy.result.suggestTables && $3.isView) { parser.yy.result.suggestTables.onlyViews = true; } } | AnyShow HiveOrImpalaCreate 'CURSOR' RegularOrBackTickedSchemaQualifiedName { parser.addTablePrimary($4); if (parser.isImpala()) { parser.suggestKeywords(['TABLE', 'VIEW']); } else { parser.suggestKeywords(['TABLE']); } } ; AnyTableOrView : AnyTable | 'VIEW' --> { isView: true } ; ShowCurrentRolesStatement : AnyShow 'CURRENT' 'ROLES' | AnyShow 'CURRENT' 'ROLES' ; ShowCurrentRolesStatement_EDIT : AnyShow 'CURRENT' 'CURSOR' { parser.suggestKeywords([ 'ROLES' ]); } | AnyShow 'CURRENT' 'CURSOR' { parser.suggestKeywords([ 'ROLES' ]); } ; ShowDatabasesStatement : AnyShow HiveOrImpalaDatabasesOrSchemas 'LIKE' SingleQuotedValue | AnyShow 'DATABASES' SingleQuotedValue ; ShowDatabasesStatement_EDIT : AnyShow HiveOrImpalaDatabasesOrSchemas 'CURSOR' { parser.suggestKeywords(['LIKE']); } ; ShowFilesStatement : AnyShow 'FILES' 'IN' RegularOrBackTickedSchemaQualifiedName OptionalPartitionSpec { parser.addTablePrimary($4); } ; ShowFilesStatement_EDIT : AnyShow 'FILES' 'CURSOR' { parser.suggestKeywords(['IN']); } | AnyShow 'FILES' 'IN' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | AnyShow 'FILES' 'IN' RegularOrBackTickedSchemaQualifiedName_EDIT OptionalPartitionSpec | AnyShow 'FILES' 'IN' RegularOrBackTickedSchemaQualifiedName OptionalPartitionSpec 'CURSOR' { parser.addTablePrimary($4); if (!$5) { parser.suggestKeywords(['PARTITION']); } } | AnyShow 'FILES' 'IN' RegularOrBackTickedSchemaQualifiedName OptionalPartitionSpec_EDIT | AnyShow 'FILES' 'CURSOR' RegularOrBackTickedSchemaQualifiedName OptionalPartitionSpec { parser.addTablePrimary($4); parser.suggestKeywords(['IN']); } ; ShowFunctionsStatement : AnyShow 'FUNCTIONS' | AnyShow 'FUNCTIONS' DoubleQuotedValue | AnyShow OptionalAggregateOrAnalytic 'FUNCTIONS' OptionalInDatabase | AnyShow OptionalAggregateOrAnalytic 'FUNCTIONS' OptionalInDatabase 'LIKE' QuotedValue ; ShowFunctionsStatement_EDIT : AnyShow AggregateOrAnalytic 'CURSOR' { parser.suggestKeywords(['FUNCTIONS']); } | AnyShow 'CURSOR' 'FUNCTIONS' OptionalInDatabase { parser.suggestKeywords(['AGGREGATE', 'ANALYTICAL']); } | AnyShow OptionalAggregateOrAnalytic 'FUNCTIONS' OptionalInDatabase 'CURSOR' { if (!$4) { parser.suggestKeywords(['IN', 'LIKE']); } else { parser.suggestKeywords(['LIKE']); } } | AnyShow AggregateOrAnalytic 'CURSOR' OptionalInDatabase 'LIKE' QuotedValue { parser.suggestKeywords(['FUNCTIONS']); } | AnyShow 'CURSOR' 'FUNCTIONS' OptionalInDatabase 'LIKE' QuotedValue { parser.suggestKeywords(['AGGREGATE', 'ANALYTICAL']); } | AnyShow OptionalAggregateOrAnalytic 'FUNCTIONS' OptionalInDatabase 'CURSOR' QuotedValue { if (!$4) { parser.suggestKeywords([{ value: 'IN', weight: 2 }, { value: 'LIKE', weight: 1 }]); } else { parser.suggestKeywords(['LIKE']); } } ; ShowGrantStatement : AnyShow 'GRANT' OptionalPrincipalName | AnyShow 'GRANT' OptionalPrincipalName 'ON' 'ALL' | AnyShow 'GRANT' OptionalPrincipalName 'ON' RegularOrBacktickedIdentifier | AnyShow 'GRANT' OptionalPrincipalName 'ON' AnyTable RegularOrBacktickedIdentifier | AnyShow 'GRANT' 'ROLE' RegularOrBacktickedIdentifier ; ShowGrantStatement_EDIT : AnyShow 'GRANT' OptionalPrincipalName_EDIT { parser.suggestKeywords(['ON']); } | AnyShow 'GRANT' OptionalPrincipalName_EDIT 'ON' 'ALL' | AnyShow 'GRANT' OptionalPrincipalName 'ON' 'CURSOR' { parser.suggestKeywords(['ALL', 'TABLE']); parser.suggestTables(); } | AnyShow 'GRANT' OptionalPrincipalName 'ON' AnyTable 'CURSOR' { parser.suggestTables(); } | AnyShow 'GRANT' OptionalPrincipalName 'ON' 'CURSOR' RegularOrBacktickedIdentifier { parser.suggestKeywords(['TABLE']); } | AnyShow 'GRANT' 'CURSOR' { parser.suggestKeywords(['ROLE']); } ; OptionalPrincipalName : | RegularIdentifier ; OptionalPrincipalName_EDIT : 'CURSOR' | RegularIdentifier 'CURSOR' ; ShowIndexStatement : AnyShow OptionallyFormattedIndex 'ON' RegularOrBacktickedIdentifier | AnyShow OptionallyFormattedIndex 'ON' RegularOrBacktickedIdentifier AnyFromOrIn RegularOrBacktickedIdentifier ; ShowIndexStatement_EDIT : AnyShow OptionallyFormattedIndex | AnyShow OptionallyFormattedIndex_EDIT | AnyShow OptionallyFormattedIndex_EDIT 'ON' RegularOrBacktickedIdentifier | AnyShow OptionallyFormattedIndex_EDIT 'ON' RegularOrBacktickedIdentifier AnyFromOrIn RegularOrBacktickedIdentifier | AnyShow OptionallyFormattedIndex 'CURSOR' { parser.suggestKeywords(['ON']); } | AnyShow OptionallyFormattedIndex 'ON' 'CURSOR' { parser.suggestTables(); } | AnyShow OptionallyFormattedIndex 'CURSOR' RegularOrBacktickedIdentifier { parser.suggestKeywords(['ON']); } | AnyShow OptionallyFormattedIndex 'ON' RegularOrBacktickedIdentifier 'CURSOR' { parser.suggestKeywords(['FROM', 'IN']); } | AnyShow OptionallyFormattedIndex 'ON' RegularOrBacktickedIdentifier 'CURSOR' RegularOrBacktickedIdentifier { parser.suggestKeywords(['FROM', 'IN']); } | AnyShow OptionallyFormattedIndex 'ON' RegularOrBacktickedIdentifier AnyFromOrIn 'CURSOR' { parser.suggestDatabases(); } | AnyShow OptionallyFormattedIndex 'ON' 'CURSOR' AnyFromOrIn RegularOrBacktickedIdentifier { parser.suggestTables({identifierChain: [{name: $6}]}); } ; ShowLocksStatement : AnyShow 'LOCKS' RegularOrBackTickedSchemaQualifiedName { parser.addTablePrimary($3); } | AnyShow 'LOCKS' RegularOrBackTickedSchemaQualifiedName 'EXTENDED' { parser.addTablePrimary($3); } | AnyShow 'LOCKS' RegularOrBackTickedSchemaQualifiedName PartitionSpec { parser.addTablePrimary($3); } | AnyShow 'LOCKS' RegularOrBackTickedSchemaQualifiedName PartitionSpec 'EXTENDED' { parser.addTablePrimary($3); } | AnyShow 'LOCKS' DatabaseOrSchema RegularOrBacktickedIdentifier ; ShowLocksStatement_EDIT : AnyShow 'LOCKS' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); parser.suggestKeywords(['DATABASE', 'SCHEMA']); } | AnyShow 'LOCKS' RegularOrBackTickedSchemaQualifiedName_EDIT | AnyShow 'LOCKS' RegularOrBackTickedSchemaQualifiedName 'CURSOR' { parser.addTablePrimary($3); parser.suggestKeywords(['EXTENDED', 'PARTITION']); } | AnyShow 'LOCKS' RegularOrBackTickedSchemaQualifiedName_EDIT 'EXTENDED' | AnyShow 'LOCKS' RegularOrBackTickedSchemaQualifiedName_EDIT PartitionSpec | AnyShow 'LOCKS' RegularOrBackTickedSchemaQualifiedName PartitionSpec 'CURSOR' { parser.addTablePrimary($3); parser.suggestKeywords(['EXTENDED']); } | AnyShow 'LOCKS' RegularOrBackTickedSchemaQualifiedName_EDIT PartitionSpec 'EXTENDED' | AnyShow 'LOCKS' DatabaseOrSchema 'CURSOR' { parser.suggestDatabases(); } ; ShowPartitionsStatement : AnyShow 'PARTITIONS' RegularOrBackTickedSchemaQualifiedName { parser.addTablePrimary($3); } | AnyShow 'PARTITIONS' RegularOrBackTickedSchemaQualifiedName PartitionSpec { parser.addTablePrimary($3); } | AnyShow 'PARTITIONS' RegularOrBackTickedSchemaQualifiedName { parser.addTablePrimary($3); } | AnyShow 'RANGE' 'PARTITIONS' RegularOrBackTickedSchemaQualifiedName { parser.addTablePrimary($3); } ; ShowPartitionsStatement_EDIT : AnyShow 'PARTITIONS' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | AnyShow 'PARTITIONS' RegularOrBackTickedSchemaQualifiedName_EDIT | AnyShow 'PARTITIONS' RegularOrBackTickedSchemaQualifiedName 'CURSOR' { parser.addTablePrimary($3); parser.suggestKeywords(['PARTITION']); } | AnyShow 'PARTITIONS' RegularOrBackTickedSchemaQualifiedName_EDIT PartitionSpec | AnyShow 'PARTITIONS' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | AnyShow 'PARTITIONS' RegularOrBackTickedSchemaQualifiedName_EDIT | AnyShow 'RANGE' 'PARTITIONS' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | AnyShow 'RANGE' 'PARTITIONS' RegularOrBackTickedSchemaQualifiedName_EDIT ; ShowRoleStatement : AnyShow 'ROLE' 'GRANT' HiveRoleOrUser RegularIdentifier | AnyShow 'ROLE' 'GRANT' 'GROUP' RegularIdentifier ; ShowRoleStatement_EDIT : AnyShow 'ROLE' 'CURSOR' { parser.suggestKeywords(['GRANT']); } | AnyShow 'ROLE' 'CURSOR' { parser.suggestKeywords(['GRANT']); } | AnyShow 'ROLE' 'CURSOR' HiveRoleOrUser RegularIdentifier { parser.suggestKeywords(['GRANT']); } | AnyShow 'ROLE' 'GRANT' 'CURSOR' { parser.suggestKeywords(['ROLE', 'USER']); } | AnyShow 'ROLE' 'GRANT' 'CURSOR' RegularIdentifier { parser.suggestKeywords(['ROLE', 'USER']); } | AnyShow 'ROLE' 'GRANT' 'CURSOR' { parser.suggestKeywords(['GROUP']); } | AnyShow 'ROLE' 'GRANT' 'CURSOR' RegularIdentifier { parser.suggestKeywords(['GROUP']); } ; ShowRolesStatement : AnyShow 'ROLES' | AnyShow 'ROLES' ; ShowTableStatement : AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase 'LIKE' SingleQuotedValue | AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase 'LIKE' SingleQuotedValue PartitionSpec ; ShowTableStatement_EDIT : AnyShow 'TABLE' 'CURSOR' { parser.suggestKeywords(['EXTENDED']); } | AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase | AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase_EDIT | AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase 'CURSOR' { if ($4) { parser.suggestKeywords(['LIKE']); } else { parser.suggestKeywords(['FROM', 'IN', 'LIKE']); } } | AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase_EDIT 'LIKE' SingleQuotedValue | AnyShow 'TABLE' 'CURSOR' OptionalFromDatabase 'LIKE' SingleQuotedValue { if (parser.isHive()) { parser.suggestKeywords(['EXTENDED']); } } | AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase 'CURSOR' SingleQuotedValue { parser.suggestKeywords(['LIKE']); } | AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase 'LIKE' SingleQuotedValue 'CURSOR' { parser.suggestKeywords(['PARTITION']); } | AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase_EDIT 'LIKE' SingleQuotedValue PartitionSpec | AnyShow 'TABLE' 'CURSOR' OptionalFromDatabase 'LIKE' SingleQuotedValue PartitionSpec { parser.suggestKeywords(['EXTENDED']); } | AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase 'CURSOR' SingleQuotedValue PartitionSpec { parser.suggestKeywords(['LIKE']); } | AnyShow 'TABLE' 'EXTENDED' OptionalFromDatabase 'LIKE' SingleQuotedValue 'CURSOR' PartitionSpecList { parser.suggestKeywords(['PARTITION']); } | AnyShow 'TABLE' 'CURSOR' { parser.suggestKeywords(['STATS']); } | AnyShow 'TABLE' 'STATS' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | AnyShow 'TABLE' 'STATS' RegularOrBackTickedSchemaQualifiedName { parser.addTablePrimary($4); } | AnyShow 'TABLE' 'STATS' RegularOrBackTickedSchemaQualifiedName_EDIT ; ShowTablesStatement : AnyShow HiveOrImpalaTables OptionalInDatabase | AnyShow HiveOrImpalaTables OptionalInDatabase SingleQuotedValue | AnyShow HiveOrImpalaTables OptionalInDatabase 'LIKE' SingleQuotedValue ; ShowTablesStatement_EDIT : AnyShow HiveOrImpalaTables OptionalInDatabase 'CURSOR' { if (!$3) { parser.suggestKeywords(['IN', 'LIKE']); } else { parser.suggestKeywords(['LIKE']); } } ; ShowTblPropertiesStatement : AnyShow 'TBLPROPERTIES' RegularOrBackTickedSchemaQualifiedName { parser.addTablePrimary($3); } | AnyShow 'TBLPROPERTIES' RegularOrBackTickedSchemaQualifiedName '(' QuotedValue ')' { parser.addTablePrimary($3); } ; ShowTblPropertiesStatement_EDIT : AnyShow 'TBLPROPERTIES' RegularOrBackTickedSchemaQualifiedName_EDIT | AnyShow 'TBLPROPERTIES' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ prependDot: true }); } ; ShowTransactionsStatement : AnyShow 'TRANSACTIONS' ; ShowViewsStatement : AnyShow 'VIEWS' OptionalInOrFromDatabase OptionalLike ; ShowViewsStatement_EDIT : AnyShow 'VIEWS' OptionalInOrFromDatabase OptionalLike 'CURSOR' { if (!$4 && !$3) { parser.suggestKeywords([{ value: 'IN', weight: 2 }, { value: 'FROM', weight: 2 }, { value: 'LIKE', weight: 1 }]); } else if (!$4) { parser.suggestKeywords(['LIKE']); } } | AnyShow 'VIEWS' InOrFromDatabase_EDIT OptionalLike | AnyShow 'VIEWS' OptionalInOrFromDatabase Like_EDIT ; OptionalInOrFromDatabase : | 'IN' RegularOrBacktickedIdentifier { parser.addDatabaseLocation(@2, [ { name: $2 } ]); } | 'FROM' RegularOrBacktickedIdentifier { parser.addDatabaseLocation(@2, [ { name: $2 } ]); } ; InOrFromDatabase_EDIT : 'IN' 'CURSOR' { parser.suggestDatabases(); } | 'FROM' 'CURSOR' { parser.suggestDatabases(); } ; OptionalLike : | 'LIKE' SingleQuotedValue ; Like_EDIT : 'LIKE' 'CURSOR' ;