Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoukangcn committed Apr 13, 2024
1 parent 28307f5 commit f635302
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,26 @@ public String fromGravitinoType(Type type) {
} else if (type instanceof Types.TimestampType) {
return DATETIME;
} else if (type instanceof Types.VarCharType) {
int length = ((Types.VarCharType) type).length();
if (length < 1 || length > 65533) {
throw new IllegalArgumentException(
String.format(
"Type %s is invalid, length should be between 1 and 65533", type.simpleString()));
}
return VARCHAR + "(" + ((Types.VarCharType) type).length() + ")";
} else if (type instanceof Types.FixedCharType) {
int length = ((Types.FixedCharType) type).length();
if (length < 1 || length > 255) {
throw new IllegalArgumentException(
String.format(
"Type %s is invalid, length should be between 1 and 255", type.toString()));
"Type %s is invalid, length should be between 1 and 255", type.simpleString()));
}

return CHAR + "(" + ((Types.FixedCharType) type).length() + ")";
} else if (type instanceof Types.StringType) {
return STRING;
}
throw new IllegalArgumentException(
String.format("Couldn't convert Gravitino type %s to Doris type", type.toString()));
String.format("Couldn't convert Gravitino type %s to Doris type", type.simpleString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ protected String generateDropTableSql(String tableName) {

@Override
protected String generatePurgeTableSql(String tableName) {
return String.format("TRUNCATE TABLE `%s`", tableName);
throw new UnsupportedOperationException(
"Doris does not support purge table in Gravitino, please use drop table");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
import com.datastrato.gravitino.rel.expressions.distributions.Distribution;
import com.datastrato.gravitino.rel.expressions.distributions.Distributions;
import com.datastrato.gravitino.rel.indexes.Index;
import com.datastrato.gravitino.rel.indexes.Indexes;
import com.datastrato.gravitino.rel.types.Type;
import com.datastrato.gravitino.rel.types.Types;
import com.datastrato.gravitino.utils.RandomNameUtils;
import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -225,7 +228,7 @@ public void testAlterTable() {

@Test
public void testCreateAllTypeTable() {
String tableName = GravitinoITUtils.genRandomName("type_table");
String tableName = GravitinoITUtils.genRandomName("all_type_table");
String tableComment = "test_comment";
List<JdbcColumn> columns = new ArrayList<>();
columns.add(JdbcColumn.builder().withName("col_1").withType(Types.IntegerType.get()).build());
Expand Down Expand Up @@ -260,4 +263,51 @@ public void testCreateAllTypeTable() {
JdbcTable load = TABLE_OPERATIONS.load(databaseName, tableName);
assertionsTableInfo(tableName, tableComment, columns, Collections.emptyMap(), null, load);
}

@Test
public void testCreateNotSupportTypeTable() {
String tableName = RandomNameUtils.genRandomName("unspport_type_table");
String tableComment = "test_comment";
List<JdbcColumn> columns = new ArrayList<>();
List<Type> notSupportType =
Arrays.asList(
Types.FixedType.of(10),
Types.IntervalDayType.get(),
Types.IntervalYearType.get(),
Types.UUIDType.get(),
Types.ListType.of(Types.DateType.get(), true),
Types.MapType.of(Types.StringType.get(), Types.IntegerType.get(), true),
Types.UnionType.of(Types.IntegerType.get()),
Types.StructType.of(
Types.StructType.Field.notNullField("col_1", Types.IntegerType.get())));

for (Type type : notSupportType) {
columns.clear();
columns.add(JdbcColumn.builder().withName("col_1").withType(Types.IntegerType.get()).build());
columns.add(
JdbcColumn.builder().withName("col_2").withType(type).withNullable(false).build());

JdbcColumn[] jdbcCols = columns.toArray(new JdbcColumn[0]);
IllegalArgumentException illegalArgumentException =
Assertions.assertThrows(
IllegalArgumentException.class,
() -> {
TABLE_OPERATIONS.create(
databaseName,
tableName,
jdbcCols,
tableComment,
createProperties(),
null,
Distributions.hash(32, NamedReference.field("col_1")),
Indexes.EMPTY_INDEXES);
});
Assertions.assertTrue(
illegalArgumentException
.getMessage()
.contains(
String.format(
"Couldn't convert Gravitino type %s to Doris type", type.simpleString())));
}
}
}

0 comments on commit f635302

Please sign in to comment.