xuyangzhong commented on code in PR #24760: URL: https://github.com/apache/flink/pull/24760#discussion_r1594070565
########## flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/materializedtable/MaterializedTableManager.java: ########## @@ -169,6 +181,83 @@ private static void createMaterializedInContinuousMode( } } + private static ResultFetcher callAlterMaterializedTableRefreshOperation( + OperationExecutor operationExecutor, + OperationHandle handle, + AlterMaterializedTableRefreshOperation alterMaterializedTableRefreshOperation) { + ObjectIdentifier materializedTableIdentifier = + alterMaterializedTableRefreshOperation.getTableIdentifier(); + ResolvedCatalogBaseTable<?> table = operationExecutor.getTable(materializedTableIdentifier); + if (!(table instanceof ResolvedCatalogMaterializedTable)) { + throw new TableException( + String.format( + "The table '%s' is not a materialized table.", + materializedTableIdentifier)); + } + + ResolvedCatalogMaterializedTable materializedTable = + (ResolvedCatalogMaterializedTable) table; + + Map<String, String> partitionSpec = + alterMaterializedTableRefreshOperation.getPartitionSpec(); + + Set<String> allPartitionKeys = + new HashSet<>(((ResolvedCatalogMaterializedTable) table).getPartitionKeys()); + Set<String> unknownPartitionKeys = new HashSet<>(partitionSpec.keySet()); + unknownPartitionKeys.removeAll(allPartitionKeys); + if (!unknownPartitionKeys.isEmpty()) { + throw new TableException( + String.format( + "The partition spec contains unknown partition keys: %s.", + unknownPartitionKeys)); + } + + // Set job name, runtime mode, checkpoint interval + Configuration customConfig = new Configuration(); + String jobName = + String.format( + "Materialized_table_%s_one_time_refresh_job", + materializedTableIdentifier.asSerializableString()); + customConfig.set(NAME, jobName); + customConfig.set(RUNTIME_MODE, BATCH); + + StringBuilder insertStatement = + new StringBuilder( + String.format( + "INSERT INTO %s SELECT * FROM (%s)", + materializedTableIdentifier, + materializedTable.getDefinitionQuery())); + + if (!partitionSpec.isEmpty()) { + insertStatement.append(" WHERE "); + insertStatement.append( + partitionSpec.entrySet().stream() + .map( + entry -> + String.format( + "%s = '%s'", entry.getKey(), entry.getValue())) + .reduce((s1, s2) -> s1 + " AND " + s2) + .orElseThrow(() -> new TableException("Could not happen"))); + } + + try { + // return jobId for one time refresh, user should get the refresh job info via desc Review Comment: I want to note the developer the information about the syntax "alter materialized table ... refresh ..." returns before. I'll delete it. -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org