Skip to content

Commit

Permalink
[hotfix][table-common] Provide Schema.derived() for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
twalthr committed Aug 25, 2021
1 parent a3f6821 commit 3510e26
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,30 @@ public void testOutputToNoSchema() {
assertEquals(Optional.empty(), result.getPhysicalDataType());
}

@Test
public void testOutputToEmptySchema() {
final ResolvedSchema tableSchema =
ResolvedSchema.of(
Column.physical("id", DataTypes.BIGINT()),
Column.metadata("rowtime", DataTypes.TIMESTAMP_LTZ(3), null, false),
Column.physical("name", DataTypes.STRING()));

final ProducingResult result =
SchemaTranslator.createProducingResult(tableSchema, Schema.derived());

assertEquals(Optional.empty(), result.getProjections());

assertEquals(
Schema.newBuilder()
.column("id", DataTypes.BIGINT())
.column("rowtime", DataTypes.TIMESTAMP_LTZ(3)) // becomes physical
.column("name", DataTypes.STRING())
.build(),
result.getSchema());

assertEquals(Optional.empty(), result.getPhysicalDataType());
}

@Test
public void testOutputToMetadataSchema() {
final ResolvedSchema tableSchema =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
@PublicEvolving
public final class Schema {

private static final Schema EMPTY = Schema.newBuilder().build();

private final List<UnresolvedColumn> columns;

private final List<UnresolvedWatermarkSpec> watermarkSpecs;
Expand All @@ -91,6 +93,19 @@ public static Schema.Builder newBuilder() {
return new Builder();
}

/**
* Convenience method for stating explicitly that a schema is empty and should be fully derived
* by the framework.
*
* <p>The semantics are equivalent to calling {@code Schema.newBuilder().build()}.
*
* <p>Note that derivation depends on the context. Usually, the method that accepts a {@link
* Schema} instance will mention whether schema derivation is supported or not.
*/
public static Schema derived() {
return EMPTY;
}

public List<UnresolvedColumn> getColumns() {
return columns;
}
Expand Down

0 comments on commit 3510e26

Please sign in to comment.