Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ static <T> T convertValue(Object rawValue, Class<T> clazz) {
return (T) convertToFloat(rawValue);
} else if (Double.class.equals(clazz)) {
return (T) convertToDouble(rawValue);
} else if (Object.class.equals(clazz)) {
return (T) rawValue;
}
throw new IllegalArgumentException("Unsupported type: " + clazz);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ public void testBasicListOption() {
list, config.get(Options.key("option.list-str").listType().noDefaultValue()));
}

@Test
public void testObjectType() {
Assertions.assertEquals(
"Hello, Apache SeaTunnel",
config.get(Options.key("option.string").objectType(Object.class).noDefaultValue()));
Assertions.assertEquals(
true,
config.get(Options.key("option.bool").objectType(Object.class).noDefaultValue()));
Assertions.assertEquals(
3.3333,
config.get(Options.key("option.float").objectType(Object.class).noDefaultValue()));
Assertions.assertEquals(
21474836470L,
config.get(Options.key("option.long").objectType(Object.class).noDefaultValue()));
}

@Test
public void testComplexTypeOption() {
List<Map<String, Map<String, List<Map<String, Object>>>>> complexType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@

class ReadonlyConfigParserTest extends BaseConfigParserTest {

private final String columnConfig = "/conf/catalog/schema_column.conf";
private final String fieldConfig = "/conf/catalog/schema_field.conf";
private static final String COLUMN_CONFIG = "/conf/catalog/schema_column.conf";
private static final String FIELD_CONFIG = "/conf/catalog/schema_field.conf";

@Test
void parseColumn() throws FileNotFoundException, URISyntaxException {
ReadonlyConfig config = getReadonlyConfig(columnConfig);
ReadonlyConfig config = getReadonlyConfig(COLUMN_CONFIG);

ReadonlyConfigParser readonlyConfigParser = new ReadonlyConfigParser();
TableSchema tableSchema = readonlyConfigParser.parse(config);
assertPrimaryKey(tableSchema);
assertConstraintKey(tableSchema);
assertColumn(tableSchema);
assertColumn(tableSchema, true);
}

@Test
void parseField() throws FileNotFoundException, URISyntaxException {
ReadonlyConfig config = getReadonlyConfig(fieldConfig);
ReadonlyConfig config = getReadonlyConfig(FIELD_CONFIG);

ReadonlyConfigParser readonlyConfigParser = new ReadonlyConfigParser();
TableSchema tableSchema = readonlyConfigParser.parse(config);
assertPrimaryKey(tableSchema);
assertConstraintKey(tableSchema);
assertColumn(tableSchema);
assertColumn(tableSchema, false);
}

private void assertPrimaryKey(TableSchema tableSchema) {
Expand All @@ -77,7 +77,7 @@ private void assertConstraintKey(TableSchema tableSchema) {
constraintKey.getColumnNames().get(0).getSortType());
}

private void assertColumn(TableSchema tableSchema) {
private void assertColumn(TableSchema tableSchema, boolean checkDefaultValue) {
List<Column> columns = tableSchema.getColumns();
Assertions.assertEquals(19, columns.size());

Expand Down Expand Up @@ -108,5 +108,13 @@ private void assertColumn(TableSchema tableSchema) {

SeaTunnelRowType seatunnalRowType1 = (SeaTunnelRowType) seaTunnelRowType.getFieldType(17);
Assertions.assertEquals(17, seatunnalRowType1.getTotalFields());

if (checkDefaultValue) {
Assertions.assertEquals(0, columns.get(0).getDefaultValue());
Assertions.assertEquals("I'm default value", columns.get(4).getDefaultValue());
Assertions.assertEquals(false, columns.get(5).getDefaultValue());
Assertions.assertEquals(1.1, columns.get(10).getDefaultValue());
Assertions.assertEquals("2020-01-01", columns.get(15).getDefaultValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ schema = {
name = string
type = "string"
nullable = true
defaultValue = "I'm default value"
comment = "string value"
},
{
name = boolean
type = "boolean"
nullable = true
defaultValue = false
comment = "boolean value"
},
{
Expand Down Expand Up @@ -82,6 +84,7 @@ schema = {
name = float
type = "float"
nullable = true
defaultValue = 1.1
comment = "float value"
},
{
Expand Down Expand Up @@ -112,6 +115,7 @@ schema = {
name = date
type = "date"
nullable = true
defaultValue = "2020-01-01"
comment = "date value"
},
{
Expand Down