-
Notifications
You must be signed in to change notification settings - Fork 14k
[FLINK-39957][table] Support EXPLAIN of CREATE [OR ALTER] MATERIALIZED TABLE #28510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
7a0b485
cf2643a
fd4a3dc
34091c4
a128d52
106f471
75c00a4
fa75dc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,13 +21,20 @@ | |
| import org.apache.flink.configuration.Configuration; | ||
| import org.apache.flink.table.catalog.ObjectIdentifier; | ||
| import org.apache.flink.table.catalog.ResolvedCatalogMaterializedTable; | ||
| import org.apache.flink.table.data.RowData; | ||
| import org.apache.flink.table.gateway.api.SqlGatewayService; | ||
| import org.apache.flink.table.gateway.api.operation.OperationHandle; | ||
| import org.apache.flink.table.gateway.api.session.SessionHandle; | ||
| import org.apache.flink.table.planner.utils.TableTestUtil; | ||
| import org.apache.flink.table.refresh.ContinuousRefreshHandler; | ||
| import org.apache.flink.table.refresh.ContinuousRefreshHandlerSerializer; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| import static org.apache.flink.table.gateway.service.utils.SqlGatewayServiceTestUtil.awaitOperationTermination; | ||
| import static org.apache.flink.table.gateway.service.utils.SqlGatewayServiceTestUtil.fetchAllResults; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** Helpers shared between the materialized table gateway ITCases. */ | ||
| final class MaterializedTableTestUtils { | ||
|
|
@@ -50,4 +57,26 @@ static ContinuousRefreshHandler getContinuousRefreshHandler( | |
| return ContinuousRefreshHandlerSerializer.INSTANCE.deserialize( | ||
| resolvedTable.getSerializedRefreshHandler(), classLoader); | ||
| } | ||
|
|
||
| /** | ||
| * Runs an EXPLAIN statement through the gateway and asserts its full plan equals the given | ||
| * golden resource. The per-test catalog name is normalized to {@code $CATALOG} before | ||
| * comparison. | ||
| */ | ||
| static void verifyExplainPlan( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to create another plan verifier if there is already existing framework for this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I wanted to do the verification in the IT cases of the Gateway. Now, I removed the custom helper and moved plan-content verification into the planner tests. Gateway ITs no longer assert plan text. They only check that EXPLAIN returns a single non-empty plan, succeeds, and is is side-effect-free. |
||
| SqlGatewayService service, | ||
| SessionHandle sessionHandle, | ||
| String catalogName, | ||
| String explainStatement, | ||
| String expectedResource) | ||
| throws Exception { | ||
| OperationHandle handle = executeStatement(service, sessionHandle, explainStatement); | ||
| awaitOperationTermination(service, sessionHandle, handle); | ||
| List<RowData> results = fetchAllResults(service, sessionHandle, handle); | ||
| assertThat(results).hasSize(1); | ||
| String actual = | ||
| TableTestUtil.replaceStageId( | ||
| results.get(0).getString(0).toString().replace(catalogName, "$CATALOG")); | ||
| assertThat(actual).isEqualTo(TableTestUtil.readFromResource(expectedResource)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| == Abstract Syntax Tree == | ||
| LogicalSink(table=[$CATALOG.test_db.users_shops], fields=[user_id, shop_id, ds, order_cnt]) | ||
| +- LogicalAggregate(group=[{0, 1, 2}], order_cnt=[COUNT($3)]) | ||
| +- LogicalProject(user_id=[$1], shop_id=[$2], ds=[$3], order_id=[$0]) | ||
| +- LogicalTableScan(table=[[$CATALOG, test_db, my_source]]) | ||
|
|
||
| == Optimized Physical Plan == | ||
| Sink(table=[$CATALOG.test_db.users_shops], fields=[user_id, shop_id, order_created_at, order_cnt]) | ||
| +- GroupAggregate(groupBy=[user_id, shop_id, order_created_at], select=[user_id, shop_id, order_created_at, COUNT(order_id) AS order_cnt]) | ||
| +- Exchange(distribution=[hash[user_id, shop_id, order_created_at]]) | ||
| +- TableSourceScan(table=[[$CATALOG, test_db, my_source]], fields=[order_id, user_id, shop_id, order_created_at]) | ||
|
|
||
| == Optimized Execution Plan == | ||
| Sink(table=[$CATALOG.test_db.users_shops], fields=[user_id, shop_id, order_created_at, order_cnt]) | ||
| +- GroupAggregate(groupBy=[user_id, shop_id, order_created_at], select=[user_id, shop_id, order_created_at, COUNT(order_id) AS order_cnt]) | ||
| +- Exchange(distribution=[hash[user_id, shop_id, order_created_at]]) | ||
| +- TableSourceScan(table=[[$CATALOG, test_db, my_source]], fields=[order_id, user_id, shop_id, order_created_at]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| == Abstract Syntax Tree == | ||
| LogicalSink(table=[$CATALOG.test_db.users_shops], fields=[user_id, shop_id, payment_amount_cents]) | ||
| +- LogicalProject(user_id=[$2], shop_id=[$3], payment_amount_cents=[$8]) | ||
| +- LogicalTableScan(table=[[$CATALOG, test_db, datagenSource]]) | ||
|
|
||
| == Optimized Physical Plan == | ||
| Sink(table=[$CATALOG.test_db.users_shops], fields=[user_id, shop_id, payment_amount_cents]) | ||
| +- Calc(select=[user_id, shop_id, payment_amount_cents]) | ||
| +- TableSourceScan(table=[[$CATALOG, test_db, datagenSource]], fields=[order_id, order_number, user_id, shop_id, product_id, status, order_type, order_created_at, payment_amount_cents]) | ||
|
|
||
| == Optimized Execution Plan == | ||
| Sink(table=[$CATALOG.test_db.users_shops], fields=[user_id, shop_id, payment_amount_cents]) | ||
| +- Calc(select=[user_id, shop_id, payment_amount_cents]) | ||
| +- TableSourceScan(table=[[$CATALOG, test_db, datagenSource]], fields=[order_id, order_number, user_id, shop_id, product_id, status, order_type, order_created_at, payment_amount_cents]) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| == Abstract Syntax Tree == | ||
| LogicalSink(table=[$CATALOG.test_db.users_shops], fields=[user_id, shop_id, ds, order_cnt]) | ||
| +- LogicalAggregate(group=[{0, 1, 2}], order_cnt=[COUNT($3)]) | ||
| +- LogicalProject(user_id=[$1], shop_id=[$2], ds=[$3], order_id=[$0]) | ||
| +- LogicalTableScan(table=[[$CATALOG, test_db, my_source]]) | ||
|
|
||
| == Optimized Physical Plan == | ||
| Sink(table=[$CATALOG.test_db.users_shops], fields=[user_id, shop_id, order_created_at, order_cnt]) | ||
| +- GroupAggregate(groupBy=[user_id, shop_id, order_created_at], select=[user_id, shop_id, order_created_at, COUNT(order_id) AS order_cnt]) | ||
| +- Exchange(distribution=[hash[user_id, shop_id, order_created_at]]) | ||
| +- TableSourceScan(table=[[$CATALOG, test_db, my_source]], fields=[order_id, user_id, shop_id, order_created_at]) | ||
|
|
||
| == Optimized Execution Plan == | ||
| Sink(table=[$CATALOG.test_db.users_shops], fields=[user_id, shop_id, order_created_at, order_cnt]) | ||
| +- GroupAggregate(groupBy=[user_id, shop_id, order_created_at], select=[user_id, shop_id, order_created_at, COUNT(order_id) AS order_cnt]) | ||
| +- Exchange(distribution=[hash[user_id, shop_id, order_created_at]]) | ||
| +- TableSourceScan(table=[[$CATALOG, test_db, my_source]], fields=[order_id, user_id, shop_id, order_created_at]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason
MaterializedTableOperationis not aModifyOperationhowever after that we call
callModifyOperations?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MaterializedTableOperationis a marker shared by SUSPEND, RESUME, REFRESH and DROP too. Those have no definition query, so they can't implement theModifyOperationcontract (getChild()/accept(visitor)) in any meaningful way. More importantly, if the marker were aModifyOperation, every MT op would fall into thecallModifyOperationsbranch and execute as anINSERT.That's what the
&& !(op instanceof MaterializedTableOperation)guard enforces. So only the query-bearing operations implementModifyOperation, and purely so the planner can translate them into a sink forEXPLAIN. Execution still goes through the manager for all of them.