Skip to content

Commit

Permalink
Spark: Don't allow branch_ usage with TIMESTAMP AS OF (apache#10059)
Browse files Browse the repository at this point in the history
  • Loading branch information
nastra authored and zachdisc committed Dec 12, 2024
1 parent 4e58d27 commit 1cb2c85
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public Table loadTable(Identifier ident, long timestamp) 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");

// convert the timestamp to milliseconds as Spark passes microseconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ public void testInvalidTimeTravelAgainstBranchIdentifierWithAsOf() {
() -> 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");

// using branch_b1 in the table identifier and TIMESTAMP AS OF
Assertions.assertThatThrownBy(
() -> sql("SELECT * FROM %s.branch_b1 TIMESTAMP AS OF now()", tableName))
.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 @@ -215,7 +215,7 @@ public Table loadTable(Identifier ident, long timestamp) 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");

// convert the timestamp to milliseconds as Spark passes microseconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@ public void testInvalidTimeTravelAgainstBranchIdentifierWithAsOf() {
() -> 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");

// using branch_b1 in the table identifier and TIMESTAMP AS OF
Assertions.assertThatThrownBy(
() -> sql("SELECT * FROM %s.branch_b1 TIMESTAMP AS OF now()", tableName))
.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 @@ -215,7 +215,7 @@ public Table loadTable(Identifier ident, long timestamp) 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");

// convert the timestamp to milliseconds as Spark passes microseconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ public void testInvalidTimeTravelAgainstBranchIdentifierWithAsOf() {
() -> 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");

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

@TestTemplate
Expand Down

0 comments on commit 1cb2c85

Please sign in to comment.