-
Notifications
You must be signed in to change notification settings - Fork 223
[AURON #1853] Convert Flink Calc operators to Native Calc operators #2283
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
1d3e730
78ad58a
cce8ac2
c84abc1
2f205bb
d163005
b52fe38
b94b59b
5884356
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * 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 java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import org.apache.calcite.rex.RexNode; | ||
| import org.apache.flink.annotation.VisibleForTesting; | ||
|
|
||
| /** | ||
| * Holds the per-fallback WARN dedup state for the shadowed {@link StreamExecCalc}. Lives in a | ||
| * non-shadowed sibling class so unit tests can call the {@link VisibleForTesting} seams directly | ||
| * — the shadow shares its FQCN with Flink's stock {@code StreamExecCalc}, which can confuse javac | ||
| * when test sources reference symbols that exist only on the shadow. | ||
| * | ||
| * <p>Dedup is JVM-wide: a given unsupported {@link RexNode} class is logged at most once per JVM, | ||
| * bounded by the small finite set of {@link RexNode} subclasses Flink can generate. | ||
| */ | ||
| final class StreamExecCalcWarnState { | ||
|
|
||
| private static final Set<Class<? extends RexNode>> WARN_DEDUP = ConcurrentHashMap.newKeySet(); | ||
|
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. Just use the Class object directly here — no need to restrict it to subclasses of RexNode. |
||
| private static final AtomicInteger WARN_EMIT_COUNT = new AtomicInteger(); | ||
|
|
||
| private StreamExecCalcWarnState() {} | ||
|
|
||
| /** | ||
| * Marks an unsupported {@link RexNode} class as seen and increments the emit counter. Returns | ||
| * {@code true} on the first occurrence of the class (caller should emit the WARN line); | ||
| * {@code false} on subsequent occurrences (caller should be silent). | ||
| */ | ||
| static boolean recordFallback(Class<? extends RexNode> unsupportedRexClass) { | ||
|
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. static boolean recordFallback(Class unsupportedFlinkNodeClass) |
||
| if (WARN_DEDUP.add(unsupportedRexClass)) { | ||
| WARN_EMIT_COUNT.incrementAndGet(); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** Increments the emit counter for plan-composition failures, which always log. */ | ||
| static void recordCompositionFailure() { | ||
| WARN_EMIT_COUNT.incrementAndGet(); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static void resetForTest() { | ||
| WARN_DEDUP.clear(); | ||
| WARN_EMIT_COUNT.set(0); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static int peekEmitCount() { | ||
| return WARN_EMIT_COUNT.get(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * 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.auron.flink.table.runtime; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import org.apache.auron.flink.table.AuronFlinkTableTestBase; | ||
| import org.apache.flink.types.Row; | ||
| import org.apache.flink.util.CollectionUtil; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * End-to-end IT cases for the shadowed {@code StreamExecCalc}. Each test submits a real SQL job | ||
| * through {@link org.apache.flink.table.api.bridge.java.StreamTableEnvironment} over the {@code T1} | ||
| * table registered in {@link AuronFlinkTableTestBase} and asserts the final row set is correct | ||
| * regardless of whether the Calc executed natively or fell back to Flink's codegen. | ||
| */ | ||
| public class AuronCalcRewriteITCase extends AuronFlinkTableTestBase { | ||
|
|
||
| /** Multi-column arithmetic projection exercises the projection loop with more than one | ||
| * convertible expression. */ | ||
| @Test | ||
| public void testMultiColumnArithmeticProjection() { | ||
| List<Row> rows = CollectionUtil.iteratorToList(tableEnvironment | ||
| .executeSql("select `int` + 1, `int` * 2 from T1") | ||
| .collect()); | ||
| rows.sort(Comparator.comparingInt(o -> (int) o.getField(0))); | ||
| assertThat(rows).isEqualTo(Arrays.asList(Row.of(2, 2), Row.of(3, 4), Row.of(3, 4))); | ||
| } | ||
|
|
||
| /** A filter-plus-projection Calc whose condition uses a not-yet-supported comparison operator | ||
| * falls back to Flink's codegen path. Asserts the job still produces correct results; the | ||
| * Auron-side {@code Filter[FFIReader]} plan-shape coverage will be added when a | ||
| * predicate-returning converter lands. */ | ||
| @Test | ||
| public void testFilterAndProjectEndToEnd() { | ||
| List<Row> rows = CollectionUtil.iteratorToList(tableEnvironment | ||
| .executeSql("select `int` * 2 from T1 where `int` > 1") | ||
| .collect()); | ||
| rows.sort(Comparator.comparingInt(o -> (int) o.getField(0))); | ||
| assertThat(rows).isEqualTo(Arrays.asList(Row.of(4), Row.of(4))); | ||
| } | ||
|
|
||
| /** Unsupported expression (a string function not in the converter set) triggers silent | ||
| * fallback. The job must still complete and emit the correct rows. */ | ||
| @Test | ||
| public void testFallbackOnUnsupportedExprStillExecutes() { | ||
| List<Row> rows = CollectionUtil.iteratorToList( | ||
| tableEnvironment.executeSql("select UPPER(`string`) from T1").collect()); | ||
| rows.sort(Comparator.comparing(o -> (String) o.getField(0))); | ||
| assertThat(rows).isEqualTo(Arrays.asList(Row.of("COMMENT#1"), Row.of("COMMENT#1"), Row.of("HI"))); | ||
| } | ||
|
|
||
| /** A job containing two Calcs — one whose expressions are all converter-supported and one | ||
| * that uses an unsupported function — must run end-to-end and emit the correct union of rows. | ||
| * This asserts the job-level correctness contract; observability of which Calc fell back is | ||
| * surfaced through the per-fallback WARN log rather than the test's value assertion. */ | ||
| @Test | ||
| public void testMixedSupportedAndUnsupportedCalcs() { | ||
| List<Row> rows = CollectionUtil.iteratorToList(tableEnvironment | ||
| .executeSql("select `int` + 1 from T1 union all select CHAR_LENGTH(`string`) from T1") | ||
| .collect()); | ||
| rows.sort(Comparator.comparingInt(o -> (int) o.getField(0))); | ||
| assertThat(rows).isEqualTo(Arrays.asList(Row.of(2), Row.of(2), Row.of(3), Row.of(3), Row.of(9), Row.of(9))); | ||
| } | ||
| } |
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.
Since we're creating a dedicated utility class for this, I'd suggest the naming shouldn't be tied specifically to the Calc operator — that way, other operators can also use it in the future.
How about naming this class
UnsupportedFlinkNodeRecorder? Also, let's put it under the Auron package directory rather than the Flink package.