Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/flink.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ jobs:
export VELOX_DEPENDENCY_SOURCE=BUNDLED
export fmt_SOURCE=BUNDLED
export folly_SOURCE=BUNDLED
git clone -b feature/watermark-status-propagation https://github.com/bigo-sg/velox4j.git
cd velox4j && git reset --hard 6e2046f
git clone -b gluten-0530 https://github.com/bigo-sg/velox4j.git
cd velox4j && git reset --hard f8684c84ac68729f1370be1ee6a80a0fe4738818
git apply $GITHUB_WORKSPACE/gluten-flink/patches/fix-velox4j.patch
Comment thread
zhanglistar marked this conversation as resolved.
$GITHUB_WORKSPACE/build/mvn clean install -DskipTests -Dgpg.skip -Dspotless.skip=true
cd ..
Expand Down
41 changes: 41 additions & 0 deletions gluten-flink/patches/fix-velox4j.patch
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
diff --git a/src/main/cpp/CMakeLists.txt b/src/main/cpp/CMakeLists.txt
index 9ed0551..5ded913 100644
--- a/src/main/cpp/CMakeLists.txt
+++ b/src/main/cpp/CMakeLists.txt
@@ -82,7 +82,7 @@ else()
GIT_REPOSITORY
${VELOX_SOURCE_URL}
GIT_TAG
- c9efdf308a94ea1cb846e2440aeb975572497d87)
+ bfa91ab98d6b53fccf2c862cdc926832835db35c)
endif()
if(TARGET gflags::gflags_shared)
get_target_property(GFLAGS_SHARED_LIBRARY gflags::gflags_shared
diff --git a/src/main/cpp/main/CMakeLists.txt b/src/main/cpp/main/CMakeLists.txt
index ada06f8..7ed80bb 100644
--- a/src/main/cpp/main/CMakeLists.txt
Expand All @@ -15,3 +28,31 @@ index ada06f8..7ed80bb 100644
message(\"Found all shared 3rd dependencies of velox4j: \${3rd_deps}\")
foreach(dep IN LISTS 3rd_deps)
get_filename_component(link_name \${dep} NAME)
diff --git a/src/main/cpp/main/velox4j/query/StatefulQueryExecutor.cc b/src/main/cpp/main/velox4j/query/StatefulQueryExecutor.cc
index 2357cf2..159e3d6 100644
--- a/src/main/cpp/main/velox4j/query/StatefulQueryExecutor.cc
+++ b/src/main/cpp/main/velox4j/query/StatefulQueryExecutor.cc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch should be applied to velox4j

@@ -81,15 +81,8 @@ StatefulSerialTask::StatefulSerialTask(
}

StatefulSerialTask::~StatefulSerialTask() {
- if (task_ != nullptr && task_->isRunning()) {
- // TODO: add a method to finish the task and set state.
- task_->finish();
- // FIXME: Calling .wait() may take no effect in single thread execution
- // mode.
- task_->requestCancel().wait();
- }
if (task_ != nullptr) {
- task_->setNativeCallbackBridge(nullptr);
+ task_->close();
}
task_.reset();
}
diff --git a/src/main/cpp/velox-ref.txt b/src/main/cpp/velox-ref.txt
index c24a828..47d494e 100644
--- a/src/main/cpp/velox-ref.txt
+++ b/src/main/cpp/velox-ref.txt
@@ -1 +1 @@
-c9efdf308a94ea1cb846e2440aeb975572497d87
+bfa91ab98d6b53fccf2c862cdc926832835db35c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ protected Transformation<RowData> translateToPlanInternal(
// TODO: velox's parallelism need to be set here, as some nodes need it.
// should set it when operator init.
parallelism = inputTransform.getParallelism();
keySelector = new GlutenKeySelector();
final ExecEdge inputEdge = getInputEdges().get(0);
io.github.zhztheplayer.velox4j.type.RowType glutenInputType =
(io.github.zhztheplayer.velox4j.type.RowType)
Expand Down Expand Up @@ -181,7 +180,8 @@ protected Transformation<RowData> translateToPlanInternal(
parallelism,
false);
partitioner =
new GlutenKeyGroupStreamPartitioner(keySelector, DEFAULT_LOWER_BOUND_MAX_PARALLELISM);
new GlutenKeyGroupStreamPartitioner(
new GlutenKeySelector(), keySelector, DEFAULT_LOWER_BOUND_MAX_PARALLELISM);
} else {
parallelism = ExecutionConfig.PARALLELISM_DEFAULT;
partitioner =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.flink.FlinkVersion;
import org.apache.flink.api.dag.Transformation;
import org.apache.flink.configuration.ReadableConfig;
import org.apache.flink.streaming.api.operators.StreamOperator;
import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
import org.apache.flink.streaming.api.transformations.TwoInputTransformation;
import org.apache.flink.table.data.RowData;
Expand Down Expand Up @@ -325,30 +324,15 @@ protected Transformation<RowData> translateToPlanInternal(
}

final RowType returnType = (RowType) getOutputType();
final TwoInputTransformation<RowData, RowData, RowData> transform;
if (operator instanceof GlutenTwoInputOperator) {
transform =
ExecNodeUtil.createTwoInputTransformation(
leftTransform,
rightTransform,
createTransformationMeta(JOIN_TRANSFORMATION, config),
new GlutenTwoInputOperatorFactory<RowData, RowData, RowData>(
(StreamOperator<RowData>) operator),
InternalTypeInfo.of(returnType),
leftTransform.getParallelism(),
0L,
false);
} else {
transform =
ExecNodeUtil.createTwoInputTransformation(
leftTransform,
rightTransform,
createTransformationMeta(JOIN_TRANSFORMATION, config),
operator,
InternalTypeInfo.of(returnType),
leftTransform.getParallelism(),
false);
}
final TwoInputTransformation<RowData, RowData, RowData> transform =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If operator is not GlutenTwoInputOperator, I think we should fallback to original flink operator

ExecNodeUtil.createTwoInputTransformation(
leftTransform,
rightTransform,
createTransformationMeta(JOIN_TRANSFORMATION, config),
new GlutenTwoInputOperatorFactory<>(operator),
InternalTypeInfo.of(returnType),
leftTransform.getParallelism(),
0L);

// set KeyType and Selector for state
RowDataKeySelector leftSelect =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.flink.FlinkVersion;
import org.apache.flink.api.dag.Transformation;
import org.apache.flink.configuration.ReadableConfig;
import org.apache.flink.streaming.api.operators.StreamOperator;
import org.apache.flink.streaming.api.operators.TwoInputStreamOperator;
import org.apache.flink.streaming.api.transformations.TwoInputTransformation;
import org.apache.flink.table.api.TableException;
Expand Down Expand Up @@ -247,12 +246,10 @@ protected Transformation<RowData> translateToPlanInternal(
leftTransform,
rightTransform,
createTransformationMeta(WINDOW_JOIN_TRANSFORMATION, config),
new GlutenTwoInputOperatorFactory<RowData, RowData, RowData>(
(StreamOperator<RowData>) operator),
new GlutenTwoInputOperatorFactory<>(operator),
InternalTypeInfo.of(returnType),
leftTransform.getParallelism(),
0L,
false);
0L);

// set KeyType and Selector for state
RowDataKeySelector leftSelect =
Expand Down
2 changes: 2 additions & 0 deletions gluten-flink/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<properties>
<flink.version>1.19.2</flink.version>
<velox4j.version>0.1.0-SNAPSHOT</velox4j.version>
<protobuf.version>3.25.5</protobuf.version>
<hadoop.version>2.7.2</hadoop.version>
Comment on lines 31 to +35
<scala.binary.version>2.12</scala.binary.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
*/
package org.apache.gluten.client;

import org.apache.gluten.streaming.api.operators.GlutenOneInputOperatorFactory;
import org.apache.gluten.streaming.api.operators.GlutenOperator;
import org.apache.gluten.streaming.api.operators.GlutenStreamSource;
import org.apache.gluten.streaming.api.operators.GlutenTwoInputOperatorFactory;
import org.apache.gluten.table.runtime.keyselector.GlutenKeySelector;
import org.apache.gluten.table.runtime.operators.GlutenOneInputOperator;
import org.apache.gluten.table.runtime.operators.GlutenSourceFunction;
Expand Down Expand Up @@ -243,16 +241,16 @@ private void createOffloadedOneInputOperator(
Class<?> outClass = supportsVectorOutput ? StatefulRecord.class : RowData.class;
GlutenOneInputOperator<?, ?> newOneInputOp =
sourceOperator.cloneWithInputOutputClasses(planNode, inClass, outClass);
// setStreamOperator would wrap this in Flink's SimpleOperatorFactory and skip Gluten-specific
// mailbox binding performed by GlutenOneInputOperatorFactory.
offloadedOpConfig.setStreamOperatorFactory(new GlutenOneInputOperatorFactory<>(newOneInputOp));
offloadedOpConfig.setStreamOperator(newOneInputOp);
if (supportsVectorOutput) {
setOffloadedOutputSerializer(offloadedOpConfig, sourceOperator);
}
if (supportsVectorInput) {
setOffloadedInputSerializer(offloadedOpConfig, sourceOperator);
setOffloadedStatePartitioner(
sourceOpConfig, offloadedOpConfig, 0, sourceOperator.getDescription());
} else {
offloadedOpConfig.setupNetworkInputs(sourceOpConfig.getTypeSerializerIn1(userClassloader));
}
}

Expand Down Expand Up @@ -283,17 +281,18 @@ private void createOffloadedTwoInputOperator(
sourceOperator.getOutputTypes(),
inClass,
outClass);
// setStreamOperator would wrap this in Flink's SimpleOperatorFactory, which only initializes
// ProcessingTimeService for Flink AbstractStreamOperator. GlutenTwoInputOperator uses
// GlutenAbstractStreamOperator so it needs the Gluten-specific factory.
offloadedOpConfig.setStreamOperatorFactory(new GlutenTwoInputOperatorFactory<>(newTwoInputOp));
offloadedOpConfig.setStreamOperator(newTwoInputOp);
offloadedOpConfig.setStatePartitioner(0, new GlutenKeySelector());
Comment on lines 280 to 285
offloadedOpConfig.setStatePartitioner(1, new GlutenKeySelector());
if (supportsVectorOutput) {
setOffloadedOutputSerializer(offloadedOpConfig, sourceOperator);
}
if (supportsVectorInput) {
setOffloadedInputSerializersForTwoInputOperator(offloadedOpConfig, sourceOperator);
} else {
offloadedOpConfig.setupNetworkInputs(
sourceOpConfig.getTypeSerializerIn1(userClassloader),
sourceOpConfig.getTypeSerializerIn2(userClassloader));
}
}

Expand Down Expand Up @@ -486,6 +485,9 @@ private void updateStatePartitioners(StreamConfig sourceConfig, StreamConfig off

private boolean supportsVectorOutput(
OperatorChainSlice chainSlice, OperatorChainSliceGraph chainSliceGraph, JobVertex jobVertex) {
if (isStreamExecExchange(chainSlice)) {
return false;
}
List<Integer> downstreamSliceIds = chainSlice.getOutputs();

// If chainSlice has downstream in the operator chain, check these downstream
Expand All @@ -498,11 +500,22 @@ private boolean supportsVectorOutput(
}
}

private boolean isStreamExecExchange(OperatorChainSlice chainSlice) {
for (StreamConfig opConfig : chainSlice.getOperatorConfigs()) {
Optional<GlutenOperator> glutenOperator = Utils.getGlutenOperator(opConfig, userClassloader);
if (glutenOperator.isPresent()
&& "StreamExecExchange".equals(glutenOperator.get().getDescription())) {
return true;
}
}
return false;
}

private boolean checkDownstreamSlicesInChain(
OperatorChainSliceGraph chainSliceGraph, List<Integer> downstreamSliceIds) {
for (Integer downstreamSliceId : downstreamSliceIds) {
OperatorChainSlice downstreamSlice = chainSliceGraph.getSlice(downstreamSliceId);
if (!downstreamSlice.isOffloadable()) {
if (!downstreamSlice.isOffloadable() || isStreamExecExchange(downstreamSlice)) {
return false;
}
if (!downstreamSlice.getInputs().stream()
Expand All @@ -521,16 +534,7 @@ private boolean checkDownstreamVerticesFromJobGraph(JobVertex jobVertex) {
// conversion)
return true;
}
// Check if all downstream vertices' operators are gluten operators
for (JobVertex downstreamVertex : downstreamVertices) {
StreamConfig downstreamStreamConfig = new StreamConfig(downstreamVertex.getConfiguration());
Optional<GlutenOperator> glutenOperator =
Utils.getGlutenOperator(downstreamStreamConfig, userClassloader);
if (!glutenOperator.isPresent()) {
return false;
}
}
return true;
return false;
}

private boolean supportsVectorInput(
Expand Down Expand Up @@ -569,16 +573,7 @@ private boolean checkUpstreamVerticesFromJobGraph(JobVertex jobVertex) {
// If there is no upstream JobVertex, can input RowVector (no upstream needs conversion)
return true;
}
// Check if the last operator of all upstream vertices are gluten operators
for (JobVertex upstreamVertex : upstreamVertices) {
StreamConfig lastOperatorConfig = findLastOperatorInChain(upstreamVertex);
Optional<GlutenOperator> glutenOperator =
Utils.getGlutenOperator(lastOperatorConfig, userClassloader);
if (!glutenOperator.isPresent()) {
return false;
}
}
return true;
return false;
}

/** Get all downstream JobVertices of a JobVertex. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.flink.streaming.runtime.partitioner.ConfigurableStreamPartitioner;
import org.apache.flink.streaming.runtime.partitioner.StreamPartitioner;
import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
import org.apache.flink.table.data.RowData;
import org.apache.flink.util.Preconditions;

import java.util.Objects;
Expand All @@ -41,13 +42,22 @@ public class GlutenKeyGroupStreamPartitioner extends StreamPartitioner<StatefulR
private static final long serialVersionUID = 1L;

private final KeySelector<StatefulRecord, Integer> keySelector;
private final KeySelector<RowData, ?> rowDataKeySelector;

private int maxParallelism;

public GlutenKeyGroupStreamPartitioner(
KeySelector<StatefulRecord, Integer> keySelector, int maxParallelism) {
this(keySelector, null, maxParallelism);
}

public GlutenKeyGroupStreamPartitioner(
KeySelector<StatefulRecord, Integer> keySelector,
KeySelector<RowData, ?> rowDataKeySelector,
int maxParallelism) {
Preconditions.checkArgument(maxParallelism > 0, "Number of key-groups must be > 0!");
this.keySelector = Preconditions.checkNotNull(keySelector);
this.rowDataKeySelector = rowDataKeySelector;
this.maxParallelism = maxParallelism;
}

Expand All @@ -57,12 +67,19 @@ public int getMaxParallelism() {

@Override
public int selectChannel(SerializationDelegate<StreamRecord<StatefulRecord>> record) {
Object value = record.getInstance().getValue();
try {
int channel = keySelector.getKey(record.getInstance().getValue());
return channel;
if (value instanceof StatefulRecord) {
return keySelector.getKey((StatefulRecord) value);
}
Preconditions.checkState(
rowDataKeySelector != null,
"RowData key selector is required when partitioning non-StatefulRecord values.");
Object key = rowDataKeySelector.getKey((RowData) value);
return KeyGroupRangeAssignment.assignKeyToParallelOperator(
key, maxParallelism, numberOfChannels);
} catch (Exception e) {
throw new RuntimeException(
"Could not extract key from " + record.getInstance().getValue(), e);
throw new RuntimeException("Could not extract key from " + value, e);
}
}

Expand Down Expand Up @@ -104,11 +121,13 @@ public boolean equals(Object o) {
return false;
}
final GlutenKeyGroupStreamPartitioner that = (GlutenKeyGroupStreamPartitioner) o;
return maxParallelism == that.maxParallelism && keySelector.equals(that.keySelector);
return maxParallelism == that.maxParallelism
&& keySelector.equals(that.keySelector)
&& Objects.equals(rowDataKeySelector, that.rowDataKeySelector);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), keySelector, maxParallelism);
return Objects.hash(super.hashCode(), keySelector, rowDataKeySelector, maxParallelism);
}
}
Loading
Loading