snuyanzin commented on code in PR #27132:
URL: https://github.com/apache/flink/pull/27132#discussion_r2444398502


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/operations/SqlMaterializedTableNodeToOperationConverterTest.java:
##########
@@ -146,13 +146,123 @@ void testCreateMaterializedTable() {
                         .partitionKeys(Arrays.asList("a", "d"))
                         .freshness(IntervalFreshness.ofSecond("30"))
                         
.logicalRefreshMode(CatalogMaterializedTable.LogicalRefreshMode.FULL)
-                        .refreshMode(CatalogMaterializedTable.RefreshMode.FULL)
+                        .refreshMode(RefreshMode.FULL)
+                        
.refreshStatus(CatalogMaterializedTable.RefreshStatus.INITIALIZING)
+                        .definitionQuery(
+                                "SELECT `t1`.`a`, `t1`.`b`, `t1`.`c`, 
`t1`.`d`\n"
+                                        + "FROM `builtin`.`default`.`t1` AS 
`t1`")
+                        .build();
+
+        final IntervalFreshness resolvedFreshness = 
materializedTable.getDefinitionFreshness();
+        
assertThat(resolvedFreshness).isEqualTo(IntervalFreshness.ofSecond("30"));
+
+        final RefreshMode resolvedRefreshMode = 
materializedTable.getRefreshMode();
+        assertThat(resolvedRefreshMode).isEqualTo(RefreshMode.FULL);
+
+        assertThat(materializedTable.getOrigin()).isEqualTo(expected);
+    }
+
+    @Test
+    void testCreateMaterializedTableWithoutFreshness() {
+        final String sql =
+                "CREATE MATERIALIZED TABLE mtbl1 (\n"
+                        + "   CONSTRAINT ct1 PRIMARY KEY(a) NOT ENFORCED"
+                        + ")\n"
+                        + "COMMENT 'materialized table comment'\n"
+                        + "PARTITIONED BY (a, d)\n"
+                        + "WITH (\n"
+                        + "  'connector' = 'filesystem', \n"
+                        + "  'format' = 'json'\n"
+                        + ")\n"
+                        + "REFRESH_MODE = FULL\n"
+                        + "AS SELECT * FROM t1";
+        Operation operation = parse(sql);
+        
assertThat(operation).isInstanceOf(CreateMaterializedTableOperation.class);
+
+        CreateMaterializedTableOperation op = 
(CreateMaterializedTableOperation) operation;
+        ResolvedCatalogMaterializedTable materializedTable = 
op.getCatalogMaterializedTable();
+        
assertThat(materializedTable).isInstanceOf(ResolvedCatalogMaterializedTable.class);
+
+        Map<String, String> options = Map.of("connector", "filesystem", 
"format", "json");
+
+        CatalogMaterializedTable expected =
+                CatalogMaterializedTable.newBuilder()
+                        .schema(
+                                Schema.newBuilder()
+                                        .column("a", 
DataTypes.BIGINT().notNull())
+                                        .column("b", 
DataTypes.VARCHAR(Integer.MAX_VALUE))
+                                        .column("c", DataTypes.INT())
+                                        .column("d", 
DataTypes.VARCHAR(Integer.MAX_VALUE))
+                                        .primaryKeyNamed("ct1", 
Collections.singletonList("a"))
+                                        .build())
+                        .comment("materialized table comment")
+                        .options(options)
+                        .partitionKeys(Arrays.asList("a", "d"))
+                        .logicalRefreshMode(LogicalRefreshMode.FULL)
+                        .freshness(null)
+                        .refreshMode(RefreshMode.FULL)
+                        
.refreshStatus(CatalogMaterializedTable.RefreshStatus.INITIALIZING)
+                        .definitionQuery(
+                                "SELECT `t1`.`a`, `t1`.`b`, `t1`.`c`, 
`t1`.`d`\n"
+                                        + "FROM `builtin`.`default`.`t1` AS 
`t1`")
+                        .build();
+
+        // The resolved freshness should default to 1 minute
+        final IntervalFreshness resolvedFreshness = 
materializedTable.getDefinitionFreshness();
+        assertThat(resolvedFreshness).isEqualTo(IntervalFreshness.ofHour("1"));
+
+        final RefreshMode resolvedRefreshMode = 
materializedTable.getRefreshMode();
+        assertThat(resolvedRefreshMode).isEqualTo(RefreshMode.FULL);
+
+        assertThat(materializedTable.getOrigin()).isEqualTo(expected);
+    }
+
+    @Test
+    void testCreateMaterializedTableWithoutFreshnessAndRefreshMode() {
+        final String sql =
+                "CREATE MATERIALIZED TABLE mtbl1 (\n"
+                        + "   CONSTRAINT ct1 PRIMARY KEY(a) NOT ENFORCED"
+                        + ")\n"
+                        + "COMMENT 'materialized table comment'\n"
+                        + "PARTITIONED BY (a, d)\n"
+                        + "WITH (\n"
+                        + "  'connector' = 'filesystem', \n"
+                        + "  'format' = 'json'\n"
+                        + ")\n"
+                        + "AS SELECT * FROM t1";
+        Operation operation = parse(sql);
+        
assertThat(operation).isInstanceOf(CreateMaterializedTableOperation.class);
+
+        CreateMaterializedTableOperation op = 
(CreateMaterializedTableOperation) operation;
+        ResolvedCatalogMaterializedTable materializedTable = 
op.getCatalogMaterializedTable();
+        
assertThat(materializedTable).isInstanceOf(ResolvedCatalogMaterializedTable.class);
+
+        Map<String, String> options = Map.of("connector", "filesystem", 
"format", "json");
+
+        CatalogMaterializedTable expected =
+                CatalogMaterializedTable.newBuilder()
+                        .schema(
+                                Schema.newBuilder()
+                                        .column("a", 
DataTypes.BIGINT().notNull())
+                                        .column("b", 
DataTypes.VARCHAR(Integer.MAX_VALUE))
+                                        .column("c", DataTypes.INT())
+                                        .column("d", 
DataTypes.VARCHAR(Integer.MAX_VALUE))
+                                        .primaryKeyNamed("ct1", 
Collections.singletonList("a"))
+                                        .build())
+                        .comment("materialized table comment")
+                        .options(options)
+                        .partitionKeys(Arrays.asList("a", "d"))
+                        .logicalRefreshMode(LogicalRefreshMode.AUTOMATIC)
+                        .freshness(null)
+                        .refreshMode(null)

Review Comment:
   do we need it?
   What values would be if we don't put here `null` s explicitly?



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