AHeise commented on code in PR #29994:
URL: https://github.com/apache/flink/pull/29994#discussion_r4680045989
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/materializedtable/MaterializedTableImpl.java:
##########
@@ -20,25 +20,108 @@
import org.apache.flink.annotation.Internal;
import org.apache.flink.table.api.MaterializedTable;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.api.internal.TableEnvironmentInternal;
+import org.apache.flink.table.catalog.CatalogBaseTable.TableKind;
+import org.apache.flink.table.catalog.CatalogManager;
+import org.apache.flink.table.catalog.CatalogMaterializedTable.RefreshMode;
+import org.apache.flink.table.catalog.CatalogMaterializedTable.RefreshStatus;
+import org.apache.flink.table.catalog.ContextResolvedTable;
+import org.apache.flink.table.catalog.IntervalFreshness;
import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.ResolvedCatalogMaterializedTable;
+
+import java.util.Optional;
/** Implementation of {@link MaterializedTable}. */
@Internal
-final class MaterializedTableImpl implements MaterializedTable {
+public final class MaterializedTableImpl implements MaterializedTable {
+
+ private final TableEnvironmentInternal tableEnvironment;
+ private final ContextResolvedTable snapshot;
Review Comment:
FLIP-616 specifies a handle that only holds the identifier:
> The handle only holds the identifier. Every getter and every operation
reads the catalog at call time, so a `suspend()`, `alter` or `drop` made
elsewhere is visible on the next call. [...] Separate getter calls are not read
atomically. Once the table is dropped, `getIdentifier()` keeps working,
`drop(true)` returns `false`, and every other call fails with a
`ValidationException`. If a new materialized table is later created at the same
path, the handle addresses it.
With the snapshot, `getOriginalQuery`, `getExpandedQuery`, `getFreshness`
and `getRefreshMode` still return the old values after an alter, a drop or a
re-create. That also breaks the FLIP's "Adjusting the query" journey, which
calls `silver.alter()...execute()` and then `silver.getExpandedQuery()` on the
same handle.
Could we keep only the `ObjectIdentifier` and resolve on every getter?
`of()` can still call `lookUp` once, so `fromMaterializedTable` keeps its
`@throws`. It also makes the class a bit smaller: no `snapshot` field and no
`resolvedSnapshot()`. If you'd rather keep the snapshot, it needs a FLIP update
and a note on the dev list, since it changes voted behavior.
This would also change the class Javadoc in `MaterializedTable` ("keeps the
definition that was read when it was created"), the docs paragraph in
`table-api.md` (en and zh), and
`testDefinitionIsKeptAndRefreshStateIsReadLive`, which should then assert that
the new query is visible.
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/materializedtable/MaterializedPipelineImpl.java:
##########
@@ -97,7 +97,7 @@ public MaterializedTable execute(CreateMode mode) {
Preconditions.checkNotNull(mode, "Create mode must not be null.");
final Mode finalOperationMode = toFactoryMode(mode);
tableEnvironment.executeInternal(buildOperation(finalOperationMode));
- return new MaterializedTableImpl(identifier);
+ return MaterializedTableImpl.of(tableEnvironment, identifier);
Review Comment:
Optional: with an identifier-only handle, `execute()` doesn't need to look
the table up again. As written, if that lookup fails, `execute()` throws even
though the create or alter has already been committed, and the caller sees a
failure for a change that went through. A constructor that takes only the
identifier would avoid that.
##########
flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/api/TableEnvironmentTest.java:
##########
@@ -307,6 +307,44 @@ void testListMaterializedTablesThrowsForUnknownNamespace()
{
.hasMessage("Database unknown_database does not exist");
}
+ @Test
+ void testFromMaterializedTable() throws Exception {
Review Comment:
Optional: `MaterializedTableTest#testBasic` already covers lookup by short
path and the getters, so this test could go. The negative test for a missing
path and a temporary-table shadow is still worth keeping.
--
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]