-
Notifications
You must be signed in to change notification settings - Fork 14k
[FLINK-36808][table-planner] Include pushed-down source abilities in the lookup join digest #29200
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 all commits
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 |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * 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.planner.plan.nodes.exec.common; | ||
|
|
||
| import org.apache.flink.table.planner.plan.nodes.exec.stream.StreamExecLookupJoin; | ||
| import org.apache.flink.table.test.program.SinkTestStep; | ||
| import org.apache.flink.table.test.program.SourceTestStep; | ||
| import org.apache.flink.table.test.program.TableTestProgram; | ||
|
|
||
| import static org.apache.flink.table.planner.plan.nodes.exec.common.LookupJoinTestPrograms.CUSTOMERS_BEFORE_DATA; | ||
| import static org.apache.flink.table.planner.plan.nodes.exec.common.LookupJoinTestPrograms.CUSTOMERS_SCHEMA; | ||
| import static org.apache.flink.table.planner.plan.nodes.exec.common.LookupJoinTestPrograms.ORDERS_BEFORE_DATA; | ||
| import static org.apache.flink.table.planner.plan.nodes.exec.common.LookupJoinTestPrograms.ORDERS_SCHEMA; | ||
| import static org.apache.flink.table.planner.plan.nodes.exec.common.LookupJoinTestPrograms.SINK_SCHEMA; | ||
|
|
||
| /** {@link TableTestProgram} definitions for semantic testing {@link StreamExecLookupJoin}. */ | ||
| public class LookupJoinSemanticTestPrograms { | ||
|
|
||
| /** A semantic test cannot take a source that carries after-restore data. */ | ||
| static final SourceTestStep CUSTOMERS = | ||
| SourceTestStep.newBuilder("customers_t") | ||
| .addOption("disable-lookup", "false") // static/lookup table | ||
| .addOption("filterable-fields", "age") | ||
| .addSchema(CUSTOMERS_SCHEMA) | ||
| .producedValues(CUSTOMERS_BEFORE_DATA) | ||
| .build(); | ||
|
|
||
| static final SourceTestStep ORDERS = | ||
| SourceTestStep.newBuilder("orders_t") | ||
| .addOption("filterable-fields", "customer_id") | ||
| .addSchema(ORDERS_SCHEMA) | ||
| .producedValues(ORDERS_BEFORE_DATA) | ||
| .build(); | ||
|
|
||
| private static String filteredLookupJoin(String filter) { | ||
| return "SELECT " | ||
| + "O.order_id, " | ||
| + "O.total, " | ||
| + "C.id, " | ||
| + "C.name, " | ||
| + "C.age, " | ||
| + "C.city, " | ||
| + "C.state, " | ||
| + "C.zipcode " | ||
| + "FROM orders_t as O " | ||
| + "JOIN customers_t FOR SYSTEM_TIME AS OF O.proc_time AS C " | ||
| + "ON O.customer_id = C.id AND " | ||
| + filter; | ||
| } | ||
|
|
||
| /** | ||
| * Both branches select the same columns from the same dim table and differ only in the filter | ||
| * pushed into it, so the two lookup joins are indistinguishable unless the pushed-down filter | ||
| * is part of the lookup join's digest. See FLINK-36808. | ||
| */ | ||
| private static String unionOfTwoFilteredLookupJoins(String firstFilter, String secondFilter) { | ||
| return "INSERT INTO sink_t " | ||
| + filteredLookupJoin(firstFilter) | ||
| + " UNION ALL " | ||
| + filteredLookupJoin(secondFilter); | ||
| } | ||
|
|
||
| private static SinkTestStep sink() { | ||
| return SinkTestStep.newBuilder("sink_t") | ||
| .addSchema(SINK_SCHEMA) | ||
| .consumedValues( | ||
| "+I[1, 44.44, 3, Claire, 37, Austin, Texas, 73301]", | ||
| "+I[2, 100.02, 5, Jake, 42, New York City, New York, 10001]", | ||
| "+I[4, 92.61, 2, Alice, 32, San Francisco, California, 95016]", | ||
| "+I[5, 12.78, 2, Alice, 32, San Francisco, California, 95016]") | ||
| .build(); | ||
| } | ||
|
|
||
| public static final TableTestProgram LOOKUP_JOIN_UNION_DIFFERENT_FILTERS = | ||
| TableTestProgram.of( | ||
| "lookup-join-union-different-filters", | ||
| "validates two lookup joins on the same table with different pushed-down filters are not merged, with the matching filter first") | ||
| .setupTableSource(CUSTOMERS) | ||
| .setupTableSource(ORDERS) | ||
| .setupTableSink(sink()) | ||
| .runSql(unionOfTwoFilteredLookupJoins("C.age > 30", "C.age > 100")) | ||
| .build(); | ||
|
|
||
| public static final TableTestProgram LOOKUP_JOIN_UNION_DIFFERENT_FILTERS_REVERSED = | ||
| TableTestProgram.of( | ||
| "lookup-join-union-different-filters-reversed", | ||
| "validates the same with the non-matching filter first, where a wrong merge returns nothing at all") | ||
| .setupTableSource(CUSTOMERS) | ||
| .setupTableSource(ORDERS) | ||
| .setupTableSink(sink()) | ||
| .runSql(unionOfTwoFilteredLookupJoins("C.age > 100", "C.age > 30")) | ||
| .build(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * 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.planner.plan.nodes.exec.stream; | ||
|
|
||
| import org.apache.flink.table.planner.plan.nodes.exec.common.LookupJoinSemanticTestPrograms; | ||
| import org.apache.flink.table.planner.plan.nodes.exec.testutils.SemanticTestBase; | ||
| import org.apache.flink.table.test.program.TableTestProgram; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** Semantic tests for {@link StreamExecLookupJoin}. */ | ||
| public class LookupJoinSemanticTests extends SemanticTestBase { | ||
|
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. there is
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.
You did make me look at where the programs live though. They were in |
||
|
|
||
| @Override | ||
| public List<TableTestProgram> programs() { | ||
| return List.of( | ||
| LookupJoinSemanticTestPrograms.LOOKUP_JOIN_UNION_DIFFERENT_FILTERS, | ||
| LookupJoinSemanticTestPrograms.LOOKUP_JOIN_UNION_DIFFERENT_FILTERS_REVERSED); | ||
| } | ||
| } | ||
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.
this is weird...
probably better with having empty collections in plans...
sorry for back and forth however we should not rely on 3rd party toString implementstion