Skip to content

[GLUTEN-8115][CORE] Refine the BuildSideRelation transform to support all scenarios#8116

Merged
philo-he merged 5 commits intoapache:mainfrom
yikf:trans-mode
Dec 9, 2024
Merged

[GLUTEN-8115][CORE] Refine the BuildSideRelation transform to support all scenarios#8116
philo-he merged 5 commits intoapache:mainfrom
yikf:trans-mode

Conversation

@yikf
Copy link
Copy Markdown
Contributor

@yikf yikf commented Dec 1, 2024

What changes were proposed in this pull request?

Fix #8115.

If exchange reuse, the buildKeys of ColumnarSubqueryBroadcastExec and the buildKeys of BroadcastExchangeExec may not be the same, making it difficult to construct the projection of the transform. therefore, the BuildSideRelation should retain the BroadcastMode of BroadcastExchangeExec to simplify the projection of the transform.

How was this patch tested?

exists unit tests, manual tests

@github-actions github-actions bot added CORE works for Gluten Core VELOX CLICKHOUSE labels Dec 1, 2024
@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 1, 2024

#8115

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 1, 2024

Run Gluten Clickhouse CI on x86

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2024

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2024

Run Gluten Clickhouse CI on x86

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2024

Run Gluten Clickhouse CI on x86

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2024

Run Gluten Clickhouse CI on x86

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2024

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2024

Run Gluten Clickhouse CI on x86

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2024

Run Gluten Clickhouse CI on x86

1 similar comment
@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2024

Run Gluten Clickhouse CI on x86

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2024

Run Gluten Clickhouse CI on x86

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 2, 2024

Run Gluten Clickhouse CI on x86

@yikf
Copy link
Copy Markdown
Contributor Author

yikf commented Dec 3, 2024

@philo-he @zhztheplayer @jackylee-ch @zzcclp Could you please take a look if you find a time, thanks

@yikf yikf changed the title [GLUTEN-8115][VL] Refine the BuildSideRelation transform to supports all scenarios [GLUTEN-8115][VL][CH] Refine the BuildSideRelation transform to supports all scenarios Dec 3, 2024
@FelixYBW FelixYBW changed the title [GLUTEN-8115][VL][CH] Refine the BuildSideRelation transform to supports all scenarios [GLUTEN-8115][CORE] Refine the BuildSideRelation transform to supports all scenarios Dec 3, 2024
@FelixYBW
Copy link
Copy Markdown
Contributor

FelixYBW commented Dec 3, 2024

Do you have a specific query example?

@philo-he philo-he changed the title [GLUTEN-8115][CORE] Refine the BuildSideRelation transform to supports all scenarios [GLUTEN-8115][CORE] Refine the BuildSideRelation transform to support all scenarios Dec 3, 2024
@yikf
Copy link
Copy Markdown
Contributor Author

yikf commented Dec 3, 2024

Do you have a specific query example?

TPC-DS Q5 is a reuse-exchange example, see: #7807

After reuse, ColumnarSubqueryBroadcastExec's buildKeys and exchange's buildKeys may not be the same reference, and in our internal case, even the names referenced by alias are different because of alias.

In Spark, the transform of relation is always carried out in BroadcastExchangeExec, so this problem does not exist. we can save the buildKeys of BroadcastExchangeExec. this way, in the subsequent transform, we can do the relation transform like spark would have done in BroadcastExchangeExec, in which case the references are always the same, and then we can take the desired index value from the buildKeys output.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 4, 2024

Run Gluten Clickhouse CI on x86

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 5, 2024

Run Gluten Clickhouse CI on x86

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 5, 2024

Run Gluten Clickhouse CI on x86

@yikf
Copy link
Copy Markdown
Contributor Author

yikf commented Dec 6, 2024

@FelixYBW @zhouyuan @philo-he Hi, Could you help please take a look, thanks.


// Copy from org.apache.spark.sql.execution.joins.HashJoin#canRewriteAsLongType
// we should keep consistent with it to identify the LongHashRelation.
private def canRewriteAsLongType(keys: Seq[Expression]): Boolean = {
Copy link
Copy Markdown
Member

@philo-he philo-he Dec 9, 2024

Choose a reason for hiding this comment

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

@yikf, if spark changes this logic on its side, e.g., for adding support for other types, unexpected failure can happen in Gluten? Seems there is no other way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There doesn't seem to be any other way at the moment.

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.

@yikf, ok, let's merge this pr firstly. Thanks for your efforts!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks @philo-he

Copy link
Copy Markdown
Member

@philo-he philo-he left a comment

Choose a reason for hiding this comment

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

Verified with internal TPC-DS 3TB test.

@philo-he philo-he merged commit 15f4cde into apache:main Dec 9, 2024
@yikf yikf deleted the trans-mode branch December 9, 2024 06:36
yikf added a commit to yikf/incubator-gluten that referenced this pull request Dec 9, 2024
felixloesing added a commit to felixloesing/gluten that referenced this pull request Aug 26, 2025
This pull request introduces a safer and more robust approach for
handling Spark's `BroadcastMode` during serialization. The main
improvement is the introduction of a new `SafeBroadcastMode` abstraction
and related utilities, which help avoid serialization issues that caused
a Stackoverflow exception during broadcast exchanges.
BroadcastMode was introduced in the
[PR](apache#8116) that caused
the issues observed. HashedRelationBroadcastMode embeds Catalyst
expression trees, which are not safe to Kryo-serialize when running with
`spark.kryo.referenceTracking=false` (default internally).

With this change, the broadcast payload now contains only primitives and
byte arrays (no Catalyst trees). For bound keys, we serialize just
column ordinals (+ null-aware flag) and for computed keys (e.g.,
upper(col)), we serialize the key expressions once as Java bytes and
deserialize only where needed to build projections.

Ran internal test set (50 queries) and ran other query specifically
checking if
`spark.gluten.velox.offHeapBroadcastBuildRelation.enabled=true;` works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLICKHOUSE CORE works for Gluten Core VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VL] BuildSideRelation supports transforms for all scenarios

3 participants