Skip to content

[VL] Follow up optimizing BHJ by building hash table in driver side like spark#11993

Merged
JkSelf merged 3 commits into
apache:mainfrom
JkSelf:driver-build-hashtable
Jul 3, 2026
Merged

[VL] Follow up optimizing BHJ by building hash table in driver side like spark#11993
JkSelf merged 3 commits into
apache:mainfrom
JkSelf:driver-build-hashtable

Conversation

@JkSelf

@JkSelf JkSelf commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Further optimize bhj performance by building hash table in driver side.

How was this patch tested?

Existing tests

Was this patch authored or co-authored using generative AI tooling?

Generated-by: bob

@JkSelf JkSelf force-pushed the driver-build-hashtable branch 8 times, most recently from 415a9df to 38347b3 Compare April 30, 2026 12:01
@github-actions github-actions Bot added the DOCS label Apr 30, 2026
@JkSelf JkSelf force-pushed the driver-build-hashtable branch 3 times, most recently from 37c4e55 to 85251b6 Compare May 2, 2026 05:37
@github-actions github-actions Bot added the TOOLS label May 2, 2026
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

2 similar comments
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@JkSelf JkSelf force-pushed the driver-build-hashtable branch from 3059c90 to 1ddf514 Compare May 2, 2026 17:58
@github-actions github-actions Bot removed the TOOLS label May 2, 2026
@JkSelf JkSelf force-pushed the driver-build-hashtable branch 10 times, most recently from 401e02c to 5c7d7fa Compare May 6, 2026 13:49

@zhztheplayer zhztheplayer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@JkSelf JkSelf force-pushed the driver-build-hashtable branch from 1b7c47c to d8bb296 Compare July 1, 2026 02:06
@github-actions github-actions Bot removed the BUILD label Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI review requested due to automatic review settings July 2, 2026 01:46
@JkSelf JkSelf force-pushed the driver-build-hashtable branch from d8bb296 to 8748a71 Compare July 2, 2026 01:46
@github-actions github-actions Bot added the BUILD label Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 33 out of 33 changed files in this pull request and generated 5 comments.

Comment on lines +935 to +940
contexts.find {
ctx =>
val buildOutputMatches = childOutputSet.subsetOf(ctx.buildOutputSet) &&
ctx.buildOutputSet.subsetOf(childOutputSet)
buildOutputMatches
}
Comment on lines +74 to +83
new RemovalListener[String, SerializedBroadcastHashTable] {
override def onRemoval(
key: String,
value: SerializedBroadcastHashTable,
cause: RemovalCause): Unit = {
if (value != null && value.serializedData != null) {
value.serializedData.release()
}
}
}
Comment on lines +124 to +129
val serializedSize = HashJoinBuilder.serializedHashTableSizeDirect(hashTableHandle)
val byteBuffer = JniUnsafeByteBuffer.allocate(serializedSize)
HashJoinBuilder.serializeHashTableDirect(
hashTableHandle,
byteBuffer.address(),
byteBuffer.size())
Comment on lines +49 to +53
out.writeLong(bloomFilterBlocksByteSize)
out.writeLong(hashProbeDynamicFiltersProduced)
serializedData.writeExternal(out)
out.writeObject(buildSideRelation)
}
Comment thread ep/build-velox/src/get-velox.sh Outdated
Comment on lines 19 to 22
CURRENT_DIR=$(cd "$(dirname "$BASH_SOURCE")"; pwd)
VELOX_REPO=https://github.com/IBM/velox.git
VELOX_BRANCH=dft-2026_06_30
VELOX_REPO=https://github.com/JkSelf/velox.git
VELOX_BRANCH=dft-2026_06_30_hashtable_ser
VELOX_ENHANCED_BRANCH=ibm-2026_06_30
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI review requested due to automatic review settings July 3, 2026 03:12
@JkSelf JkSelf force-pushed the driver-build-hashtable branch from ead9402 to 1763724 Compare July 3, 2026 03:12
@github-actions github-actions Bot removed the BUILD label Jul 3, 2026
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 32 out of 32 changed files in this pull request and generated 2 comments.

Comment on lines +185 to 189
if (!dropDuplicates_) {
uniqueTable_->setAllowDuplicates(true);
}
lookup_.reset();
}
Comment on lines +49 to +53
out.writeLong(bloomFilterBlocksByteSize)
out.writeLong(hashProbeDynamicFiltersProduced)
serializedData.writeExternal(out)
out.writeObject(buildSideRelation)
}
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI review requested due to automatic review settings July 3, 2026 04:03
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 32 out of 32 changed files in this pull request and generated 1 comment.

Comment on lines +1069 to +1076
// Return SerializedHashTableBroadcastRelation
SerializedHashTableBroadcastRelation(
serializedHashTable,
safeMode,
newOutput,
0L, // buildTimeMs - tracked inside SerializedBroadcastHashTable
0L // serializeTimeMs - tracked inside SerializedBroadcastHashTable
)
@JkSelf JkSelf force-pushed the driver-build-hashtable branch from c260a52 to 8c4d8a0 Compare July 3, 2026 04:37
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI review requested due to automatic review settings July 3, 2026 05:12
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 32 out of 32 changed files in this pull request and generated 7 comments.

Comment on lines +926 to +942
val joinContextOpt: Option[BroadcastJoinContextInfo] =
findLogicalLink(child).flatMap {
logicalPlan =>
logicalPlan.getTagValue(
BroadcastJoinContextTag.BROADCAST_JOIN_CONTEXT
).flatMap {
contexts =>
val childOutputSet = AttributeSet(newOutput)
// Find the context whose build output matches the child's output
contexts.find {
ctx =>
val buildOutputMatches = childOutputSet.subsetOf(ctx.buildOutputSet) &&
ctx.buildOutputSet.subsetOf(childOutputSet)
buildOutputMatches
}
}
}
Comment on lines +994 to +1018
// Use the join keys from the matched context
// Since we already matched the context by comparing outputs,
// we know this is the correct one
val joinKeys = if (joinContext.buildRight) {
joinContext.originalRightKeys
} else {
joinContext.originalLeftKeys
}
val buildContext = BroadcastHashJoinContext(
buildSideJoinKeys = if (newBuildKeys.nonEmpty) newBuildKeys else joinKeys,
substraitJoinType = substraitJoinType,
buildRight = joinContext.buildRight,
hasMixedFiltCondition = hasMixedFiltCondition,
isExistenceJoin = joinContext.joinType
.isInstanceOf[ExistenceJoin],
buildSideStructure = newOutput,
filterBuildColumns = filterBuildColumns,
filterPropagatesNulls = filterPropagatesNulls,
buildHashTableId = broadcastId,
isNullAwareAntiJoin = joinContext.isNullAwareAntiJoin,
bloomFilterPushdownSize = bloomFilterPushdownSize,
buildHashTableTimeMetric = Option(buildHashTableTimeMetric),
serializeHashTableTimeMetric = Option(serializeHashTableTimeMetric),
serializedHashTableSizeMetric = Option(serializedHashTableSizeMetric)
)
Comment on lines 725 to +729
"buildHashTableTime" -> SQLMetrics.createTimingMetric(
sparkContext,
"time to build hash table")
"time to build hash table"),
"deserializeHashTableTime" -> SQLMetrics.createTimingMetric(
sparkContext,
Comment on lines +136 to +139
val bloomFilterBlocksByteSize = HashJoinBuilder
.getHashTableBloomFilterBlocksByteSize(hashTableHandle)
val hashProbeDynamicFiltersProduced = if (bloomFilterBlocksByteSize > 0) 1L else 0L

Comment on lines +259 to +265
val startTime = System.nanoTime()
val jniWrapper = ColumnarBatchSerializerJniWrapper.create(runtime)
val serializeHandle: Long = {
val allocator = ArrowBufferAllocators.globalInstance()
val cSchema = ArrowSchema.allocateNew(allocator)
val arrowSchema = SparkArrowUtil.toArrowSchema(
SparkShimLoader.getSparkShims.structFromAttributes(output),
Comment on lines +231 to +239
val startTime = System.nanoTime()
val jniWrapper = ColumnarBatchSerializerJniWrapper.create(runtime)
val serializeHandle: Long = {
val allocator = ArrowBufferAllocators.globalInstance()
val cSchema = ArrowSchema.allocateNew(allocator)
val arrowSchema = SparkArrowUtil.toArrowSchema(
SparkShimLoader.getSparkShims.structFromAttributes(output),
SQLConf.get.sessionLocalTimeZone)
ArrowAbiUtil.exportSchema(allocator, arrowSchema, cSchema)
Comment on lines +975 to +980
case Some(cond) =>
val buildAttrs = joinContext.buildOutputSet
val cols: Array[String] = cond.references.toSeq.collect {
case a: Attribute if buildAttrs.contains(a) =>
ConverterUtils.genColumnNameWithExprId(a)
}.toArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants