Skip to content

Commit

Permalink
Fix to prevent importing existing storage table
Browse files Browse the repository at this point in the history
  • Loading branch information
jnmt committed Nov 17, 2023
1 parent 012f941 commit 7eeffe2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public Set<String> getNamespaceNames() throws ExecutionException {
@Override
public void importTable(String namespace, String table, Map<String, String> options)
throws ExecutionException {
TableMetadata tableMetadata = getTableMetadata(namespace, table);
TableMetadata tableMetadata = admin.getTableMetadata(namespace, table);
if (tableMetadata != null) {
throw new IllegalArgumentException(
"Table already exists: " + ScalarDbUtils.getFullTableName(namespace, table));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,29 @@ public void importTable_ShouldCallStorageAdminProperly() throws ExecutionExcepti
}

@Test
public void importTable_WithTableAlreadyExists_ShouldThrowIllegalArgumentException()
public void importTable_WithStorageTableAlreadyExists_ShouldThrowIllegalArgumentException()
throws ExecutionException {
// Arrange
String primaryKeyColumn = "pk";
String column = "col";
TableMetadata metadata =
TableMetadata.newBuilder()
.addColumn(primaryKeyColumn, DataType.INT)
.addColumn(column, DataType.INT)
.addPartitionKey(primaryKeyColumn)
.build();
when(distributedStorageAdmin.getTableMetadata(NAMESPACE, TABLE)).thenReturn(metadata);

// Act
Throwable thrown =
catchThrowable(() -> admin.importTable(NAMESPACE, TABLE, Collections.emptyMap()));

// Assert
assertThat(thrown).isInstanceOf(IllegalArgumentException.class);
}

@Test
public void importTable_WithTransactionTableAlreadyExists_ShouldThrowIllegalArgumentException()
throws ExecutionException {
// Arrange
String primaryKeyColumn = "pk";
Expand Down

0 comments on commit 7eeffe2

Please sign in to comment.