Skip to content

HIVE-28607: Iceberg: Syntax sugar for Iceberg Branching. #5889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- SORT_QUERY_RESULTS

create table ice01 (id int) stored by iceberg;
insert into ice01 values (1), (2), (3), (4);

--- create branch
create branch branch1 FROM ice01;

-- insert some values in branch1
insert into default.ice01.branch_branch1 values (5), (6);
select * from default.ice01.branch_branch1;

-- replace branch
create or replace branch test_branch_1 FROM ice01;;
select * from default.ice01.branch_branch1;

-- create tag
create tag tag1 FROM ice01;
select * from default.ice01.tag_tag1;

-- replace tag
delete from ice01 where id=2;
create or replace tag tag1 FROM ice01;
select * from default.ice01.tag_tag1;

-- drop branch
drop branch branch1 FROM ice01;

--drop tag
drop tag tag1 FROM ice01;
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
PREHOOK: query: create table ice01 (id int) stored by iceberg
PREHOOK: type: CREATETABLE
PREHOOK: Output: database:default
PREHOOK: Output: default@ice01
POSTHOOK: query: create table ice01 (id int) stored by iceberg
POSTHOOK: type: CREATETABLE
POSTHOOK: Output: database:default
POSTHOOK: Output: default@ice01
PREHOOK: query: insert into ice01 values (1), (2), (3), (4)
PREHOOK: type: QUERY
PREHOOK: Input: _dummy_database@_dummy_table
PREHOOK: Output: default@ice01
POSTHOOK: query: insert into ice01 values (1), (2), (3), (4)
POSTHOOK: type: QUERY
POSTHOOK: Input: _dummy_database@_dummy_table
POSTHOOK: Output: default@ice01
PREHOOK: query: create branch branch1 FROM ice01
PREHOOK: type: ALTERTABLE_CREATEBRANCH
PREHOOK: Input: default@ice01
POSTHOOK: query: create branch branch1 FROM ice01
POSTHOOK: type: ALTERTABLE_CREATEBRANCH
POSTHOOK: Input: default@ice01
PREHOOK: query: insert into default.ice01.branch_branch1 values (5), (6)
PREHOOK: type: QUERY
PREHOOK: Input: _dummy_database@_dummy_table
PREHOOK: Output: default@ice01
POSTHOOK: query: insert into default.ice01.branch_branch1 values (5), (6)
POSTHOOK: type: QUERY
POSTHOOK: Input: _dummy_database@_dummy_table
POSTHOOK: Output: default@ice01
PREHOOK: query: select * from default.ice01.branch_branch1
PREHOOK: type: QUERY
PREHOOK: Input: default@ice01
PREHOOK: Output: hdfs://### HDFS PATH ###
POSTHOOK: query: select * from default.ice01.branch_branch1
POSTHOOK: type: QUERY
POSTHOOK: Input: default@ice01
POSTHOOK: Output: hdfs://### HDFS PATH ###
1
2
3
4
5
6
PREHOOK: query: create or replace branch test_branch_1 FROM ice01
PREHOOK: type: ALTERTABLE_CREATEBRANCH
PREHOOK: Input: default@ice01
POSTHOOK: query: create or replace branch test_branch_1 FROM ice01
POSTHOOK: type: ALTERTABLE_CREATEBRANCH
POSTHOOK: Input: default@ice01
PREHOOK: query: select * from default.ice01.branch_branch1
PREHOOK: type: QUERY
PREHOOK: Input: default@ice01
PREHOOK: Output: hdfs://### HDFS PATH ###
POSTHOOK: query: select * from default.ice01.branch_branch1
POSTHOOK: type: QUERY
POSTHOOK: Input: default@ice01
POSTHOOK: Output: hdfs://### HDFS PATH ###
1
2
3
4
5
6
PREHOOK: query: create tag tag1 FROM ice01
PREHOOK: type: ALTERTABLE_CREATETAG
PREHOOK: Input: default@ice01
POSTHOOK: query: create tag tag1 FROM ice01
POSTHOOK: type: ALTERTABLE_CREATETAG
POSTHOOK: Input: default@ice01
PREHOOK: query: select * from default.ice01.tag_tag1
PREHOOK: type: QUERY
PREHOOK: Input: default@ice01
PREHOOK: Output: hdfs://### HDFS PATH ###
POSTHOOK: query: select * from default.ice01.tag_tag1
POSTHOOK: type: QUERY
POSTHOOK: Input: default@ice01
POSTHOOK: Output: hdfs://### HDFS PATH ###
1
2
3
4
PREHOOK: query: delete from ice01 where id=2
PREHOOK: type: QUERY
PREHOOK: Input: default@ice01
PREHOOK: Output: default@ice01
POSTHOOK: query: delete from ice01 where id=2
POSTHOOK: type: QUERY
POSTHOOK: Input: default@ice01
POSTHOOK: Output: default@ice01
PREHOOK: query: create or replace tag tag1 FROM ice01
PREHOOK: type: ALTERTABLE_CREATETAG
PREHOOK: Input: default@ice01
POSTHOOK: query: create or replace tag tag1 FROM ice01
POSTHOOK: type: ALTERTABLE_CREATETAG
POSTHOOK: Input: default@ice01
PREHOOK: query: select * from default.ice01.tag_tag1
PREHOOK: type: QUERY
PREHOOK: Input: default@ice01
PREHOOK: Output: hdfs://### HDFS PATH ###
POSTHOOK: query: select * from default.ice01.tag_tag1
POSTHOOK: type: QUERY
POSTHOOK: Input: default@ice01
POSTHOOK: Output: hdfs://### HDFS PATH ###
1
3
4
PREHOOK: query: drop branch branch1 FROM ice01
PREHOOK: type: ALTERTABLE_DROPBRANCH
PREHOOK: Input: default@ice01
POSTHOOK: query: drop branch branch1 FROM ice01
POSTHOOK: type: ALTERTABLE_DROPBRANCH
POSTHOOK: Input: default@ice01
PREHOOK: query: drop tag tag1 FROM ice01
PREHOOK: type: ALTERTABLE_DROPTAG
PREHOOK: Input: default@ice01
POSTHOOK: query: drop tag tag1 FROM ice01
POSTHOOK: type: ALTERTABLE_DROPTAG
POSTHOOK: Input: default@ice01
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,42 @@ alterStatementSuffixReplaceTag
-> ^(TOK_ALTERTABLE_REPLACE_SNAPSHOTREF KW_TAG $sourceBranch $snapshotId refRetain?)
;

dropBranchStatement
@init { gParent.pushMsg("alter table drop branch (if exists) branchName", state); }
@after { gParent.popMsg(state); }
: KW_DROP KW_BRANCH ifExists? branchName=identifier KW_FROM tableName
-> ^(TOK_ALTERTABLE tableName
^(TOK_ALTERTABLE_DROP_BRANCH ifExists? $branchName)
)
;

alterStatementSuffixDropBranch
@init { gParent.pushMsg("alter table drop branch (if exists) branchName", state); }
@after { gParent.popMsg(state); }
: KW_DROP KW_BRANCH ifExists? branchName=identifier
-> ^(TOK_ALTERTABLE_DROP_BRANCH ifExists? $branchName)
;

createBranchStatement
@init { gParent.pushMsg("create branch statement", state); }
@after { gParent.popMsg(state); }
: KW_CREATE KW_BRANCH ifNotExists? branchName=identifier KW_FROM tableName
snapshotIdOfRef? refRetain? retentionOfSnapshots?
-> ^(TOK_ALTERTABLE tableName
^(TOK_ALTERTABLE_CREATE_BRANCH $branchName ifNotExists? snapshotIdOfRef? refRetain? retentionOfSnapshots?)
)
;

createOrReplaceBranchStatement
@init { gParent.pushMsg("create branch statement", state); }
@after { gParent.popMsg(state); }
: KW_CREATE KW_OR KW_REPLACE KW_BRANCH branchName=identifier KW_FROM tableName
snapshotIdOfRef? refRetain? retentionOfSnapshots?
-> ^(TOK_ALTERTABLE tableName
^(TOK_ALTERTABLE_CREATE_BRANCH $branchName KW_REPLACE snapshotIdOfRef? refRetain? retentionOfSnapshots?)
)
;

alterStatementSuffixCreateBranch
@init { gParent.pushMsg("alter table create branch", state); }
@after { gParent.popMsg(state); }
Expand Down Expand Up @@ -601,20 +630,47 @@ retentionOfSnapshots
-> ^(TOK_WITH_SNAPSHOT_RETENTION $minSnapshotsToKeep ($maxSnapshotAge $timeUnit)?)
;

dropTagStatement
@init { gParent.pushMsg("drop tag (if exists) tagName", state); }
@after { gParent.popMsg(state); }
: KW_DROP KW_TAG ifExists? tagName=identifier KW_FROM tableName
-> ^(TOK_ALTERTABLE tableName
^(TOK_ALTERTABLE_DROP_TAG ifExists? $tagName)
)
;

alterStatementSuffixDropTag
@init { gParent.pushMsg("alter table drop tag (if exists) tagName", state); }
@after { gParent.popMsg(state); }
: KW_DROP KW_TAG ifExists? tagName=identifier
-> ^(TOK_ALTERTABLE_DROP_TAG ifExists? $tagName)
;

createTagStatement
@init { gParent.pushMsg("alter table drop tag (if exists) tagName", state); }
@after { gParent.popMsg(state); }
: KW_CREATE KW_TAG ifNotExists? tagName=identifier snapshotIdOfRef? refRetain? KW_FROM tableName
-> ^(TOK_ALTERTABLE tableName
^(TOK_ALTERTABLE_CREATE_TAG $tagName ifNotExists? snapshotIdOfRef? refRetain?)
)
;

alterStatementSuffixCreateTag
@init { gParent.pushMsg("alter table create tag", state); }
@after { gParent.popMsg(state); }
: KW_CREATE KW_TAG ifNotExists? tagName=identifier snapshotIdOfRef? refRetain?
-> ^(TOK_ALTERTABLE_CREATE_TAG $tagName ifNotExists? snapshotIdOfRef? refRetain?)
;

createOrReplaceTagStatement
@init { gParent.pushMsg("create or replace tag", state); }
@after { gParent.popMsg(state); }
: KW_CREATE KW_OR KW_REPLACE KW_TAG tagName=identifier snapshotIdOfRef? refRetain? KW_FROM tableName
-> ^(TOK_ALTERTABLE tableName
^(TOK_ALTERTABLE_CREATE_TAG $tagName KW_REPLACE snapshotIdOfRef? refRetain?)
)
;

alterStatementSuffixCreateOrReplaceTag
@init { gParent.pushMsg("alter table create tag", state); }
@after { gParent.popMsg(state); }
Expand Down
6 changes: 6 additions & 0 deletions parser/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,12 @@ ddlStatement
| createTableStatement
| dropTableStatement
| truncateTableStatement
| (KW_CREATE KW_OR KW_REPLACE KW_BRANCH) => createOrReplaceBranchStatement
| (KW_CREATE KW_OR KW_REPLACE KW_TAG) => createOrReplaceTagStatement
| createBranchStatement
| dropBranchStatement
| createTagStatement
| dropTagStatement
| alterStatement
| descStatement
| showStatement
Expand Down
Loading