Skip to content

[SPARK-54707] [SQL] Refactor PIVOT resolution main logic to the PivotTransformer#53474

Closed
mihailoale-db wants to merge 1 commit intoapache:masterfrom
mihailoale-db:pivotrefactor
Closed

[SPARK-54707] [SQL] Refactor PIVOT resolution main logic to the PivotTransformer#53474
mihailoale-db wants to merge 1 commit intoapache:masterfrom
mihailoale-db:pivotrefactor

Conversation

@mihailoale-db
Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

In this issue I propose to refactor PIVOT resolution main logic to the PivotTransformer in order to reuse it later to implement PIVOT in the single-pass resolver.

Why are the changes needed?

To ease the development of the single-pass resolver.

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.

@github-actions github-actions Bot added the SQL label Dec 15, 2025
@mihailoale-db
Copy link
Copy Markdown
Contributor Author

@vladimirg-db @cloud-fan PTAL.

@mihailoale-db mihailoale-db force-pushed the pivotrefactor branch 2 times, most recently from 113eded to b229446 Compare December 15, 2025 15:19
Comment thread sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala Outdated
Copy link
Copy Markdown
Contributor

@dtenedor dtenedor left a comment

Choose a reason for hiding this comment

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

Generally LGTM! Just one question about an unused parameter.

aggregates: Seq[Expression],
childOutput: Seq[Attribute],
newAlias: (Expression, Option[String]) => Alias,
fixedPointImplementation: Boolean): LogicalPlan = {
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 parameter doesn't appear to be used anywhere? Is this PR accidentally missing a piece of code that should be using it? If not, should we remove it, at least for now until we can think of a way to use it later and then we can put it back?

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.

It's something that's going to be used once we implement PIVOT in the single-pass resolver. I guess that we can remove it for now and add it later if possible

aggregates.zip(pivotAggregatesAttributes).map {
case (aggregate, pivotAtt) =>
newAlias(
ExtractValue(pivotAtt, Literal(i), conf.resolver),
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 used to be:

ExtractValue(pivotAtt, Literal(i), resolver)

The original code used a resolver from the Analyzer's scope, while the new code uses conf.resolver from SQLConfHelper. These are usually the same, but if the Analyzer ever overrides resolver, this could cause behavioral differences. This is worth verifying they're guaranteed equivalent. Is it intended?

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's no enforcement as I can see. For example we use conf.resolver in the Analyzer.scala besides the Analyzer.resolver whereas in the ColumnResolutionHelper we use only the conf.resolver. It looks like a matter of preference so I would keep it as it is to avoid adding another parameter to the already extensive PivotTransformers list

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.

Sounds good.

@dtenedor
Copy link
Copy Markdown
Contributor

This change seems like a pure refactor at this point. LGTM, merging to master.

@dtenedor dtenedor closed this in 04624f6 Dec 16, 2025
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