Skip to content
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

Spark: Don't allow branch_ usage with VERSION AS OF #9219

Merged
merged 1 commit into from
Dec 5, 2023
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 @@ -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 @@ -426,6 +426,21 @@ public void testInvalidTimeTravelBasedOnBothAsOfAndTableIdentifier() {
});
}

@Test
public void testInvalidTimeTravelAgainstBranchIdentifierWithAsOf() {
long snapshotId = validationCatalog.loadTable(tableIdent).currentSnapshot().snapshotId();
validationCatalog.loadTable(tableIdent).manageSnapshots().createBranch("b1").commit();

// create a second snapshot
sql("INSERT INTO %s VALUES (4, 'd', 4.0), (5, 'e', 5.0)", tableName);

// 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
public void testSpecifySnapshotAndTimestamp() {
// get the snapshot ID of the last write
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 @@ -421,6 +421,21 @@ public void testInvalidTimeTravelBasedOnBothAsOfAndTableIdentifier() {
.hasMessage("Cannot do time-travel based on both table identifier and AS OF");
}

@Test
public void testInvalidTimeTravelAgainstBranchIdentifierWithAsOf() {
long snapshotId = validationCatalog.loadTable(tableIdent).currentSnapshot().snapshotId();
validationCatalog.loadTable(tableIdent).manageSnapshots().createBranch("b1").commit();

// create a second snapshot
sql("INSERT INTO %s VALUES (4, 'd', 4.0), (5, 'e', 5.0)", tableName);

// 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
public void testSpecifySnapshotAndTimestamp() {
// get the snapshot ID of the last write
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 @@ -421,6 +421,21 @@ public void testInvalidTimeTravelBasedOnBothAsOfAndTableIdentifier() {
.hasMessage("Cannot do time-travel based on both table identifier and AS OF");
}

@Test
public void testInvalidTimeTravelAgainstBranchIdentifierWithAsOf() {
long snapshotId = validationCatalog.loadTable(tableIdent).currentSnapshot().snapshotId();
validationCatalog.loadTable(tableIdent).manageSnapshots().createBranch("b1").commit();

// create a second snapshot
sql("INSERT INTO %s VALUES (4, 'd', 4.0), (5, 'e', 5.0)", tableName);

// 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
public void testSpecifySnapshotAndTimestamp() {
// get the snapshot ID of the last write
Expand Down