// 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 : GrantStatement | RevokeStatement ; DataDefinition_EDIT : GrantStatement_EDIT | RevokeStatement_EDIT ; GrantStatement : 'GRANT' HivePrivilegeTypeList OptionalOnSpecification 'TO' PrincipalSpecificationList OptionalWithGrantOption | 'GRANT' UserOrRoleList 'TO' PrincipalSpecificationList OptionalWithAdminOption | 'GRANT' 'ROLE' UserOrRoleList 'TO' PrincipalSpecificationList OptionalWithAdminOption | 'GRANT' 'ROLE' RegularOrBacktickedIdentifier 'TO' 'GROUP' RegularOrBacktickedIdentifier | 'GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' RegularOrBacktickedIdentifier OptionalWithGrantOption | 'GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' 'ROLE' RegularOrBacktickedIdentifier OptionalWithGrantOption ; GrantStatement_EDIT : 'GRANT' 'CURSOR' { parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'INDEX', 'INSERT', 'LOCK', 'ROLE', 'SELECT', 'UPDATE']); } | 'GRANT' HivePrivilegeTypeList_EDIT OptionalOnSpecification | 'GRANT' HivePrivilegeTypeList OnSpecification_EDIT | 'GRANT' HivePrivilegeTypeList OptionalOnSpecification 'CURSOR' { if (!$3) { parser.suggestKeywords(['ON', 'TO']); } else { parser.suggestKeywords(['TO']); } } | 'GRANT' HivePrivilegeTypeList OptionalOnSpecification 'TO' 'CURSOR' { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | 'GRANT' HivePrivilegeTypeList OptionalOnSpecification 'TO' PrincipalSpecificationList_EDIT | 'GRANT' HivePrivilegeTypeList OptionalOnSpecification 'TO' PrincipalSpecificationList OptionalWithGrantOption 'CURSOR' { if (!$6) { parser.suggestKeywords(['WITH GRANT OPTION']); } } | 'GRANT' HivePrivilegeTypeList OptionalOnSpecification 'TO' PrincipalSpecificationList WithGrantOption_EDIT | 'GRANT' UserOrRoleList 'CURSOR' { parser.suggestKeywords(['TO']); } | 'GRANT' UserOrRoleList 'TO' 'CURSOR' { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | 'GRANT' UserOrRoleList 'TO' PrincipalSpecificationList_EDIT | 'GRANT' UserOrRoleList 'TO' PrincipalSpecificationList OptionalWithAdminOption 'CURSOR' { if (!$5) { parser.suggestKeywords(['WITH ADMIN OPTION']); } } | 'GRANT' UserOrRoleList 'TO' PrincipalSpecificationList WithAdminOption_EDIT | 'GRANT' 'ROLE' UserOrRoleList 'TO' 'CURSOR' { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | 'GRANT' 'ROLE' UserOrRoleList 'TO' PrincipalSpecificationList_EDIT | 'GRANT' 'ROLE' UserOrRoleList 'TO' PrincipalSpecificationList OptionalWithAdminOption 'CURSOR' { if (!$6) { parser.suggestKeywords(['WITH ADMIN OPTION']); } } | 'GRANT' 'ROLE' UserOrRoleList 'TO' PrincipalSpecificationList WithAdminOption_EDIT | 'GRANT' 'CURSOR' { parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DROP', 'INSERT', 'REFRESH', 'ROLE', 'SELECT']); } | 'GRANT' 'ROLE' RegularOrBacktickedIdentifier 'CURSOR' { parser.suggestKeywords(['TO GROUP']); } | 'GRANT' 'ROLE' RegularOrBacktickedIdentifier 'TO' 'CURSOR' { parser.suggestKeywords(['GROUP']); } | 'GRANT' ImpalaPrivilegeType_EDIT | 'GRANT' ImpalaPrivilegeType 'CURSOR' { if ($2.isCreate) { parser.suggestKeywords(['ON DATABASE', 'ON SERVER']); } else { parser.suggestKeywords(['ON DATABASE', 'ON SERVER', 'ON TABLE', 'ON URI']); } } | 'GRANT' ImpalaPrivilegeType 'ON' 'CURSOR' { if ($2.isCreate) { parser.suggestKeywords(['DATABASE', 'SERVER']); } else { parser.suggestKeywords(['DATABASE', 'SERVER', 'TABLE', 'URI']); } } | 'GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification_EDIT | 'GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'CURSOR' { parser.suggestKeywords(['TO']); } | 'GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' 'CURSOR' { parser.suggestKeywords(['ROLE']); } | 'GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' RegularOrBacktickedIdentifier OptionalWithGrantOption 'CURSOR' { if (!$7) { parser.suggestKeywords(['WITH GRANT OPTION']); } } | 'GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' RegularOrBacktickedIdentifier WithGrantOption_EDIT | 'GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' 'ROLE' RegularOrBacktickedIdentifier OptionalWithGrantOption 'CURSOR' { if (!$8) { parser.suggestKeywords(['WITH GRANT OPTION']); } } | 'GRANT' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'TO' 'ROLE' RegularOrBacktickedIdentifier WithGrantOption_EDIT ; OptionalOnSpecification : | 'ON' HiveObjectSpecification ; OnSpecification_EDIT : 'ON' 'CURSOR' { parser.suggestKeywords(['DATABASE', 'TABLE']); parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | 'ON' HiveObjectSpecification_EDIT ; HiveObjectSpecification : 'DATABASE' RegularOrBacktickedIdentifier | 'TABLE' SchemaQualifiedTableIdentifier { parser.addTablePrimary($2); } | SchemaQualifiedTableIdentifier { parser.addTablePrimary($1); } ; HiveObjectSpecification_EDIT : 'DATABASE' 'CURSOR' { parser.suggestDatabases(); } | 'TABLE' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | 'TABLE' SchemaQualifiedTableIdentifier_EDIT | SchemaQualifiedTableIdentifier_EDIT ; ImpalaObjectSpecification : 'DATABASE' RegularOrBacktickedIdentifier | 'TABLE' SchemaQualifiedTableIdentifier { parser.addTablePrimary($2); } | 'SERVER' RegularOrBacktickedIdentifier | 'URI' RegularOrBacktickedIdentifier ; ImpalaObjectSpecification_EDIT : 'DATABASE' 'CURSOR' { parser.suggestDatabases(); } | 'TABLE' 'CURSOR' { parser.suggestTables(); parser.suggestDatabases({ appendDot: true }); } | 'TABLE' SchemaQualifiedTableIdentifier_EDIT ; HivePrivilegeTypeList : HivePrivilegeTypeWithOptionalColumn { if ($1.toUpperCase() === 'ALL') { $$ = { singleAll: true }; } } | HivePrivilegeTypeList ',' HivePrivilegeTypeWithOptionalColumn ; HivePrivilegeTypeList_EDIT : HivePrivilegeTypeWithOptionalColumn_EDIT | HivePrivilegeTypeList ',' HivePrivilegeTypeWithOptionalColumn_EDIT | HivePrivilegeTypeWithOptionalColumn_EDIT ',' HivePrivilegeTypeList | HivePrivilegeTypeList ',' HivePrivilegeTypeWithOptionalColumn_EDIT ',' HivePrivilegeTypeList | 'CURSOR' ',' HivePrivilegeTypeList { parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'INDEX', 'INSERT', 'LOCK', 'SELECT', 'SHOW_DATABASE', 'UPDATE']); } | HivePrivilegeTypeList ',' 'CURSOR' { parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'INDEX', 'INSERT', 'LOCK', 'SELECT', 'SHOW_DATABASE', 'UPDATE']); } | HivePrivilegeTypeList ',' 'CURSOR' ',' HivePrivilegeTypeList { parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'INDEX', 'INSERT', 'LOCK', 'SELECT', 'SHOW_DATABASE', 'UPDATE']); } ; HivePrivilegeTypeWithOptionalColumn : HivePrivilegeType OptionalParenthesizedColumnList ; HivePrivilegeTypeWithOptionalColumn_EDIT : HivePrivilegeType ParenthesizedColumnList_EDIT ; HivePrivilegeType : 'INSERT' | 'SELECT' | 'UPDATE' | 'DELETE' | 'ALTER' | 'CREATE' | 'DROP' | 'INDEX' | 'LOCK' | 'SHOW_DATABASE' | 'ALL' ; ImpalaPrivilegeType : 'ALL' | 'ALTER' | 'CREATE' --> { isCreate: true } | 'DROP' | 'INSERT' | 'REFRESH' | 'SELECT' OptionalParenthesizedColumnList ; ImpalaPrivilegeType_EDIT : 'SELECT' ParenthesizedColumnList_EDIT ; PrincipalSpecificationList : PrincipalSpecification | PrincipalSpecificationList ',' PrincipalSpecification ; PrincipalSpecificationList_EDIT : PrincipalSpecificationList ',' 'CURSOR' { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | 'CURSOR' ',' PrincipalSpecificationList { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | PrincipalSpecificationList ',' 'CURSOR' ',' PrincipalSpecificationList { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } ; PrincipalSpecification : 'USER' RegularOrBacktickedIdentifier | 'GROUP' RegularOrBacktickedIdentifier | 'ROLE' RegularOrBacktickedIdentifier ; PrincipalSpecification_EDIT : 'USER' 'CURSOR' | 'GROUP' 'CURSOR' | 'ROLE' 'CURSOR' ; UserOrRoleList : RegularOrBacktickedIdentifier | UserOrRoleList ',' RegularOrBacktickedIdentifier ; OptionalWithGrantOption : | 'WITH' 'GRANT' 'OPTION' | 'WITH' 'GRANT' 'OPTION' ; WithGrantOption_EDIT : 'WITH' 'CURSOR' { parser.suggestKeywords(['GRANT OPTION']); } | 'WITH' 'GRANT' 'CURSOR' { parser.suggestKeywords(['OPTION']); } | 'WITH' 'GRANT' 'CURSOR' { parser.suggestKeywords(['OPTION']); } ; OptionalWithAdminOption : | 'WITH' 'ADMIN' 'OPTION' ; WithAdminOption_EDIT : 'WITH' 'CURSOR' { parser.suggestKeywords(['ADMIN OPTION']); } | 'WITH' 'ADMIN' 'CURSOR' { parser.suggestKeywords(['OPTION']); } ; RevokeStatement : 'REVOKE' HivePrivilegeTypeList OptionalOnSpecification 'FROM' PrincipalSpecificationList | 'REVOKE' 'GRANT' 'OPTION' 'FOR' HivePrivilegeTypeList OptionalOnSpecification 'FROM' PrincipalSpecificationList | 'REVOKE' UserOrRoleList 'FROM' PrincipalSpecificationList | 'REVOKE' 'ROLE' UserOrRoleList 'FROM' PrincipalSpecificationList | 'REVOKE' 'ADMIN' 'OPTION' 'FOR' UserOrRoleList 'FROM' PrincipalSpecificationList | 'REVOKE' 'ADMIN' 'OPTION' 'FOR' 'ROLE' UserOrRoleList 'FROM' PrincipalSpecificationList | 'REVOKE' 'ALL' PrivilegesOrGrantOption 'FROM' UserOrRoleList | 'REVOKE' 'ROLE' RegularOrBacktickedIdentifier 'FROM' 'GROUP' RegularOrBacktickedIdentifier | 'REVOKE' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'FROM' RegularOrBacktickedIdentifier | 'REVOKE' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'FROM' 'ROLE' RegularOrBacktickedIdentifier ; RevokeStatement_EDIT : 'REVOKE' 'CURSOR' { parser.suggestKeywords(['ADMIN OPTION FOR', 'ALL', 'ALL GRANT OPTION FROM', 'ALL PRIVILEGES FROM', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'GRANT OPTION FOR', 'INDEX', 'INSERT', 'LOCK', 'ROLE', 'SELECT', 'UPDATE']); } | 'REVOKE' HivePrivilegeTypeList_EDIT | 'REVOKE' HivePrivilegeTypeList OnSpecification_EDIT | 'REVOKE' HivePrivilegeTypeList OptionalOnSpecification 'CURSOR' { if (!$3) { if ($2.singleAll) { parser.suggestKeywords(['FROM', 'GRANT OPTION', 'ON', 'PRIVILEGES FROM']); } else { parser.suggestKeywords(['FROM', 'ON']); } } else { parser.suggestKeywords(['FROM']); } } | 'REVOKE' HivePrivilegeTypeList OptionalOnSpecification 'FROM' 'CURSOR' { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | 'REVOKE' HivePrivilegeTypeList OptionalOnSpecification 'FROM' PrincipalSpecificationList_EDIT | 'REVOKE' 'GRANT' 'CURSOR' { parser.suggestKeywords(['OPTION FOR']); } | 'REVOKE' 'GRANT' 'OPTION' 'CURSOR' { parser.suggestKeywords(['FOR']); } | 'REVOKE' 'GRANT' 'OPTION' 'FOR' 'CURSOR' { parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DELETE', 'DROP', 'INDEX', 'INSERT', 'LOCK', 'SELECT', 'SHOW_DATABASE', 'UPDATE']); } | 'REVOKE' 'GRANT' 'OPTION' 'FOR' HivePrivilegeTypeList_EDIT | 'REVOKE' 'GRANT' 'OPTION' 'FOR' HivePrivilegeTypeList OnSpecification_EDIT | 'REVOKE' 'GRANT' 'OPTION' 'FOR' HivePrivilegeTypeList OptionalOnSpecification 'CURSOR' { if (!$6) { parser.suggestKeywords(['FROM', 'ON']); } else { parser.suggestKeywords(['FROM']); } } | 'REVOKE' 'GRANT' 'OPTION' 'FOR' HivePrivilegeTypeList OptionalOnSpecification 'FROM' 'CURSOR' { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | 'REVOKE' 'GRANT' 'OPTION' 'FOR' HivePrivilegeTypeList OptionalOnSpecification 'FROM' PrincipalSpecificationList_EDIT | 'REVOKE' UserOrRoleList 'CURSOR' { if ($2.toUpperCase() === 'ADMIN') { parser.suggestKeywords(['FROM', 'OPTION FOR']); } else { parser.suggestKeywords(['FROM']); } } | 'REVOKE' UserOrRoleList 'FROM' 'CURSOR' { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | 'REVOKE' UserOrRoleList 'FROM' PrincipalSpecificationList_EDIT | 'REVOKE' 'ROLE' UserOrRoleList 'CURSOR' { parser.suggestKeywords(['FROM']); } | 'REVOKE' 'ROLE' UserOrRoleList 'FROM' 'CURSOR' { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | 'REVOKE' 'ROLE' UserOrRoleList 'FROM' PrincipalSpecificationList_EDIT | 'REVOKE' 'ADMIN' 'OPTION' 'CURSOR' { parser.suggestKeywords(['FOR']); } | 'REVOKE' 'ADMIN' 'OPTION' 'FOR' 'CURSOR' { parser.suggestKeywords(['ROLE']); } | 'REVOKE' 'ADMIN' 'OPTION' 'FOR' UserOrRoleList 'CURSOR' { parser.suggestKeywords(['FROM']); } | 'REVOKE' 'ADMIN' 'OPTION' 'FOR' UserOrRoleList 'FROM' 'CURSOR' { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | 'REVOKE' 'ADMIN' 'OPTION' 'FOR' UserOrRoleList 'FROM' PrincipalSpecificationList_EDIT | 'REVOKE' 'ADMIN' 'OPTION' 'FOR' 'ROLE' UserOrRoleList 'CURSOR' { parser.suggestKeywords(['FROM']); } | 'REVOKE' 'ADMIN' 'OPTION' 'FOR' 'ROLE' UserOrRoleList 'FROM' 'CURSOR' { parser.suggestKeywords(['GROUP', 'ROLE', 'USER']); } | 'REVOKE' 'ADMIN' 'OPTION' 'FOR' 'ROLE' UserOrRoleList 'FROM' PrincipalSpecificationList_EDIT | 'REVOKE' 'ALL' PrivilegesOrGrantOption_EDIT | 'REVOKE' 'ALL' PrivilegesOrGrantOption 'CURSOR' { parser.suggestKeywords(['FROM']); } | 'REVOKE' 'CURSOR' { parser.suggestKeywords(['ALL', 'ALTER', 'CREATE', 'DROP', 'INSERT', 'REFRESH', 'ROLE', 'SELECT']); } | 'REVOKE' 'ROLE' RegularOrBacktickedIdentifier 'CURSOR' { parser.suggestKeywords(['FROM GROUP']); } | 'REVOKE' 'ROLE' RegularOrBacktickedIdentifier 'FROM' 'CURSOR' { parser.suggestKeywords(['GROUP']); } | 'REVOKE' ImpalaPrivilegeType_EDIT | 'REVOKE' ImpalaPrivilegeType 'CURSOR' { if ($2.isCreate) { parser.suggestKeywords(['ON DATABASE', 'ON SERVER']); } else { parser.suggestKeywords(['ON DATABASE', 'ON SERVER', 'ON TABLE', 'ON URI']); } } | 'REVOKE' ImpalaPrivilegeType 'ON' 'CURSOR' { if ($2.isCreate) { parser.suggestKeywords(['DATABASE', 'SERVER']); } else { parser.suggestKeywords(['DATABASE', 'SERVER', 'TABLE', 'URI']); } } | 'REVOKE' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification_EDIT | 'REVOKE' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'CURSOR' { parser.suggestKeywords(['FROM']); } | 'REVOKE' ImpalaPrivilegeType 'ON' ImpalaObjectSpecification 'FROM' 'CURSOR' { parser.suggestKeywords(['ROLE']); } ; PrivilegesOrGrantOption : 'PRIVILEGES' | 'GRANT' 'OPTION' ; PrivilegesOrGrantOption_EDIT : 'GRANT' 'CURSOR' { parser.suggestKeywords(['OPTION']); } ;