Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-50130][SQL][FOLLOWUP] Make Encoder generation lazy #48829

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ueshin
Copy link
Member

@ueshin ueshin commented Nov 12, 2024

What changes were proposed in this pull request?

Makes Encoder generation lazy.

Why are the changes needed?

The encoder with empty schema for lazy plan could cause unexpected behavior.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Existing tests.

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

No.

@zhengruifeng
Copy link
Contributor

shall we add a test for it?

@@ -95,13 +95,12 @@ private[sql] object Dataset {
def ofRows(sparkSession: SparkSession, logicalPlan: LogicalPlan): DataFrame =
sparkSession.withActive {
val qe = sparkSession.sessionState.executePlan(logicalPlan)
val encoder = if (qe.isLazyAnalysis) {
RowEncoder.encoderFor(new StructType())
if (qe.isLazyAnalysis) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we clean up the code a bit more?

if (!qe.isLazyAnalysis) qe.assertAnalyzed()
new Dataset[Row](qe, () => RowEncoder.encoderFor(qe.analyzed.schema))

Copy link
Member Author

Choose a reason for hiding this comment

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

Now with this PR, the encoder creation is lazy only when qe.isLazyAnalysis, to be consistent with the current behavior. Also the previously failed test suggested to make it consistent.

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.

5 participants