hackergin commented on code in PR #24700:
URL: https://github.com/apache/flink/pull/24700#discussion_r1577583807


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/CatalogMaterializedTable.java:
##########
@@ -0,0 +1,280 @@
+/*
+ * 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.catalog;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.util.Preconditions;
+
+import javax.annotation.Nullable;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Represents the unresolved metadata of a materialized table in a {@link 
Catalog}.
+ *
+ * <p>Materialized Table definition: In the context of streaming-batch unified 
storage, it provides
+ * full history data and incremental changelog. By defining the data's 
production business logic and
+ * freshness, data refresh is achieved through continuous or full refresh 
pipeline, while also
+ * possessing the capability for both batch and incremental consumption.
+ *
+ * <p>The metadata for {@link CatalogMaterializedTable} includes the following 
four main parts:
+ *
+ * <ul>
+ *   <li>Schema, comments, options and partition keys.
+ *   <li>Data freshness, which determines when the data is generated and 
becomes visible for user.
+ *   <li>Data production business logic, also known as the definition query.
+ *   <li>Background refresh pipeline, either through a flink streaming or 
periodic flink batch job,
+ *       it is initialized after materialized table is created.
+ * </ul>
+ */
+@PublicEvolving
+public interface CatalogMaterializedTable extends CatalogBaseTable {
+
+    /** Builder for configuring and creating instances of {@link 
CatalogMaterializedTable}. */
+    @PublicEvolving
+    static CatalogMaterializedTable.Builder newBuilder() {
+        return new CatalogMaterializedTable.Builder();
+    }
+
+    @Override
+    default TableKind getTableKind() {
+        return TableKind.MATERIALIZED_TABLE;
+    }
+
+    /**
+     * Check if the table is partitioned or not.
+     *
+     * @return true if the table is partitioned; otherwise, false
+     */
+    boolean isPartitioned();
+
+    /**
+     * Get the partition keys of the table. This will be an empty set if the 
table is not
+     * partitioned.
+     *
+     * @return partition keys of the table
+     */
+    List<String> getPartitionKeys();
+
+    /**
+     * Returns a copy of this {@code CatalogMaterializedTable} with given 
table options {@code
+     * options}.
+     *
+     * @return a new copy of this table with replaced table options
+     */
+    CatalogMaterializedTable copy(Map<String, String> options);
+
+    /**
+     * Returns a copy of this {@code CatalogDynamicTable} with given refresh 
info.
+     *
+     * @return a new copy of this table with replaced refresh info
+     */
+    CatalogMaterializedTable copy(
+            RefreshStatus refreshStatus,
+            String refreshHandlerDescription,
+            byte[] serializedRefreshHandler);
+
+    /** Return the snapshot specified for the table. Return Optional.empty() 
if not specified. */
+    Optional<Long> getSnapshot();
+
+    /**
+     * The definition query text of materialized table, text is expanded in 
contrast to the original
+     * SQL. This is needed because the context such as current DB is lost 
after the session, in
+     * which view is defined, is gone. Expanded query text takes care of this, 
as an example.
+     *
+     * <p>For example, for a dynamic table that is defined in the context of 
"default" database with

Review Comment:
   ```suggestion
        * <p>For example, for a materialized table that is defined in the 
context of "default" database with
   ```



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/refresh/RefreshHandlerSerializer.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.refresh;
+
+import org.apache.flink.annotation.PublicEvolving;
+
+import java.io.IOException;
+
+/** This interface is used to serialize and deserialize the {@link 
RefreshHandler}. */
+@PublicEvolving
+public interface RefreshHandlerSerializer<T extends RefreshHandler> {
+
+    /** Serialize the {@link RefreshHandler} to bytes. */

Review Comment:
   ```suggestion
       /** Serialize the {@link RefreshHandler} instance to bytes. */
   ```



##########
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/CatalogBaseTableResolutionTest.java:
##########
@@ -140,6 +165,30 @@ void testCatalogTableResolution() {
         assertThat(resolvedTable.getSchema()).isEqualTo(LEGACY_TABLE_SCHEMA);
     }
 
+    @Test
+    void testCatalogMaterializedTableResolution() {
+        final CatalogMaterializedTable materializedTable = 
catalogMaterializedTable();
+
+        assertThat(materializedTable.getUnresolvedSchema()).isNotNull();
+
+        final ResolvedCatalogMaterializedTable resolvedMaterializedTable =
+                
resolveCatalogBaseTable(ResolvedCatalogMaterializedTable.class, 
materializedTable);
+
+        assertThat(resolvedMaterializedTable.getResolvedSchema())

Review Comment:
   Can we directly support the comparison of ResolvedCatalogMaterializedTable 
here, without the need to compare its sub-objects?
   
   



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/DefaultCatalogMaterializedTable.java:
##########
@@ -0,0 +1,291 @@
+/*
+ * 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.catalog;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.api.Schema;
+
+import javax.annotation.Nullable;
+
+import java.time.Duration;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Default implementation of a {@link CatalogMaterializedTable}. */
+@Internal
+public class DefaultCatalogMaterializedTable implements 
CatalogMaterializedTable {
+
+    private final Schema schema;
+    private final @Nullable String comment;
+    private final List<String> partitionKeys;
+    private final Map<String, String> options;
+
+    private final @Nullable Long snapshot;
+
+    private final String definitionQuery;
+    private final Duration freshness;
+    private final LogicalRefreshMode logicalRefreshMode;
+    private final RefreshMode refreshMode;
+    private final RefreshStatus refreshStatus;
+    private final @Nullable String refreshHandlerDescription;
+    private final @Nullable byte[] serializedRefreshHandler;
+
+    protected DefaultCatalogMaterializedTable(
+            Schema schema,
+            @Nullable String comment,
+            List<String> partitionKeys,
+            Map<String, String> options,
+            @Nullable Long snapshot,
+            String definitionQuery,
+            Duration freshness,
+            LogicalRefreshMode logicalRefreshMode,
+            RefreshMode refreshMode,
+            RefreshStatus refreshStatus,
+            @Nullable String refreshHandlerDescription,
+            @Nullable byte[] serializedRefreshHandler) {
+        this.schema = checkNotNull(schema, "Schema must not be null.");
+        this.comment = comment;
+        this.partitionKeys = checkNotNull(partitionKeys, "Partition keys must 
not be null.");
+        this.options = checkNotNull(options, "Options must not be null.");
+        this.snapshot = snapshot;
+        this.definitionQuery = definitionQuery;

Review Comment:
   Do we need to add a "not null" check here for  definitionQuery, freshness, 
logicalRefreshMode ? 



-- 
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