Skip to content

Commit

Permalink
don't allow branch_ usage with VERSION AS OF
Browse files Browse the repository at this point in the history
  • Loading branch information
nastra committed Nov 23, 2023
1 parent 986f333 commit 0127c1d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public Table loadTable(Identifier ident, String version) throws NoSuchTableExcep
SparkTable sparkTable = (SparkTable) table;

Preconditions.checkArgument(
sparkTable.snapshotId() == null,
sparkTable.snapshotId() == null && sparkTable.branch() == null,
"Cannot do time-travel based on both table identifier and AS OF");

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public Long snapshotId() {
return snapshotId;
}

public String branch() {
return branch;
}

public SparkTable copyWithSnapshotId(long newSnapshotId) {
return new SparkTable(icebergTable, newSnapshotId, refreshEagerly);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ public void testTimestampAsOf() {
public void testInvalidTimeTravelBasedOnBothAsOfAndTableIdentifier() {
// get the snapshot ID of the last write
long snapshotId = validationCatalog.loadTable(tableIdent).currentSnapshot().snapshotId();
validationCatalog.loadTable(tableIdent).manageSnapshots().createBranch("b1").commit();
// get a timestamp just after the last write
long timestamp =
validationCatalog.loadTable(tableIdent).currentSnapshot().timestampMillis() + 2;
Expand Down Expand Up @@ -424,6 +425,12 @@ public void testInvalidTimeTravelBasedOnBothAsOfAndTableIdentifier() {
"SELECT * FROM %s.%s TIMESTAMP AS OF %s",
tableName, timestampPrefix + timestamp, timestamp);
});

// using branch_b1 in the table identifier and VERSION AS OF
Assertions.assertThatThrownBy(
() -> sql("SELECT * FROM %s.branch_b1 VERSION AS OF %s", tableName, snapshotId))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cannot do time-travel based on both table identifier and AS OF");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public Table loadTable(Identifier ident, String version) throws NoSuchTableExcep
SparkTable sparkTable = (SparkTable) table;

Preconditions.checkArgument(
sparkTable.snapshotId() == null,
sparkTable.snapshotId() == null && sparkTable.branch() == null,
"Cannot do time-travel based on both table identifier and AS OF");

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public Long snapshotId() {
return snapshotId;
}

public String branch() {
return branch;
}

public SparkTable copyWithSnapshotId(long newSnapshotId) {
return new SparkTable(icebergTable, newSnapshotId, refreshEagerly);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ public void testTimestampAsOf() {
public void testInvalidTimeTravelBasedOnBothAsOfAndTableIdentifier() {
// get the snapshot ID of the last write
long snapshotId = validationCatalog.loadTable(tableIdent).currentSnapshot().snapshotId();
validationCatalog.loadTable(tableIdent).manageSnapshots().createBranch("b1").commit();
// get a timestamp just after the last write
long timestamp =
validationCatalog.loadTable(tableIdent).currentSnapshot().timestampMillis() + 2;
Expand Down Expand Up @@ -419,6 +420,12 @@ public void testInvalidTimeTravelBasedOnBothAsOfAndTableIdentifier() {
})
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cannot do time-travel based on both table identifier and AS OF");

// using branch_b1 in the table identifier and VERSION AS OF
Assertions.assertThatThrownBy(
() -> sql("SELECT * FROM %s.branch_b1 VERSION AS OF %s", tableName, snapshotId))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cannot do time-travel based on both table identifier and AS OF");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public Table loadTable(Identifier ident, String version) throws NoSuchTableExcep
SparkTable sparkTable = (SparkTable) table;

Preconditions.checkArgument(
sparkTable.snapshotId() == null,
sparkTable.snapshotId() == null && sparkTable.branch() == null,
"Cannot do time-travel based on both table identifier and AS OF");

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public Long snapshotId() {
return snapshotId;
}

public String branch() {
return branch;
}

public SparkTable copyWithSnapshotId(long newSnapshotId) {
return new SparkTable(icebergTable, newSnapshotId, refreshEagerly);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ public void testTimestampAsOf() {
public void testInvalidTimeTravelBasedOnBothAsOfAndTableIdentifier() {
// get the snapshot ID of the last write
long snapshotId = validationCatalog.loadTable(tableIdent).currentSnapshot().snapshotId();
validationCatalog.loadTable(tableIdent).manageSnapshots().createBranch("b1").commit();
// get a timestamp just after the last write
long timestamp =
validationCatalog.loadTable(tableIdent).currentSnapshot().timestampMillis() + 2;
Expand Down Expand Up @@ -419,6 +420,12 @@ public void testInvalidTimeTravelBasedOnBothAsOfAndTableIdentifier() {
})
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cannot do time-travel based on both table identifier and AS OF");

// using branch_b1 in the table identifier and VERSION AS OF
Assertions.assertThatThrownBy(
() -> sql("SELECT * FROM %s.branch_b1 VERSION AS OF %s", tableName, snapshotId))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Cannot do time-travel based on both table identifier and AS OF");
}

@Test
Expand Down

0 comments on commit 0127c1d

Please sign in to comment.