Skip to content
Merged
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
Expand Up @@ -943,9 +943,6 @@ public void alterTableSnapshotRefOperation(org.apache.hadoop.hive.ql.metadata.Ta
AlterTableSnapshotRefSpec alterTableSnapshotRefSpec) {
TableDesc tableDesc = Utilities.getTableDesc(hmsTable);
Table icebergTable = IcebergTableUtil.getTable(conf, tableDesc.getProperties());
Optional.ofNullable(icebergTable.currentSnapshot()).orElseThrow(() ->
new UnsupportedOperationException(String.format("Cannot alter %s on iceberg table %s.%s which has no snapshot",
alterTableSnapshotRefSpec.getOperationType().getName(), hmsTable.getDbName(), hmsTable.getTableName())));

switch (alterTableSnapshotRefSpec.getOperationType()) {
case CREATE_BRANCH:
Expand All @@ -954,6 +951,10 @@ public void alterTableSnapshotRefOperation(org.apache.hadoop.hive.ql.metadata.Ta
IcebergBranchExec.createBranch(icebergTable, createBranchSpec);
break;
case CREATE_TAG:
Optional.ofNullable(icebergTable.currentSnapshot()).orElseThrow(() -> new UnsupportedOperationException(
String.format("Cannot alter %s on iceberg table %s.%s which has no snapshot",
alterTableSnapshotRefSpec.getOperationType().getName(), hmsTable.getDbName(),
hmsTable.getTableName())));
AlterTableSnapshotRefSpec.CreateSnapshotRefSpec createTagSpec =
(AlterTableSnapshotRefSpec.CreateSnapshotRefSpec) alterTableSnapshotRefSpec.getOperationParams();
IcebergTagExec.createTag(icebergTable, createTagSpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.iceberg.mr.hive;

import java.util.Optional;
import org.apache.hadoop.hive.ql.parse.AlterTableSnapshotRefSpec;
import org.apache.iceberg.ManageSnapshots;
import org.apache.iceberg.SnapshotRef;
Expand Down Expand Up @@ -55,11 +56,16 @@ public static void createBranch(Table table, AlterTableSnapshotRefSpec.CreateSna
throw new IllegalArgumentException(String.format("Tag %s does not exist", tagName));
}
} else {
snapshotId = table.currentSnapshot().snapshotId();
snapshotId = Optional.ofNullable(table.currentSnapshot()).map(snapshot -> snapshot.snapshotId()).orElse(null);
}
LOG.info("Creating branch {} on iceberg table {} with snapshotId {}", branchName, table.name(), snapshotId);
ManageSnapshots manageSnapshots = table.manageSnapshots();
manageSnapshots.createBranch(branchName, snapshotId);
if (snapshotId != null) {
LOG.info("Creating a branch {} on an iceberg table {} with snapshotId {}", branchName, table.name(), snapshotId);
manageSnapshots.createBranch(branchName, snapshotId);
} else {
LOG.info("Creating a branch {} on an empty iceberg table {}", branchName, table.name());
manageSnapshots.createBranch(branchName);
}
if (createBranchSpec.getMaxRefAgeMs() != null) {
manageSnapshots.setMaxRefAgeMs(branchName, createBranchSpec.getMaxRefAgeMs());
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ set hive.explain.user=false;

create table iceTbl (id int, name string) Stored by Iceberg;

-- creating branch requires table to have current snapshot. here insert some values to generate current snapshot
-- create a branch on an empty table
explain alter table iceTbl create branch test_branch_0;
alter table iceTbl create branch test_branch_0;

insert into iceTbl values(1, 'jack');

-- create s branch test_branch_1 with default values based on the current snapshotId
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ POSTHOOK: query: create table iceTbl (id int, name string) Stored by Iceberg
POSTHOOK: type: CREATETABLE
POSTHOOK: Output: database:default
POSTHOOK: Output: default@iceTbl
PREHOOK: query: explain alter table iceTbl create branch test_branch_0
PREHOOK: type: ALTERTABLE_CREATEBRANCH
PREHOOK: Input: default@icetbl
POSTHOOK: query: explain alter table iceTbl create branch test_branch_0
POSTHOOK: type: ALTERTABLE_CREATEBRANCH
POSTHOOK: Input: default@icetbl
STAGE DEPENDENCIES:
Stage-0 is a root stage

STAGE PLANS:
Stage: Stage-0
SnapshotRef Operation
table name: default.iceTbl
spec: AlterTableSnapshotRefSpec{operationType=CREATE_BRANCH, operationParams=CreateSnapshotRefSpec{refName=test_branch_0}}

PREHOOK: query: alter table iceTbl create branch test_branch_0
PREHOOK: type: ALTERTABLE_CREATEBRANCH
PREHOOK: Input: default@icetbl
POSTHOOK: query: alter table iceTbl create branch test_branch_0
POSTHOOK: type: ALTERTABLE_CREATEBRANCH
POSTHOOK: Input: default@icetbl
PREHOOK: query: insert into iceTbl values(1, 'jack')
PREHOOK: type: QUERY
PREHOOK: Input: _dummy_database@_dummy_table
Expand Down