Timm0 commented on code in PR #29838:
URL: https://github.com/apache/flink/pull/29838#discussion_r4549775142


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/materializedtable/QueryMaterializedTableMergeContext.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.api.internal.materializedtable;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.Schema;
+import 
org.apache.flink.table.catalog.CatalogMaterializedTable.LogicalRefreshMode;
+import org.apache.flink.table.catalog.IntervalFreshness;
+import org.apache.flink.table.catalog.ResolvedCatalogMaterializedTable;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.catalog.StartMode;
+import org.apache.flink.table.catalog.TableDistribution;
+import org.apache.flink.table.operations.QueryOperation;
+import 
org.apache.flink.table.operations.materializedtable.MaterializedTableMergeContext;
+import org.apache.flink.table.types.DataType;
+
+import javax.annotation.Nullable;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static 
org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType;
+
+/**
+ * The {@link MaterializedTableMergeContext} of {@code Table#materializeInto}, 
with the semantics of
+ * the equivalent {@code CREATE OR ALTER MATERIALIZED TABLE} statement.
+ */
+@Internal
+final class QueryMaterializedTableMergeContext implements 
MaterializedTableMergeContext {
+
+    private final QueryOperation queryOperation;
+    private final String serializedQuery;
+    private final @Nullable IntervalFreshness freshness;
+    private final ResolvedSchema querySchema;
+
+    QueryMaterializedTableMergeContext(
+            QueryOperation queryOperation,
+            String serializedQuery,
+            @Nullable IntervalFreshness freshness) {
+        this.queryOperation = queryOperation;
+        this.serializedQuery = serializedQuery;
+        this.freshness = freshness;
+        this.querySchema = 
toPhysicalSchema(queryOperation.getResolvedSchema());

Review Comment:
   `materializeInto` now parses the `serializedQuery` and stores the schema of 
that operation. This is exactly what SQL does as well, it validates it SQL text 
with Calcite and stores the schema of that plan. 
   I was also looking into comparing the stored schema with the Table's schema 
but that doesn't work, because the Table API and Calcite infer different types 
for the same query (e.g. nullability of window aggregates). This difference is 
not a problem, since now the the catalog entry and refresh job both come from 
the same SQL. I also added a test for this case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to