use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy in project flink by apache.
the class MergeTableLikeUtilTest method mergeOverwritingMetadataColumnsDuplicate.
@Test
public void mergeOverwritingMetadataColumnsDuplicate() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.metadata("two", DataTypes.INT())).build();
List<SqlNode> derivedColumns = Collections.singletonList(metadataColumn("two", DataTypes.BOOLEAN(), true));
Map<FeatureOption, MergingStrategy> mergingStrategies = getDefaultMergingStrategies();
mergingStrategies.put(FeatureOption.METADATA, MergingStrategy.OVERWRITING);
TableSchema mergedSchema = util.mergeTables(mergingStrategies, sourceSchema, derivedColumns, Collections.emptyList(), null);
TableSchema expectedSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.metadata("two", DataTypes.BOOLEAN(), true)).build();
assertThat(mergedSchema, equalTo(expectedSchema));
}
use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy in project flink by apache.
the class MergeTableLikeUtilTest method mergeOverwritingGeneratedColumnsDuplicate.
@Test
public void mergeOverwritingGeneratedColumnsDuplicate() {
TableSchema sourceSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.computed("two", DataTypes.INT(), "one + 1")).build();
List<SqlNode> derivedColumns = Collections.singletonList(computedColumn("two", plus("one", "3")));
Map<FeatureOption, MergingStrategy> mergingStrategies = getDefaultMergingStrategies();
mergingStrategies.put(FeatureOption.GENERATED, MergingStrategy.OVERWRITING);
TableSchema mergedSchema = util.mergeTables(mergingStrategies, sourceSchema, derivedColumns, Collections.emptyList(), null);
TableSchema expectedSchema = TableSchema.builder().add(TableColumn.physical("one", DataTypes.INT())).add(TableColumn.computed("two", DataTypes.INT(), "`one` + 3")).build();
assertThat(mergedSchema, equalTo(expectedSchema));
}
use of org.apache.flink.sql.parser.ddl.SqlTableLike.MergingStrategy in project flink by apache.
the class MergeTableLikeUtil method computeMergingStrategies.
/**
* Calculates merging strategies for all options. It applies options given by a user to the
* {@link #defaultMergingStrategies}. The {@link MergingStrategy} specified for {@link
* FeatureOption#ALL} overwrites all the default options. Those can be further changed with a
* specific {@link FeatureOption}.
*/
public Map<FeatureOption, MergingStrategy> computeMergingStrategies(List<SqlTableLike.SqlTableLikeOption> mergingOptions) {
Map<FeatureOption, MergingStrategy> result = new HashMap<>(defaultMergingStrategies);
Optional<SqlTableLike.SqlTableLikeOption> maybeAllOption = mergingOptions.stream().filter(option -> option.getFeatureOption() == FeatureOption.ALL).findFirst();
maybeAllOption.ifPresent((allOption) -> {
MergingStrategy strategy = allOption.getMergingStrategy();
for (FeatureOption featureOption : FeatureOption.values()) {
if (featureOption != FeatureOption.ALL) {
result.put(featureOption, strategy);
}
}
});
for (SqlTableLike.SqlTableLikeOption mergingOption : mergingOptions) {
result.put(mergingOption.getFeatureOption(), mergingOption.getMergingStrategy());
}
return result;
}
Aggregations