Skip to content

Commit

Permalink
fix: allow empty structs in schema inference (#5656)
Browse files Browse the repository at this point in the history
  • Loading branch information
agavra committed Jun 19, 2020
1 parent b5cc092 commit 3c38c8c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ public String visitMap(final Schema schema, final String key, final String value
}

public String visitStruct(final Schema schema, final List<? extends String> fields) {
if (fields.isEmpty()) {
return "STRUCT< >";
}
return fields.stream()
.collect(Collectors.joining(", ", STRUCT_START, STRUCTURED_END));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ public void shouldFormatOptionalMap() {
assertThat(STRICT.format(schema), is("MAP<VARCHAR, DOUBLE>"));
}

@Test
public void shouldFormatEmptyStruct() {
// Given:
final Schema struct = SchemaBuilder.struct().optional().build();

// Then:
assertThat(DEFAULT.format(struct), is("STRUCT< >"));
}

@Test
public void shouldFormatStruct() {
// Given:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ public void shouldIgnoreConnectMapWithUnsupportedKey() {
);
}

@Test
public void shouldInferEmptyStruct() {
final Schema emptyStruct = SchemaBuilder.struct().optional().build();
shouldInferConnectType(emptyStruct, emptyStruct);
}

@Test
public void shouldInferComplexConnectSchema() {
final Schema arrayInner = SchemaBuilder.struct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
} ],
"schemas" : {
"CSAS_BIG_STRUCT_0.KsqlTopic.Source" : "STRUCT<COL1 VARCHAR> NOT NULL",
"CSAS_BIG_STRUCT_0.BIG_STRUCT" : "STRUCT<S STRUCT<>> NOT NULL"
"CSAS_BIG_STRUCT_0.BIG_STRUCT" : "STRUCT<S STRUCT< >> NOT NULL"
},
"configs" : {
"ksql.extension.dir" : "ext",
Expand Down

0 comments on commit 3c38c8c

Please sign in to comment.