Skip to content

Commit

Permalink
update for CR
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoukangcn committed Apr 16, 2024
1 parent 4d344c4 commit 2c02688
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public class DorisExceptionConverter extends JdbcExceptionConverter {
private static final Pattern DATABASE_ALREADY_EXISTS_PATTERN =
Pattern.compile(DATABASE_ALREADY_EXISTS_PATTERN_STRING);

private static final String TABLE_NOT_EXIST_PATTERN_STRING =
".*detailMessage = Unknown table '.*' in .*:.*";

private static final Pattern TABLE_NOT_EXIST_PATTERN =
Pattern.compile(TABLE_NOT_EXIST_PATTERN_STRING);

@SuppressWarnings("FormatStringAnnotation")
@Override
public GravitinoRuntimeException toGravitinoException(SQLException se) {
Expand Down Expand Up @@ -70,6 +76,10 @@ static int getErrorCodeFromMessage(String message) {
return CODE_DATABASE_EXISTS;
}

if (TABLE_NOT_EXIST_PATTERN.matcher(message).matches()) {
return CODE_NO_SUCH_TABLE;
}

return CODE_OTHER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ protected String generateCreateTableSql(
// Add Partition Info
if (partitioning != null && partitioning.length > 0) {
// TODO: Add partitioning support
throw new UnsupportedOperationException("Currently we do not support Partitioning in Doris");
}

// Return the generated SQL statement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ public void testGetErrorCodeFromMessage() {
Assertions.assertEquals(
DorisExceptionConverter.CODE_DATABASE_EXISTS,
DorisExceptionConverter.getErrorCodeFromMessage(msg));

msg =
"errCode = 2, detailMessage = Unknown table 'table_name' in default_cluster:database_name";
Assertions.assertEquals(
DorisExceptionConverter.CODE_NO_SUCH_TABLE,
DorisExceptionConverter.getErrorCodeFromMessage(msg));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.datastrato.gravitino.catalog.jdbc.JdbcColumn;
import com.datastrato.gravitino.catalog.jdbc.JdbcTable;
import com.datastrato.gravitino.exceptions.NoSuchTableException;
import com.datastrato.gravitino.integration.test.util.GravitinoITUtils;
import com.datastrato.gravitino.rel.TableChange;
import com.datastrato.gravitino.rel.expressions.NamedReference;
Expand Down Expand Up @@ -35,10 +36,14 @@ public class DorisTableOperationsIT extends TestDorisAbstractIT {
private static final Type VARCHAR_255 = Types.VarCharType.of(255);
private static final Type VARCHAR_1024 = Types.VarCharType.of(1024);

private static Type INT = Types.IntegerType.get();
private static final Type INT = Types.IntegerType.get();

private static final String databaseName = GravitinoITUtils.genRandomName("doris_test_db");

private static final long MAX_WAIT = 5;

private static final long WAIT_INTERVAL = 1;

@BeforeAll
public static void startup() {
TestDorisAbstractIT.startup();
Expand Down Expand Up @@ -88,6 +93,19 @@ public void testBasicTableOperation() {
Assertions.assertTrue(listTables.contains(tableName));
JdbcTable load = TABLE_OPERATIONS.load(databaseName, tableName);
assertionsTableInfo(tableName, tableComment, columns, properties, indexes, load);

// rename table
String newName = GravitinoITUtils.genRandomName("new_table");
Assertions.assertDoesNotThrow(() -> TABLE_OPERATIONS.rename(databaseName, tableName, newName));
Assertions.assertDoesNotThrow(() -> TABLE_OPERATIONS.load(databaseName, newName));

Assertions.assertDoesNotThrow(() -> TABLE_OPERATIONS.drop(databaseName, newName));

listTables = TABLE_OPERATIONS.listTables(databaseName);
Assertions.assertFalse(listTables.contains(newName));

Assertions.assertThrows(
NoSuchTableException.class, () -> TABLE_OPERATIONS.drop(databaseName, newName));
}

@Test
Expand Down Expand Up @@ -141,8 +159,8 @@ public void testAlterTable() {
columns.add(col_3);

Awaitility.await()
.atMost(5, TimeUnit.SECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.atMost(MAX_WAIT, TimeUnit.SECONDS)
.pollInterval(WAIT_INTERVAL, TimeUnit.SECONDS)
.untilAsserted(
() ->
assertionsTableInfo(
Expand Down Expand Up @@ -188,8 +206,8 @@ public void testAlterTable() {
columns.add(col_3);
columns.add(col_4);
Awaitility.await()
.atMost(5, TimeUnit.SECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.atMost(MAX_WAIT, TimeUnit.SECONDS)
.pollInterval(WAIT_INTERVAL, TimeUnit.SECONDS)
.untilAsserted(
() ->
assertionsTableInfo(
Expand All @@ -213,8 +231,83 @@ public void testAlterTable() {
columns.add(col_4);
columns.add(col_3);
Awaitility.await()
.atMost(5, TimeUnit.SECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.atMost(MAX_WAIT, TimeUnit.SECONDS)
.pollInterval(WAIT_INTERVAL, TimeUnit.SECONDS)
.untilAsserted(
() ->
assertionsTableInfo(
tableName,
tableComment,
columns,
properties,
indexes,
TABLE_OPERATIONS.load(databaseName, tableName)));

// drop column if exist
TABLE_OPERATIONS.alterTable(
databaseName, tableName, TableChange.deleteColumn(new String[] {"col_4"}, true));
columns.clear();
columns.add(col_1);
columns.add(col_2);
columns.add(col_3);
Awaitility.await()
.atMost(MAX_WAIT, TimeUnit.SECONDS)
.pollInterval(WAIT_INTERVAL, TimeUnit.SECONDS)
.untilAsserted(
() ->
assertionsTableInfo(
tableName,
tableComment,
columns,
properties,
indexes,
TABLE_OPERATIONS.load(databaseName, tableName)));

// delete column that does not exist
IllegalArgumentException illegalArgumentException =
Assertions.assertThrows(
IllegalArgumentException.class,
() ->
TABLE_OPERATIONS.alterTable(
databaseName,
tableName,
TableChange.deleteColumn(new String[] {"col_4"}, false)));

Assertions.assertEquals(
"Delete column does not exist: col_4", illegalArgumentException.getMessage());
Assertions.assertDoesNotThrow(
() ->
TABLE_OPERATIONS.alterTable(
databaseName, tableName, TableChange.deleteColumn(new String[] {"col_4"}, true)));

// test add index
TABLE_OPERATIONS.alterTable(
databaseName,
tableName,
TableChange.addIndex(
Index.IndexType.PRIMARY_KEY, "k2_index", new String[][] {{"col_2"}, {"col_3"}}));

Index[] newIndexes =
new Index[] {Indexes.primary("k2_index", new String[][] {{"col_2"}, {"col_3"}})};
Awaitility.await()
.atMost(MAX_WAIT, TimeUnit.SECONDS)
.pollInterval(WAIT_INTERVAL, TimeUnit.SECONDS)
.untilAsserted(
() ->
assertionsTableInfo(
tableName,
tableComment,
columns,
properties,
newIndexes,
TABLE_OPERATIONS.load(databaseName, tableName)));

// test delete index
TABLE_OPERATIONS.alterTable(databaseName, tableName, TableChange.deleteIndex("k2_index", true));

Awaitility.await()
.atMost(MAX_WAIT, TimeUnit.SECONDS)
.pollInterval(WAIT_INTERVAL, TimeUnit.SECONDS)
.untilAsserted(
() ->
assertionsTableInfo(
Expand Down

0 comments on commit 2c02688

Please sign in to comment.