lsyldliu commented on code in PR #24160:
URL: https://github.com/apache/flink/pull/24160#discussion_r1465762258
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/join/stream/AbstractStreamingJoinOperator.java:
##########
@@ -66,6 +67,10 @@ public abstract class AbstractStreamingJoinOperator extends
AbstractStreamOperat
protected transient JoinConditionWithNullFilters joinCondition;
protected transient TimestampedCollector<RowData> collector;
+ protected transient boolean requiresCopy;
Review Comment:
We don't need this member variable, this only used for minibatch join, it
must need to copy.
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/join/stream/MiniBatchStreamingJoinOperator.java:
##########
@@ -0,0 +1,420 @@
+/*
+ * 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.runtime.operators.join.stream;
+
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.util.RowDataUtil;
+import org.apache.flink.table.runtime.generated.GeneratedJoinCondition;
+import
org.apache.flink.table.runtime.operators.bundle.trigger.BundleTriggerCallback;
+import org.apache.flink.table.runtime.operators.bundle.trigger.CoBundleTrigger;
+import org.apache.flink.table.runtime.operators.join.FlinkJoinType;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.BufferBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasNoUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.JoinKeyContainsUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinRecordStateView;
+import org.apache.flink.table.runtime.operators.metrics.SimpleGauge;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/** Streaming unbounded Join base operator which support mini-batch join. */
+public abstract class MiniBatchStreamingJoinOperator extends
StreamingJoinOperator
+ implements BundleTriggerCallback {
+
+ private static final long serialVersionUID = -1106342589994963997L;
+
+ private final CoBundleTrigger<RowData, RowData> coBundleTrigger;
+
+ private transient BufferBundle<?> leftBuffer;
+ private transient BufferBundle<?> rightBuffer;
+ private transient SimpleGauge<Integer> leftBundleReducedSizeGauge;
+ private transient SimpleGauge<Integer> rightBundleReducedSizeGauge;
+
+ public MiniBatchStreamingJoinOperator(MiniBatchStreamingJoinParameter
parameter) {
+ super(
+ parameter.leftType,
+ parameter.rightType,
+ parameter.generatedJoinCondition,
+ parameter.leftInputSideSpec,
+ parameter.rightInputSideSpec,
+ parameter.leftIsOuter,
+ parameter.rightIsOuter,
+ parameter.filterNullKeys,
+ parameter.leftStateRetentionTime,
+ parameter.rightStateRetentionTime);
+
+ this.coBundleTrigger = parameter.coBundleTrigger;
+ }
+
+ @Override
+ public void open() throws Exception {
+ super.open();
+
+ // must copy in mini-batch
+ this.requiresCopy = true;
+
+ this.leftBuffer = initialBuffer(leftInputSideSpec);
+ this.rightBuffer = initialBuffer(rightInputSideSpec);
Review Comment:
this.leftSerializer = leftType.createSerializer(new
ExecutionConfig());
this.rightSerializer = rightType.createSerializer(new
ExecutionConfig());
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/join/stream/MiniBatchStreamingJoinOperator.java:
##########
@@ -0,0 +1,420 @@
+/*
+ * 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.runtime.operators.join.stream;
+
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.util.RowDataUtil;
+import org.apache.flink.table.runtime.generated.GeneratedJoinCondition;
+import
org.apache.flink.table.runtime.operators.bundle.trigger.BundleTriggerCallback;
+import org.apache.flink.table.runtime.operators.bundle.trigger.CoBundleTrigger;
+import org.apache.flink.table.runtime.operators.join.FlinkJoinType;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.BufferBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasNoUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.JoinKeyContainsUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinRecordStateView;
+import org.apache.flink.table.runtime.operators.metrics.SimpleGauge;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/** Streaming unbounded Join base operator which support mini-batch join. */
+public abstract class MiniBatchStreamingJoinOperator extends
StreamingJoinOperator
+ implements BundleTriggerCallback {
+
+ private static final long serialVersionUID = -1106342589994963997L;
+
+ private final CoBundleTrigger<RowData, RowData> coBundleTrigger;
+
+ private transient BufferBundle<?> leftBuffer;
+ private transient BufferBundle<?> rightBuffer;
+ private transient SimpleGauge<Integer> leftBundleReducedSizeGauge;
+ private transient SimpleGauge<Integer> rightBundleReducedSizeGauge;
+
+ public MiniBatchStreamingJoinOperator(MiniBatchStreamingJoinParameter
parameter) {
+ super(
+ parameter.leftType,
+ parameter.rightType,
+ parameter.generatedJoinCondition,
+ parameter.leftInputSideSpec,
+ parameter.rightInputSideSpec,
+ parameter.leftIsOuter,
+ parameter.rightIsOuter,
+ parameter.filterNullKeys,
+ parameter.leftStateRetentionTime,
+ parameter.rightStateRetentionTime);
+
+ this.coBundleTrigger = parameter.coBundleTrigger;
+ }
+
+ @Override
+ public void open() throws Exception {
+ super.open();
+
+ // must copy in mini-batch
+ this.requiresCopy = true;
+
+ this.leftBuffer = initialBuffer(leftInputSideSpec);
+ this.rightBuffer = initialBuffer(rightInputSideSpec);
+
+ coBundleTrigger.registerCallback(this);
+ coBundleTrigger.reset();
+ LOG.info("Initialize MiniBatchStreamingJoinOperator successfully.");
+
+ // register metrics
+ leftBundleReducedSizeGauge = new SimpleGauge<>(0);
+ rightBundleReducedSizeGauge = new SimpleGauge<>(0);
+
+ getRuntimeContext()
+ .getMetricGroup()
+ .gauge("leftBundleReducedSize", leftBundleReducedSizeGauge);
+ getRuntimeContext()
+ .getMetricGroup()
+ .gauge("rightBundleReducedSize", rightBundleReducedSizeGauge);
+ }
+
+ @Override
+ public void processElement1(StreamRecord<RowData> element) throws
Exception {
+ RowData record = leftSerializer.toSerializedRow(element.getValue(),
requiresCopy);
Review Comment:
```suggestion
RowData record = leftSerializer.copy(element.getValue());
```
##########
flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/join/stream/StreamingJoinOperatorTestBase.java:
##########
@@ -41,7 +41,7 @@
/** Base test class for {@link AbstractStreamingJoinOperator}. */
public abstract class StreamingJoinOperatorTestBase {
- protected final InternalTypeInfo<RowData> leftTypeInfo =
+ protected InternalTypeInfo<RowData> leftTypeInfo =
Review Comment:
The final keyword shouldn't be remove for leftTypeInfo
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/join/stream/MiniBatchStreamingJoinOperator.java:
##########
@@ -0,0 +1,420 @@
+/*
+ * 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.runtime.operators.join.stream;
+
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.util.RowDataUtil;
+import org.apache.flink.table.runtime.generated.GeneratedJoinCondition;
+import
org.apache.flink.table.runtime.operators.bundle.trigger.BundleTriggerCallback;
+import org.apache.flink.table.runtime.operators.bundle.trigger.CoBundleTrigger;
+import org.apache.flink.table.runtime.operators.join.FlinkJoinType;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.BufferBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasNoUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.JoinKeyContainsUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinRecordStateView;
+import org.apache.flink.table.runtime.operators.metrics.SimpleGauge;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/** Streaming unbounded Join base operator which support mini-batch join. */
+public abstract class MiniBatchStreamingJoinOperator extends
StreamingJoinOperator
+ implements BundleTriggerCallback {
+
+ private static final long serialVersionUID = -1106342589994963997L;
+
+ private final CoBundleTrigger<RowData, RowData> coBundleTrigger;
+
+ private transient BufferBundle<?> leftBuffer;
+ private transient BufferBundle<?> rightBuffer;
Review Comment:
protected transient TypeSerializer<RowData> leftSerializer;
protected transient TypeSerializer<RowData> rightSerializer;
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/typeutils/AbstractRowDataSerializer.java:
##########
@@ -33,6 +33,12 @@ public abstract class AbstractRowDataSerializer<T extends
RowData> extends Paged
/** Get the number of fields. */
public abstract int getArity();
+ /** Convert a {@link RowData} to a serialized row. */
+ public RowData toSerializedRow(T rowData, boolean requiresCopy) throws
IOException {
Review Comment:
Revert this change, we don't need it.
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/join/stream/MiniBatchStreamingJoinOperator.java:
##########
@@ -0,0 +1,420 @@
+/*
+ * 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.runtime.operators.join.stream;
+
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.util.RowDataUtil;
+import org.apache.flink.table.runtime.generated.GeneratedJoinCondition;
+import
org.apache.flink.table.runtime.operators.bundle.trigger.BundleTriggerCallback;
+import org.apache.flink.table.runtime.operators.bundle.trigger.CoBundleTrigger;
+import org.apache.flink.table.runtime.operators.join.FlinkJoinType;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.BufferBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasNoUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.JoinKeyContainsUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinRecordStateView;
+import org.apache.flink.table.runtime.operators.metrics.SimpleGauge;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/** Streaming unbounded Join base operator which support mini-batch join. */
+public abstract class MiniBatchStreamingJoinOperator extends
StreamingJoinOperator
+ implements BundleTriggerCallback {
+
+ private static final long serialVersionUID = -1106342589994963997L;
+
+ private final CoBundleTrigger<RowData, RowData> coBundleTrigger;
+
+ private transient BufferBundle<?> leftBuffer;
+ private transient BufferBundle<?> rightBuffer;
+ private transient SimpleGauge<Integer> leftBundleReducedSizeGauge;
+ private transient SimpleGauge<Integer> rightBundleReducedSizeGauge;
+
+ public MiniBatchStreamingJoinOperator(MiniBatchStreamingJoinParameter
parameter) {
+ super(
+ parameter.leftType,
+ parameter.rightType,
+ parameter.generatedJoinCondition,
+ parameter.leftInputSideSpec,
+ parameter.rightInputSideSpec,
+ parameter.leftIsOuter,
+ parameter.rightIsOuter,
+ parameter.filterNullKeys,
+ parameter.leftStateRetentionTime,
+ parameter.rightStateRetentionTime);
+
+ this.coBundleTrigger = parameter.coBundleTrigger;
+ }
+
+ @Override
+ public void open() throws Exception {
+ super.open();
+
+ // must copy in mini-batch
+ this.requiresCopy = true;
+
+ this.leftBuffer = initialBuffer(leftInputSideSpec);
+ this.rightBuffer = initialBuffer(rightInputSideSpec);
+
+ coBundleTrigger.registerCallback(this);
+ coBundleTrigger.reset();
+ LOG.info("Initialize MiniBatchStreamingJoinOperator successfully.");
+
+ // register metrics
+ leftBundleReducedSizeGauge = new SimpleGauge<>(0);
+ rightBundleReducedSizeGauge = new SimpleGauge<>(0);
+
+ getRuntimeContext()
+ .getMetricGroup()
+ .gauge("leftBundleReducedSize", leftBundleReducedSizeGauge);
+ getRuntimeContext()
+ .getMetricGroup()
+ .gauge("rightBundleReducedSize", rightBundleReducedSizeGauge);
+ }
+
+ @Override
+ public void processElement1(StreamRecord<RowData> element) throws
Exception {
+ RowData record = leftSerializer.toSerializedRow(element.getValue(),
requiresCopy);
+ RowData joinKey = (RowData) getCurrentKey();
+ RowData uniqueKey = null;
+ if (leftInputSideSpec.getUniqueKeySelector() != null) {
+ uniqueKey =
leftInputSideSpec.getUniqueKeySelector().getKey(record);
+ }
+ leftBuffer.addRecord(joinKey, uniqueKey, record);
+ coBundleTrigger.onElement1(record);
+ }
+
+ @Override
+ public void processElement2(StreamRecord<RowData> element) throws
Exception {
+ RowData record = rightSerializer.toSerializedRow(element.getValue(),
requiresCopy);
Review Comment:
ditto
##########
flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/join/stream/StreamingJoinOperatorTestBase.java:
##########
@@ -51,17 +51,17 @@ public abstract class StreamingJoinOperatorTestBase {
},
new String[] {"order_id", "line_order_id",
"shipping_address"}));
- protected final InternalTypeInfo<RowData> rightTypeInfo =
+ protected InternalTypeInfo<RowData> rightTypeInfo =
InternalTypeInfo.of(
RowType.of(
new LogicalType[] {new CharType(false, 20), new
CharType(true, 10)},
new String[] {"line_order_id0",
"line_order_ship_mode"}));
- protected final RowDataKeySelector leftKeySelector =
+ protected RowDataKeySelector leftKeySelector =
Review Comment:
ditto
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/join/stream/MiniBatchStreamingJoinOperator.java:
##########
@@ -0,0 +1,416 @@
+/*
+ * 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.runtime.operators.join.stream;
+
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.util.RowDataUtil;
+import org.apache.flink.table.runtime.generated.GeneratedJoinCondition;
+import
org.apache.flink.table.runtime.operators.bundle.trigger.BundleTriggerCallback;
+import org.apache.flink.table.runtime.operators.bundle.trigger.CoBundleTrigger;
+import org.apache.flink.table.runtime.operators.join.FlinkJoinType;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.BufferBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasNoUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.JoinKeyContainsUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinRecordStateView;
+import org.apache.flink.table.runtime.operators.metrics.SimpleGauge;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/** Streaming unbounded Join base operator which support mini-batch join. */
+public abstract class MiniBatchStreamingJoinOperator extends
StreamingJoinOperator
+ implements BundleTriggerCallback {
+
+ private static final long serialVersionUID = -1106342589994963997L;
+
+ private final CoBundleTrigger<RowData, RowData> coBundleTrigger;
+
+ private transient BufferBundle leftBuffer;
+ private transient BufferBundle rightBuffer;
+ private transient SimpleGauge<Integer> leftBundleReducedSizeGauge;
+ private transient SimpleGauge<Integer> rightBundleReducedSizeGauge;
+
+ public MiniBatchStreamingJoinOperator(MiniBatchStreamingJoinParameter
parameter) {
+ super(
+ parameter.leftType,
+ parameter.rightType,
+ parameter.generatedJoinCondition,
+ parameter.leftInputSideSpec,
+ parameter.rightInputSideSpec,
+ parameter.leftIsOuter,
+ parameter.rightIsOuter,
+ parameter.filterNullKeys,
+ parameter.leftStateRetentionTime,
+ parameter.rightStateRetentionTime);
+
+ this.coBundleTrigger = parameter.coBundleTrigger;
+ }
+
+ @Override
+ public void open() throws Exception {
+ super.open();
+
+ this.leftBuffer = initialBuffer(leftInputSideSpec);
+ this.rightBuffer = initialBuffer(rightInputSideSpec);
+
+ coBundleTrigger.registerCallback(this);
+ coBundleTrigger.reset();
+ LOG.info("Initialize MiniBatchStreamingJoinOperator successfully.");
+
+ // register metrics
+ leftBundleReducedSizeGauge = new SimpleGauge<>(0);
+ rightBundleReducedSizeGauge = new SimpleGauge<>(0);
+
+ getRuntimeContext()
+ .getMetricGroup()
+ .gauge("leftBundleReducedSize", leftBundleReducedSizeGauge);
+ getRuntimeContext()
+ .getMetricGroup()
+ .gauge("rightBundleReducedSize", rightBundleReducedSizeGauge);
+ }
+
+ @Override
+ public void processElement1(StreamRecord<RowData> element) throws
Exception {
+ RowData joinKey = (RowData) getCurrentKey();
+ RowData uniqueKey = null;
+ if (leftInputSideSpec.getUniqueKeySelector() != null) {
+ uniqueKey =
leftInputSideSpec.getUniqueKeySelector().getKey(element.getValue());
+ }
+ leftBuffer.addRecord(joinKey, uniqueKey, element.getValue());
+ coBundleTrigger.onElement1(element.getValue());
+ }
+
+ @Override
+ public void processElement2(StreamRecord<RowData> element) throws
Exception {
+ RowData joinKey = (RowData) getCurrentKey();
+ RowData uniqueKey = null;
+ if (rightInputSideSpec.getUniqueKeySelector() != null) {
+ uniqueKey =
rightInputSideSpec.getUniqueKeySelector().getKey(element.getValue());
+ }
+ rightBuffer.addRecord(joinKey, uniqueKey, element.getValue());
+ coBundleTrigger.onElement2(element.getValue());
+ }
+
+ @Override
+ public void processWatermark1(Watermark mark) throws Exception {
+ finishBundle();
+ super.processWatermark1(mark);
+ }
+
+ @Override
+ public void processWatermark2(Watermark mark) throws Exception {
+ finishBundle();
+ super.processWatermark2(mark);
+ }
+
+ @Override
+ public void prepareSnapshotPreBarrier(long checkpointId) throws Exception {
+ finishBundle();
+ }
+
+ @Override
+ public void finish() throws Exception {
+ finishBundle();
+ super.finish();
+ }
+
+ @Override
+ public void finishBundle() throws Exception {
+ if (!leftBuffer.isEmpty() || !rightBuffer.isEmpty()) {
+ // update metrics value
+ leftBundleReducedSizeGauge.update(leftBuffer.reducedSize());
+ rightBundleReducedSizeGauge.update(rightBuffer.reducedSize());
+
+ this.processBundles(leftBuffer, rightBuffer);
+ leftBuffer.clear();
+ rightBuffer.clear();
+
+
+ }
+ coBundleTrigger.reset();
+ }
+
+ protected abstract void processBundles(BufferBundle leftBuffer,
BufferBundle rightBuffer)
+ throws Exception;
+
+ private BufferBundle initialBuffer(JoinInputSideSpec inputSideSpec) {
+ if (inputSideSpec.joinKeyContainsUniqueKey()) {
+ return new JoinKeyContainsUniqueKeyBundle();
+ }
+ if (inputSideSpec.hasUniqueKey()) {
+ return new InputSideHasUniqueKeyBundle();
+ }
+ return new InputSideHasNoUniqueKeyBundle();
+ }
+
+ private void processElementWithSuppress(
+ Iterator<RowData> iter,
+ JoinRecordStateView inputSideStateView,
+ JoinRecordStateView otherSideStateView,
+ boolean inputIsLeft)
+ throws Exception {
+ RowData pre = null; // always retractMsg if not null
+ while (iter.hasNext()) {
+ RowData current = iter.next();
+ boolean isSuppress = false;
+ if (RowDataUtil.isRetractMsg(current) && iter.hasNext()) {
+ RowData next = iter.next();
+ if (RowDataUtil.isAccumulateMsg(next)) {
+ isSuppress = true;
+ } else {
+ // retract + retract
+ pre = next;
+ }
+ processElement(
+ current, inputSideStateView, otherSideStateView,
inputIsLeft, isSuppress);
+ if (isSuppress) {
+ processElement(
+ next, inputSideStateView, otherSideStateView,
inputIsLeft, isSuppress);
+ }
+ } else {
+ // 1. current is accumulateMsg 2. current is retractMsg and no
next row
+ if (pre != null) {
+ if (RowDataUtil.isAccumulateMsg(current)) {
+ isSuppress = true;
+ }
+ processElement(
+ pre, inputSideStateView, otherSideStateView,
inputIsLeft, isSuppress);
+ pre = null;
+ }
+ processElement(
+ current, inputSideStateView, otherSideStateView,
inputIsLeft, isSuppress);
+ }
+ }
+ }
+
+ /**
+ * RetractMsg+accumulatingMsg would be optimized which would keep sending
retractMsg but do not
+ * deal with state.
+ */
+ protected void processSingleSideBundles(
+ BufferBundle inputBuffer,
+ JoinRecordStateView inputSideStateView,
+ JoinRecordStateView otherSideStateView,
+ boolean inputIsLeft)
+ throws Exception {
+ if (inputBuffer instanceof InputSideHasNoUniqueKeyBundle) {
+ // -U/+U pair is already folded in the buffer so it is no need to
go to
+ // processElementByPair function
+ for (Map.Entry<RowData, List<RowData>> entry :
inputBuffer.getRecords().entrySet()) {
+ // set state key first
+ setCurrentKey(entry.getKey());
+ for (RowData rowData : entry.getValue()) {
+ processElement(
+ rowData, inputSideStateView, otherSideStateView,
inputIsLeft, false);
+ }
+ }
+ } else if (inputBuffer instanceof JoinKeyContainsUniqueKeyBundle) {
+ for (Map.Entry<RowData, List<RowData>> entry :
inputBuffer.getRecords().entrySet()) {
+ // set state key first
+ setCurrentKey(entry.getKey());
+ Iterator<RowData> iter = entry.getValue().iterator();
+ processElementWithSuppress(
+ iter, inputSideStateView, otherSideStateView,
inputIsLeft);
+ }
+ } else {
+ for (RowData jk : inputBuffer.getJoinKeys()) {
Review Comment:
ping again
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/join/stream/MiniBatchStreamingJoinOperator.java:
##########
@@ -0,0 +1,416 @@
+/*
+ * 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.runtime.operators.join.stream;
+
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.util.RowDataUtil;
+import org.apache.flink.table.runtime.generated.GeneratedJoinCondition;
+import
org.apache.flink.table.runtime.operators.bundle.trigger.BundleTriggerCallback;
+import org.apache.flink.table.runtime.operators.bundle.trigger.CoBundleTrigger;
+import org.apache.flink.table.runtime.operators.join.FlinkJoinType;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.BufferBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasNoUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.JoinKeyContainsUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinRecordStateView;
+import org.apache.flink.table.runtime.operators.metrics.SimpleGauge;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/** Streaming unbounded Join base operator which support mini-batch join. */
+public abstract class MiniBatchStreamingJoinOperator extends
StreamingJoinOperator
+ implements BundleTriggerCallback {
+
+ private static final long serialVersionUID = -1106342589994963997L;
+
+ private final CoBundleTrigger<RowData, RowData> coBundleTrigger;
+
+ private transient BufferBundle leftBuffer;
+ private transient BufferBundle rightBuffer;
+ private transient SimpleGauge<Integer> leftBundleReducedSizeGauge;
+ private transient SimpleGauge<Integer> rightBundleReducedSizeGauge;
+
+ public MiniBatchStreamingJoinOperator(MiniBatchStreamingJoinParameter
parameter) {
+ super(
+ parameter.leftType,
+ parameter.rightType,
+ parameter.generatedJoinCondition,
+ parameter.leftInputSideSpec,
+ parameter.rightInputSideSpec,
+ parameter.leftIsOuter,
+ parameter.rightIsOuter,
+ parameter.filterNullKeys,
+ parameter.leftStateRetentionTime,
+ parameter.rightStateRetentionTime);
+
+ this.coBundleTrigger = parameter.coBundleTrigger;
+ }
+
+ @Override
+ public void open() throws Exception {
+ super.open();
+
+ this.leftBuffer = initialBuffer(leftInputSideSpec);
+ this.rightBuffer = initialBuffer(rightInputSideSpec);
+
+ coBundleTrigger.registerCallback(this);
+ coBundleTrigger.reset();
+ LOG.info("Initialize MiniBatchStreamingJoinOperator successfully.");
+
+ // register metrics
+ leftBundleReducedSizeGauge = new SimpleGauge<>(0);
+ rightBundleReducedSizeGauge = new SimpleGauge<>(0);
+
+ getRuntimeContext()
+ .getMetricGroup()
+ .gauge("leftBundleReducedSize", leftBundleReducedSizeGauge);
+ getRuntimeContext()
+ .getMetricGroup()
+ .gauge("rightBundleReducedSize", rightBundleReducedSizeGauge);
+ }
+
+ @Override
+ public void processElement1(StreamRecord<RowData> element) throws
Exception {
+ RowData joinKey = (RowData) getCurrentKey();
+ RowData uniqueKey = null;
+ if (leftInputSideSpec.getUniqueKeySelector() != null) {
+ uniqueKey =
leftInputSideSpec.getUniqueKeySelector().getKey(element.getValue());
+ }
+ leftBuffer.addRecord(joinKey, uniqueKey, element.getValue());
+ coBundleTrigger.onElement1(element.getValue());
+ }
+
+ @Override
+ public void processElement2(StreamRecord<RowData> element) throws
Exception {
+ RowData joinKey = (RowData) getCurrentKey();
+ RowData uniqueKey = null;
+ if (rightInputSideSpec.getUniqueKeySelector() != null) {
+ uniqueKey =
rightInputSideSpec.getUniqueKeySelector().getKey(element.getValue());
+ }
+ rightBuffer.addRecord(joinKey, uniqueKey, element.getValue());
+ coBundleTrigger.onElement2(element.getValue());
+ }
+
+ @Override
+ public void processWatermark1(Watermark mark) throws Exception {
+ finishBundle();
+ super.processWatermark1(mark);
+ }
+
+ @Override
+ public void processWatermark2(Watermark mark) throws Exception {
+ finishBundle();
+ super.processWatermark2(mark);
+ }
+
+ @Override
+ public void prepareSnapshotPreBarrier(long checkpointId) throws Exception {
+ finishBundle();
+ }
+
+ @Override
+ public void finish() throws Exception {
+ finishBundle();
+ super.finish();
+ }
+
+ @Override
+ public void finishBundle() throws Exception {
+ if (!leftBuffer.isEmpty() || !rightBuffer.isEmpty()) {
+ // update metrics value
+ leftBundleReducedSizeGauge.update(leftBuffer.reducedSize());
+ rightBundleReducedSizeGauge.update(rightBuffer.reducedSize());
+
+ this.processBundles(leftBuffer, rightBuffer);
+ leftBuffer.clear();
+ rightBuffer.clear();
+
+
+ }
+ coBundleTrigger.reset();
+ }
+
+ protected abstract void processBundles(BufferBundle leftBuffer,
BufferBundle rightBuffer)
+ throws Exception;
+
+ private BufferBundle initialBuffer(JoinInputSideSpec inputSideSpec) {
+ if (inputSideSpec.joinKeyContainsUniqueKey()) {
+ return new JoinKeyContainsUniqueKeyBundle();
+ }
+ if (inputSideSpec.hasUniqueKey()) {
+ return new InputSideHasUniqueKeyBundle();
+ }
+ return new InputSideHasNoUniqueKeyBundle();
+ }
+
+ private void processElementWithSuppress(
+ Iterator<RowData> iter,
+ JoinRecordStateView inputSideStateView,
+ JoinRecordStateView otherSideStateView,
+ boolean inputIsLeft)
+ throws Exception {
+ RowData pre = null; // always retractMsg if not null
+ while (iter.hasNext()) {
+ RowData current = iter.next();
+ boolean isSuppress = false;
+ if (RowDataUtil.isRetractMsg(current) && iter.hasNext()) {
+ RowData next = iter.next();
+ if (RowDataUtil.isAccumulateMsg(next)) {
+ isSuppress = true;
+ } else {
+ // retract + retract
+ pre = next;
+ }
+ processElement(
+ current, inputSideStateView, otherSideStateView,
inputIsLeft, isSuppress);
+ if (isSuppress) {
+ processElement(
+ next, inputSideStateView, otherSideStateView,
inputIsLeft, isSuppress);
+ }
+ } else {
+ // 1. current is accumulateMsg 2. current is retractMsg and no
next row
+ if (pre != null) {
+ if (RowDataUtil.isAccumulateMsg(current)) {
+ isSuppress = true;
+ }
+ processElement(
+ pre, inputSideStateView, otherSideStateView,
inputIsLeft, isSuppress);
+ pre = null;
+ }
+ processElement(
+ current, inputSideStateView, otherSideStateView,
inputIsLeft, isSuppress);
+ }
+ }
+ }
+
+ /**
+ * RetractMsg+accumulatingMsg would be optimized which would keep sending
retractMsg but do not
+ * deal with state.
+ */
+ protected void processSingleSideBundles(
+ BufferBundle inputBuffer,
+ JoinRecordStateView inputSideStateView,
+ JoinRecordStateView otherSideStateView,
+ boolean inputIsLeft)
+ throws Exception {
+ if (inputBuffer instanceof InputSideHasNoUniqueKeyBundle) {
+ // -U/+U pair is already folded in the buffer so it is no need to
go to
+ // processElementByPair function
+ for (Map.Entry<RowData, List<RowData>> entry :
inputBuffer.getRecords().entrySet()) {
+ // set state key first
+ setCurrentKey(entry.getKey());
+ for (RowData rowData : entry.getValue()) {
+ processElement(
+ rowData, inputSideStateView, otherSideStateView,
inputIsLeft, false);
+ }
+ }
+ } else if (inputBuffer instanceof JoinKeyContainsUniqueKeyBundle) {
+ for (Map.Entry<RowData, List<RowData>> entry :
inputBuffer.getRecords().entrySet()) {
+ // set state key first
+ setCurrentKey(entry.getKey());
+ Iterator<RowData> iter = entry.getValue().iterator();
+ processElementWithSuppress(
+ iter, inputSideStateView, otherSideStateView,
inputIsLeft);
+ }
+ } else {
+ for (RowData jk : inputBuffer.getJoinKeys()) {
+ // set state key first
+ setCurrentKey(jk);
+ for (Map.Entry<RowData, List<RowData>> entry :
+ inputBuffer.getRecordsWithJoinKey(jk).entrySet()) {
+ Iterator<RowData> iter = entry.getValue().iterator();
+ processElementWithSuppress(
+ iter, inputSideStateView, otherSideStateView,
inputIsLeft);
+ }
+ }
+ }
+ }
+
+ public static MiniBatchStreamingJoinOperator
newMiniBatchStreamJoinOperator(
+ FlinkJoinType joinType,
+ InternalTypeInfo<RowData> leftType,
+ InternalTypeInfo<RowData> rightType,
+ GeneratedJoinCondition generatedJoinCondition,
+ JoinInputSideSpec leftInputSideSpec,
+ JoinInputSideSpec rightInputSideSpec,
+ boolean leftIsOuter,
+ boolean rightIsOuter,
+ boolean[] filterNullKeys,
+ long leftStateRetentionTime,
+ long rightStateRetentionTime,
+ CoBundleTrigger<RowData, RowData> coBundleTrigger) {
+ MiniBatchStreamingJoinParameter parameter =
+ new MiniBatchStreamingJoinParameter(
+ leftType,
+ rightType,
+ generatedJoinCondition,
+ leftInputSideSpec,
+ rightInputSideSpec,
+ leftIsOuter,
+ rightIsOuter,
+ filterNullKeys,
+ leftStateRetentionTime,
+ rightStateRetentionTime,
+ coBundleTrigger);
+ switch (joinType) {
+ case INNER:
+ return new MiniBatchInnerJoinStreamOperator(parameter);
+ case LEFT:
+ return new MiniBatchLeftOuterJoinStreamOperator(parameter);
+ case RIGHT:
+ return new MiniBatchRightOuterJoinStreamOperator(parameter);
+ case FULL:
+ return new MiniBatchFullOuterJoinStreamOperator(parameter);
+ default:
+ throw new UnsupportedOperationException("Unsupported join
type: " + joinType);
+ }
+ }
+
+ static class MiniBatchStreamingJoinParameter implements Serializable {
+ InternalTypeInfo<RowData> leftType;
+ InternalTypeInfo<RowData> rightType;
+ GeneratedJoinCondition generatedJoinCondition;
+ JoinInputSideSpec leftInputSideSpec;
+ JoinInputSideSpec rightInputSideSpec;
+ boolean leftIsOuter;
+ boolean rightIsOuter;
+ boolean[] filterNullKeys;
+ long leftStateRetentionTime;
+ long rightStateRetentionTime;
+
+ CoBundleTrigger<RowData, RowData> coBundleTrigger;
+
+ MiniBatchStreamingJoinParameter(
+ InternalTypeInfo<RowData> leftType,
+ InternalTypeInfo<RowData> rightType,
+ GeneratedJoinCondition generatedJoinCondition,
+ JoinInputSideSpec leftInputSideSpec,
+ JoinInputSideSpec rightInputSideSpec,
+ boolean leftIsOuter,
+ boolean rightIsOuter,
+ boolean[] filterNullKeys,
+ long leftStateRetentionTime,
+ long rightStateRetentionTime,
+ CoBundleTrigger<RowData, RowData> coBundleTrigger) {
+ this.leftType = leftType;
+ this.rightType = rightType;
+ this.generatedJoinCondition = generatedJoinCondition;
+ this.leftInputSideSpec = leftInputSideSpec;
+ this.rightInputSideSpec = rightInputSideSpec;
+ this.leftIsOuter = leftIsOuter;
+ this.rightIsOuter = rightIsOuter;
+ this.filterNullKeys = filterNullKeys;
+ this.leftStateRetentionTime = leftStateRetentionTime;
+ this.rightStateRetentionTime = rightStateRetentionTime;
+ this.coBundleTrigger = coBundleTrigger;
+ }
+ }
+
+ /** Inner MiniBatch Join operator. */
+ private static class MiniBatchInnerJoinStreamOperator extends
MiniBatchStreamingJoinOperator {
+
+ public
MiniBatchInnerJoinStreamOperator(MiniBatchStreamingJoinParameter parameter) {
+ super(parameter);
+ }
+
+ @Override
+ protected void processBundles(BufferBundle leftBuffer, BufferBundle
rightBuffer)
+ throws Exception {
+ // process right
+ this.processSingleSideBundles(
+ rightBuffer, rightRecordStateView, leftRecordStateView,
false);
+ // process left
+ this.processSingleSideBundles(
+ leftBuffer, leftRecordStateView, rightRecordStateView,
true);
+ }
+ }
+
+ /** MiniBatch Left outer join operator. */
+ private static class MiniBatchLeftOuterJoinStreamOperator
+ extends MiniBatchStreamingJoinOperator {
+
+ public
MiniBatchLeftOuterJoinStreamOperator(MiniBatchStreamingJoinParameter parameter)
{
+ super(parameter);
+ }
+
+ @Override
+ protected void processBundles(BufferBundle leftBuffer, BufferBundle
rightBuffer)
+ throws Exception {
+ // more efficient to process right first for left out join, i.e,
some retractions can be
+ // avoided
+ // process right
+ this.processSingleSideBundles(
+ rightBuffer, rightRecordStateView, leftRecordStateView,
false);
+ // process left
+ this.processSingleSideBundles(
+ leftBuffer, leftRecordStateView, rightRecordStateView,
true);
+ }
+ }
+
+ /** MiniBatch Right outer join operator. */
+ private static class MiniBatchRightOuterJoinStreamOperator
+ extends MiniBatchStreamingJoinOperator {
+
+ public
MiniBatchRightOuterJoinStreamOperator(MiniBatchStreamingJoinParameter
parameter) {
+ super(parameter);
+ }
+
+ @Override
+ protected void processBundles(BufferBundle leftBuffer, BufferBundle
rightBuffer)
+ throws Exception {
+
Review Comment:
ping again
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/join/stream/MiniBatchStreamingJoinOperator.java:
##########
@@ -0,0 +1,416 @@
+/*
+ * 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.runtime.operators.join.stream;
+
+import org.apache.flink.streaming.api.watermark.Watermark;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.util.RowDataUtil;
+import org.apache.flink.table.runtime.generated.GeneratedJoinCondition;
+import
org.apache.flink.table.runtime.operators.bundle.trigger.BundleTriggerCallback;
+import org.apache.flink.table.runtime.operators.bundle.trigger.CoBundleTrigger;
+import org.apache.flink.table.runtime.operators.join.FlinkJoinType;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.BufferBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasNoUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.InputSideHasUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.bundle.JoinKeyContainsUniqueKeyBundle;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinRecordStateView;
+import org.apache.flink.table.runtime.operators.metrics.SimpleGauge;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/** Streaming unbounded Join base operator which support mini-batch join. */
+public abstract class MiniBatchStreamingJoinOperator extends
StreamingJoinOperator
+ implements BundleTriggerCallback {
+
+ private static final long serialVersionUID = -1106342589994963997L;
+
+ private final CoBundleTrigger<RowData, RowData> coBundleTrigger;
+
+ private transient BufferBundle leftBuffer;
+ private transient BufferBundle rightBuffer;
+ private transient SimpleGauge<Integer> leftBundleReducedSizeGauge;
+ private transient SimpleGauge<Integer> rightBundleReducedSizeGauge;
+
+ public MiniBatchStreamingJoinOperator(MiniBatchStreamingJoinParameter
parameter) {
+ super(
+ parameter.leftType,
+ parameter.rightType,
+ parameter.generatedJoinCondition,
+ parameter.leftInputSideSpec,
+ parameter.rightInputSideSpec,
+ parameter.leftIsOuter,
+ parameter.rightIsOuter,
+ parameter.filterNullKeys,
+ parameter.leftStateRetentionTime,
+ parameter.rightStateRetentionTime);
+
+ this.coBundleTrigger = parameter.coBundleTrigger;
+ }
+
+ @Override
+ public void open() throws Exception {
+ super.open();
+
+ this.leftBuffer = initialBuffer(leftInputSideSpec);
+ this.rightBuffer = initialBuffer(rightInputSideSpec);
+
+ coBundleTrigger.registerCallback(this);
+ coBundleTrigger.reset();
+ LOG.info("Initialize MiniBatchStreamingJoinOperator successfully.");
+
+ // register metrics
+ leftBundleReducedSizeGauge = new SimpleGauge<>(0);
+ rightBundleReducedSizeGauge = new SimpleGauge<>(0);
+
+ getRuntimeContext()
+ .getMetricGroup()
+ .gauge("leftBundleReducedSize", leftBundleReducedSizeGauge);
+ getRuntimeContext()
+ .getMetricGroup()
+ .gauge("rightBundleReducedSize", rightBundleReducedSizeGauge);
+ }
+
+ @Override
+ public void processElement1(StreamRecord<RowData> element) throws
Exception {
+ RowData joinKey = (RowData) getCurrentKey();
+ RowData uniqueKey = null;
+ if (leftInputSideSpec.getUniqueKeySelector() != null) {
+ uniqueKey =
leftInputSideSpec.getUniqueKeySelector().getKey(element.getValue());
+ }
+ leftBuffer.addRecord(joinKey, uniqueKey, element.getValue());
+ coBundleTrigger.onElement1(element.getValue());
+ }
+
+ @Override
+ public void processElement2(StreamRecord<RowData> element) throws
Exception {
+ RowData joinKey = (RowData) getCurrentKey();
+ RowData uniqueKey = null;
+ if (rightInputSideSpec.getUniqueKeySelector() != null) {
+ uniqueKey =
rightInputSideSpec.getUniqueKeySelector().getKey(element.getValue());
+ }
+ rightBuffer.addRecord(joinKey, uniqueKey, element.getValue());
+ coBundleTrigger.onElement2(element.getValue());
+ }
+
+ @Override
+ public void processWatermark1(Watermark mark) throws Exception {
+ finishBundle();
+ super.processWatermark1(mark);
+ }
+
+ @Override
+ public void processWatermark2(Watermark mark) throws Exception {
+ finishBundle();
+ super.processWatermark2(mark);
+ }
+
+ @Override
+ public void prepareSnapshotPreBarrier(long checkpointId) throws Exception {
+ finishBundle();
+ }
+
+ @Override
+ public void finish() throws Exception {
Review Comment:
ping again
##########
flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/join/stream/StreamingMiniBatchJoinOperatorTest.java:
##########
@@ -0,0 +1,1807 @@
+/*
+ * 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.runtime.operators.join.stream;
+
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.runtime.keyselector.RowDataKeySelector;
+import
org.apache.flink.table.runtime.operators.bundle.trigger.CountCoBundleTrigger;
+import org.apache.flink.table.runtime.operators.join.FlinkJoinType;
+import
org.apache.flink.table.runtime.operators.join.stream.state.JoinInputSideSpec;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+import org.apache.flink.table.types.logical.CharType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.utils.HandwrittenSelectorUtil;
+import org.apache.flink.types.RowKind;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Stream;
+
+import static
org.apache.flink.table.runtime.util.StreamRecordUtils.deleteRecord;
+import static
org.apache.flink.table.runtime.util.StreamRecordUtils.insertRecord;
+import static org.apache.flink.table.runtime.util.StreamRecordUtils.rowOfKind;
+import static
org.apache.flink.table.runtime.util.StreamRecordUtils.updateAfterRecord;
+import static
org.apache.flink.table.runtime.util.StreamRecordUtils.updateBeforeRecord;
+
+/** Test for StreamingMiniBatchJoinOperatorTest. */
+public final class StreamingMiniBatchJoinOperatorTest extends
StreamingJoinOperatorTestBase {
+
+ private RowDataKeySelector leftUniqueKeySelector;
+ private RowDataKeySelector rightUniqueKeySelector;
+
+ @BeforeEach
+ public void beforeEach(TestInfo testInfo) throws Exception {
+ rightTypeInfo =
+ InternalTypeInfo.of(
+ RowType.of(
+ new LogicalType[] {
+ new CharType(false, 20),
+ new CharType(false, 20),
+ new CharType(true, 10)
+ },
+ new String[] {
+ "order_id#", "line_order_id0",
"line_order_ship_mode"
+ }));
+
+ rightKeySelector =
+ HandwrittenSelectorUtil.getRowDataSelector(
+ new int[] {1},
+ rightTypeInfo.toRowType().getChildren().toArray(new
LogicalType[0]));
+ super.beforeEach(testInfo);
+ }
+
+ @Tag("miniBatchSize=3")
+ @Test
+ public void testLeftJoinWithLeftArriveFirst() throws Exception {
+ // joinKey is LineOrd
+ // left fold || right fold
+ testHarness.processElement1(
+ insertRecord(
+ "Ord#1", "LineOrd#2", "3 Bellevue Drive, Pottstown, PA
19464")); // left +I
+ testHarness.processElement1(
+ insertRecord(
+ "Ord#i",
+ "LineOrd#6",
+ "i6 Bellevue Drive, Pottstown, Pi 19464")); // left +I
+ assertor.shouldEmitNothing(testHarness);
+ testHarness.processElement2(insertRecord("Ord#X", "LineOrd#2",
"AIR")); // right
+
+ assertor.shouldEmit(
+ testHarness,
+ rowOfKind(
+ RowKind.INSERT,
+ "Ord#i",
+ "LineOrd#6",
+ "i6 Bellevue Drive, Pottstown, Pi 19464",
+ null,
+ null,
+ null),
+ rowOfKind(
+ RowKind.INSERT,
+ "Ord#1",
+ "LineOrd#2",
+ "3 Bellevue Drive, Pottstown, PA 19464",
+ "Ord#X",
+ "LineOrd#2",
+ "AIR"));
+ }
+
+ @Tag("miniBatchSize=1")
+ @Test
+ public void testLeftJoinWithLeftArriveFirstNoMiniBatch() throws Exception {
+ // joinKey is LineOrd
+ // left fold || right fold
+ testHarness.processElement1(
+ insertRecord(
+ "Ord#1", "LineOrd#2", "3 Bellevue Drive, Pottstown, PA
19464")); // left +I
+
+ testHarness.processElement1(
+ insertRecord(
+ "Ord#i",
+ "LineOrd#6",
+ "i6 Bellevue Drive, Pottstown, Pi 19464")); // left +I
+ testHarness.processElement2(insertRecord("Ord#X", "LineOrd#2",
"AIR")); // right
+
+ assertor.shouldEmit(
+ testHarness,
+ rowOfKind(
+ RowKind.INSERT,
+ "Ord#1",
+ "LineOrd#2",
+ "3 Bellevue Drive, Pottstown, PA 19464",
+ null,
+ null,
+ null),
+ rowOfKind(
+ RowKind.INSERT,
+ "Ord#i",
+ "LineOrd#6",
+ "i6 Bellevue Drive, Pottstown, Pi 19464",
+ null,
+ null,
+ null),
+ rowOfKind(
+ RowKind.DELETE,
+ "Ord#1",
+ "LineOrd#2",
+ "3 Bellevue Drive, Pottstown, PA 19464",
+ null,
+ null,
+ null),
+ rowOfKind(
+ RowKind.INSERT,
+ "Ord#1",
+ "LineOrd#2",
+ "3 Bellevue Drive, Pottstown, PA 19464",
+ "Ord#X",
+ "LineOrd#2",
+ "AIR"));
+ }
+
+ @Tag("miniBatchSize=3")
+ @Test
+ public void testRightJoinWithRightArriveFirst() throws Exception {
+ // joinKey is LineOrd
+ // left fold || right fold
+ testHarness.processElement2(insertRecord("Ord#X", "LineOrd#2",
"AIR")); // right
+
+ testHarness.processElement1(
+ insertRecord(
+ "Ord#1", "LineOrd#2", "3 Bellevue Drive, Pottstown, PA
19464")); // left +I
+ assertor.shouldEmitNothing(testHarness);
+ testHarness.processElement1(
+ insertRecord(
+ "Ord#i",
+ "LineOrd#6",
+ "i6 Bellevue Drive, Pottstown, Pi 19464")); // left +I
+
+ assertor.shouldEmit(
+ testHarness,
+ rowOfKind(
+ RowKind.INSERT,
+ "Ord#1",
+ "LineOrd#2",
+ "3 Bellevue Drive, Pottstown, PA 19464",
+ "Ord#X",
+ "LineOrd#2",
+ "AIR"));
+ }
+
+ @Tag("miniBatchSize=1")
+ @Test
+ public void testRightJoinWithRightArriveFirstWithNoMiniBatch() throws
Exception {
+ // joinKey is LineOrd
+ // left fold || right fold
+ testHarness.processElement2(insertRecord("Ord#X", "LineOrd#2",
"AIR")); // right
+
+ testHarness.processElement1(
+ insertRecord(
+ "Ord#1", "LineOrd#2", "3 Bellevue Drive, Pottstown, PA
19464")); // left +I
+ testHarness.processElement1(
+ insertRecord(
+ "Ord#i",
+ "LineOrd#6",
+ "i6 Bellevue Drive, Pottstown, Pi 19464")); // left +I
+
+ assertor.shouldEmit(
+ testHarness,
+ rowOfKind(RowKind.INSERT, null, null, null, "Ord#X",
"LineOrd#2", "AIR"),
+ rowOfKind(RowKind.DELETE, null, null, null, "Ord#X",
"LineOrd#2", "AIR"),
+ rowOfKind(
+ RowKind.INSERT,
+ "Ord#1",
+ "LineOrd#2",
+ "3 Bellevue Drive, Pottstown, PA 19464",
+ "Ord#X",
+ "LineOrd#2",
+ "AIR"));
+ }
+
+ @Tag("miniBatchSize=3")
+ @Test
+ public void testFullJoinWithRightArriveFirst() throws Exception {
+ // joinKey is LineOrd
+ // left fold || right fold
+ testHarness.processElement2(insertRecord("Ord#X", "LineOrd#2",
"AIR")); // right
+
+ testHarness.processElement1(
+ insertRecord(
+ "Ord#1", "LineOrd#2", "3 Bellevue Drive, Pottstown, PA
19464")); // left +I
+ assertor.shouldEmitNothing(testHarness);
+ testHarness.processElement1(
+ insertRecord(
+ "Ord#i",
+ "LineOrd#6",
+ "i6 Bellevue Drive, Pottstown, Pi 19464")); // left +I
+
+ assertor.shouldEmit(
+ testHarness,
+ rowOfKind(RowKind.INSERT, null, null, null, "Ord#X",
"LineOrd#2", "AIR"),
+ rowOfKind(
+ RowKind.INSERT,
+ "Ord#i",
+ "LineOrd#6",
+ "i6 Bellevue Drive, Pottstown, Pi 19464",
+ null,
+ null,
+ null),
+ rowOfKind(RowKind.DELETE, null, null, null, "Ord#X",
"LineOrd#2", "AIR"),
+ rowOfKind(
+ RowKind.INSERT,
+ "Ord#1",
+ "LineOrd#2",
+ "3 Bellevue Drive, Pottstown, PA 19464",
+ "Ord#X",
+ "LineOrd#2",
+ "AIR"));
+ }
+
+ @Tag("miniBatchSize=1")
+ @Test
+ public void testFullJoinWithRightArriveFirstWithNoMiniBatch() throws
Exception {
+ // joinKey is LineOrd
+ // left fold || right fold
Review Comment:
I think the above six tests doesn't test the fold logic, only for reducing
retract message of timing-related left and right stream.
--
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]