Skip to content

Commit 2ec03f1

Browse files
authored
feat: hive Authorization syntax and unit tests (#159)
Co-authored-by: zhaoge <>
1 parent 6a99d63 commit 2ec03f1

9 files changed

Lines changed: 957 additions & 903 deletions

File tree

src/grammar/hive/HiveSqlParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ privilegeType
471471
| KW_UPDATE
472472
| KW_CREATE
473473
| KW_DROP
474+
| KW_INDEX
474475
| KW_LOCK
475476
| KW_SELECT
476477
| KW_SHOW_DATABASE

src/lib/hive/HiveSqlLexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated from /Users/xuxiaoqi/Documents/dt-sql-parser-copy/src/grammar/hive/HiveSqlLexer.g4 by ANTLR 4.9.0-SNAPSHOT
1+
// Generated from /Users/xuxiaoqi/Documents/work/daishu-code/dt-sql-parser/src/grammar/hive/HiveSqlLexer.g4 by ANTLR 4.9.0-SNAPSHOT
22

33

44
import { ATN } from "antlr4ts/atn/ATN";

src/lib/hive/HiveSqlParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/lib/hive/HiveSqlParser.ts

Lines changed: 900 additions & 899 deletions
Large diffs are not rendered by default.

src/lib/hive/HiveSqlParserListener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated from /Users/xuxiaoqi/Documents/dt-sql-parser-copy/src/grammar/hive/HiveSqlParser.g4 by ANTLR 4.9.0-SNAPSHOT
1+
// Generated from /Users/xuxiaoqi/Documents/work/daishu-code/dt-sql-parser/src/grammar/hive/HiveSqlParser.g4 by ANTLR 4.9.0-SNAPSHOT
22

33

44
import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener";

src/lib/hive/HiveSqlParserVisitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated from /Users/xuxiaoqi/Documents/dt-sql-parser-copy/src/grammar/hive/HiveSqlParser.g4 by ANTLR 4.9.0-SNAPSHOT
1+
// Generated from /Users/xuxiaoqi/Documents/work/daishu-code/dt-sql-parser/src/grammar/hive/HiveSqlParser.g4 by ANTLR 4.9.0-SNAPSHOT
22

33

44
import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor";
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import HiveSQL from '../../../../src/parser/hive';
2+
import { readSQL } from '../../../helper';
3+
4+
const parser = new HiveSQL();
5+
6+
const features = {
7+
manageRoles: readSQL(__dirname, 'authorization.sql'),
8+
};
9+
10+
describe('HiveSQL Related To Authorization Tests', () => {
11+
features.manageRoles.forEach((manageRole) => {
12+
it(manageRole, () => {
13+
expect(parser.validate(manageRole).length).toBe(0);
14+
});
15+
});
16+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-- SQL Standards Based Hive Authorization
2+
-- Role Management Commands -- Set Role
3+
SET ROLE `admin`;
4+
5+
SET ROLE ALL;
6+
7+
SET ROLE NONE;
8+
9+
-- Role Management Commands -- Grant Role
10+
GRANT role_name TO USER user_name;
11+
12+
GRANT role_name, role_name TO USER user1, ROLE role2 WITH ADMIN OPTION ;
13+
14+
-- Role Management Commands -- Revoke Role
15+
REVOKE role_name FROM USER `user`;
16+
17+
REVOKE ADMIN OPTION FOR role_name, role_name FROM USER `user`, ROLE `role`;
18+
19+
-- Managing Object Privileges -- Object Privilege Commands
20+
GRANT
21+
INSERT
22+
ON table_or_view_name
23+
TO USER `user`;
24+
25+
GRANT INSERT, SELECT, UPDATE, DELETE, ALL ON table_or_view_name1 TO USER `user`, ROLE `role` WITH GRANT OPTION;
26+
27+
REVOKE INSERT
28+
ON table_or_view_name
29+
FROM USER `user`;
30+
31+
REVOKE GRANT OPTION FOR ALL, ALTER, UPDATE, CREATE, DROP, INDEX, LOCK, SELECT, SHOW_DATABASE
32+
ON table_or_view_name
33+
FROM USER `user`, ROLE `role`;
34+

test/parser/hive/syntax/fixtures/show.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ SHOW CURRENT ROLES;
9393
-- Show Role Grant
9494
SHOW ROLE GRANT USER user1;
9595

96+
SHOW ROLE GRANT ROLE `role`;
97+
9698
-- Show Principals
9799
SHOW PRINCIPALS role1;
98100

0 commit comments

Comments
 (0)