feat: hive Authorization syntax and unit tests (#159)

Co-authored-by: zhaoge <>
This commit is contained in:
XCynthia 2023-09-12 20:10:43 +08:00 committed by GitHub
parent 6a99d63d71
commit 2ec03f1770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 957 additions and 903 deletions

View File

@ -471,6 +471,7 @@ privilegeType
| KW_UPDATE | KW_UPDATE
| KW_CREATE | KW_CREATE
| KW_DROP | KW_DROP
| KW_INDEX
| KW_LOCK | KW_LOCK
| KW_SELECT | KW_SELECT
| KW_SHOW_DATABASE | KW_SHOW_DATABASE

View File

@ -1,4 +1,4 @@
// Generated from /Users/xuxiaoqi/Documents/dt-sql-parser-copy/src/grammar/hive/HiveSqlLexer.g4 by ANTLR 4.9.0-SNAPSHOT // Generated from /Users/xuxiaoqi/Documents/work/daishu-code/dt-sql-parser/src/grammar/hive/HiveSqlLexer.g4 by ANTLR 4.9.0-SNAPSHOT
import { ATN } from "antlr4ts/atn/ATN"; import { ATN } from "antlr4ts/atn/ATN";

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
// Generated from /Users/xuxiaoqi/Documents/dt-sql-parser-copy/src/grammar/hive/HiveSqlParser.g4 by ANTLR 4.9.0-SNAPSHOT // Generated from /Users/xuxiaoqi/Documents/work/daishu-code/dt-sql-parser/src/grammar/hive/HiveSqlParser.g4 by ANTLR 4.9.0-SNAPSHOT
import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener"; import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener";

View File

@ -1,4 +1,4 @@
// Generated from /Users/xuxiaoqi/Documents/dt-sql-parser-copy/src/grammar/hive/HiveSqlParser.g4 by ANTLR 4.9.0-SNAPSHOT // Generated from /Users/xuxiaoqi/Documents/work/daishu-code/dt-sql-parser/src/grammar/hive/HiveSqlParser.g4 by ANTLR 4.9.0-SNAPSHOT
import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor"; import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor";

View File

@ -0,0 +1,16 @@
import HiveSQL from '../../../../src/parser/hive';
import { readSQL } from '../../../helper';
const parser = new HiveSQL();
const features = {
manageRoles: readSQL(__dirname, 'authorization.sql'),
};
describe('HiveSQL Related To Authorization Tests', () => {
features.manageRoles.forEach((manageRole) => {
it(manageRole, () => {
expect(parser.validate(manageRole).length).toBe(0);
});
});
});

View File

@ -0,0 +1,34 @@
-- SQL Standards Based Hive Authorization
-- Role Management Commands -- Set Role
SET ROLE `admin`;
SET ROLE ALL;
SET ROLE NONE;
-- Role Management Commands -- Grant Role
GRANT role_name TO USER user_name;
GRANT role_name, role_name TO USER user1, ROLE role2 WITH ADMIN OPTION ;
-- Role Management Commands -- Revoke Role
REVOKE role_name FROM USER `user`;
REVOKE ADMIN OPTION FOR role_name, role_name FROM USER `user`, ROLE `role`;
-- Managing Object Privileges -- Object Privilege Commands
GRANT
INSERT
ON table_or_view_name
TO USER `user`;
GRANT INSERT, SELECT, UPDATE, DELETE, ALL ON table_or_view_name1 TO USER `user`, ROLE `role` WITH GRANT OPTION;
REVOKE INSERT
ON table_or_view_name
FROM USER `user`;
REVOKE GRANT OPTION FOR ALL, ALTER, UPDATE, CREATE, DROP, INDEX, LOCK, SELECT, SHOW_DATABASE
ON table_or_view_name
FROM USER `user`, ROLE `role`;

View File

@ -93,6 +93,8 @@ SHOW CURRENT ROLES;
-- Show Role Grant -- Show Role Grant
SHOW ROLE GRANT USER user1; SHOW ROLE GRANT USER user1;
SHOW ROLE GRANT ROLE `role`;
-- Show Principals -- Show Principals
SHOW PRINCIPALS role1; SHOW PRINCIPALS role1;