From ced4c5da0a58ca7b00a3ec714d5a69b619288814 Mon Sep 17 00:00:00 2001 From: jeremyhi Date: Fri, 2 Feb 2024 17:10:37 +0800 Subject: [PATCH] chore: add some unit test for TableSchela --- .../java/io/greptime/models/TableSchema.java | 6 ++- .../{TableTest.java => TableSchemaTest.java} | 37 +++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) rename ingester-protocol/src/test/java/io/greptime/models/{TableTest.java => TableSchemaTest.java} (71%) diff --git a/ingester-protocol/src/main/java/io/greptime/models/TableSchema.java b/ingester-protocol/src/main/java/io/greptime/models/TableSchema.java index 659358b..16ce06c 100644 --- a/ingester-protocol/src/main/java/io/greptime/models/TableSchema.java +++ b/ingester-protocol/src/main/java/io/greptime/models/TableSchema.java @@ -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); } @@ -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); diff --git a/ingester-protocol/src/test/java/io/greptime/models/TableTest.java b/ingester-protocol/src/test/java/io/greptime/models/TableSchemaTest.java similarity index 71% rename from ingester-protocol/src/test/java/io/greptime/models/TableTest.java rename to ingester-protocol/src/test/java/io/greptime/models/TableSchemaTest.java index cdcd7dc..97155df 100644 --- a/ingester-protocol/src/test/java/io/greptime/models/TableTest.java +++ b/ingester-protocol/src/test/java/io/greptime/models/TableSchemaTest.java @@ -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) // @@ -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) // @@ -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")); + } + } }