Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow empty structs in schema inference #5656

Merged
merged 3 commits into from
Jun 19, 2020
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 @@ -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< >";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, what does the below collector return with empty fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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