Skip to content

Commit

Permalink
[FLINK-37098] Fix UnresolvedSchema of QueryOperationCatalogView
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidwys committed Jan 21, 2025
1 parent 632f3fe commit e000678
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ public QueryOperation getQueryOperation() {

@Override
public Schema getUnresolvedSchema() {
return Schema.newBuilder().fromResolvedSchema(queryOperation.getResolvedSchema()).build();
return Optional.ofNullable(originalView)
.map(CatalogView::getUnresolvedSchema)
.orElseGet(
() ->
Schema.newBuilder()
.fromResolvedSchema(queryOperation.getResolvedSchema())
.build());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

import static org.apache.flink.table.api.Expressions.$;
import static org.apache.flink.table.api.Expressions.lit;
import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for resolving types of computed columns (including time attributes) of tables from catalog.
Expand Down Expand Up @@ -202,6 +203,28 @@ void testTimeAttributeOfViewSelect() {
testUtil.verifyExecPlan("SELECT * FROM `cat`.`default`.v");
}

@TestTemplate
void testShowCreateViewUsesCorrectColumnNames() {
TableTestUtil testUtil = getTestUtil();
TableEnvironment tableEnvironment = testUtil.getTableEnv();
tableEnvironment.registerCatalog("cat", new CustomCatalog("cat"));
tableEnvironment.executeSql(
"CREATE VIEW `cat`.`default`.v (`customer_id`, `product_id`) AS " + "SELECT 1, 1");
String result =
tableEnvironment
.executeSql("SHOW CREATE VIEW `cat`.`default`.v")
.collect()
.next()
.getFieldAs(0);
assertThat(result)
.isEqualTo(
"CREATE VIEW `cat`.`default`.`v` (\n"
+ " `customer_id`,\n"
+ " `product_id`\n"
+ ")\n"
+ "AS SELECT 1, 1\n");
}

private static class CustomCatalog extends GenericInMemoryCatalog {
public CustomCatalog(String name) {
super(name);
Expand Down

0 comments on commit e000678

Please sign in to comment.