xishuaidelin commented on code in PR #24160:
URL: https://github.com/apache/flink/pull/24160#discussion_r1465806063


##########
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:
   Yes. I add this to clear the bundle.



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to