Skip to content

Commit

Permalink
chore: add some unit test for TableSchela
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun committed Feb 2, 2024
1 parent d17a218 commit ced4c5d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public Builder addTag(String name, DataType dataType) {
* @return this builder
*/
public Builder addTimestamp(String name, DataType dataType) {
Ensures.ensure(dataType.isTimestamp(), "Invalid timestamp data type");
Ensures.ensure(dataType.isTimestamp(),
"Invalid timestamp data type: %s, only support `DataType.TimestampXXX`", dataType);
return addColumn(name, SemanticType.Timestamp, dataType);
}

Expand Down Expand Up @@ -139,7 +140,8 @@ public Builder addColumn(String name, //
Ensures.ensureNonNull(dataType, "Null data type");

if (semanticType == SemanticType.Timestamp) {
Ensures.ensure(dataType.isTimestamp(), "Invalid timestamp data type");
Ensures.ensure(dataType.isTimestamp(),
"Invalid timestamp data type: %s, only support `DataType.TimestampXXX`", dataType);
}

this.columnNames.add(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
/**
* @author jiachun.fjc
*/
public class TableTest {
public class TableSchemaTest {

@Test
public void testTableNonNull() {
public void testNonNull() {
TableSchema schema = TableSchema.newBuilder("test_table") //
.addTag("col1", DataType.String) //
.addTag("col2", DataType.String) //
Expand All @@ -54,7 +54,7 @@ public void testTableNonNull() {
}

@Test
public void testTableSomeNull() {
public void testSomeNull() {
TableSchema schema = TableSchema.newBuilder("test_table") //
.addTag("col1", DataType.String) //
.addTag("col2", DataType.String) //
Expand All @@ -73,4 +73,35 @@ public void testTableSomeNull() {
Assert.assertFalse(rawRows.getRows(2).getValues(2).hasI32Value());
Assert.assertFalse(rawRows.getRows(1).getValues(1).hasStringValue());
}


@Test
public void testNotSupportTimestamp() {
TableSchema.Builder builder = TableSchema.newBuilder("test_table") //
.addTag("col1", DataType.String) //
.addTag("col2", DataType.String) //
.addField("col3", DataType.Int32);

try {
builder.addTimestamp("col4", DataType.Int32);
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("Invalid timestamp data type"));
}
}

@Test
public void testNotSupportDecimalExtension() {
TableSchema.Builder builder = TableSchema.newBuilder("test_table") //
.addTag("col1", DataType.String) //
.addTag("col2", DataType.String) //
.addField("col3", DataType.Int32);

try {
builder.addColumn("col4", SemanticType.Field, DataType.Float64, new DataType.DecimalTypeExtension(39, 9));
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("Only decimal type can have decimal type extension"));
}
}
}

0 comments on commit ced4c5d

Please sign in to comment.