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-49349][SQL] Improve error message for LCA with Generate #48915

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wangyum
Copy link
Member

@wangyum wangyum commented Nov 21, 2024

What changes were proposed in this pull request?

This PR add a new check in CheckAnalysis to improve error message for LCA with Generate.

Why are the changes needed?

Improve error message.

Before this PR:

[INTERNAL_ERROR] Invalid call to dataType on unresolved object SQLSTATE: XX000
org.apache.spark.sql.catalyst.analysis.UnresolvedException: [INTERNAL_ERROR] Invalid call to dataType on unresolved object SQLSTATE: XX000
	at org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute.dataType(unresolved.scala:292)
	at org.apache.spark.sql.catalyst.expressions.LateralColumnAliasReference.dataType(namedExpressions.scala:472)

After this PR:

[UNSUPPORTED_FEATURE.LATERAL_COLUMN_ALIAS_IN_GENERATOR] The feature is not supported: Referencing a lateral column alias `new_name` in generator expression "unresolvedalias(lateralAliasReference(new_name) LIKE a%)". SQLSTATE: 0A000;
'Project [explode(split(name#21, ,, -1)) AS new_name#19, unresolvedalias(lateralAliasReference(new_name) LIKE a%)]
+- SubqueryAlias spark_catalog.default.employee
   +- Relation spark_catalog.default.employee[dept#20,name#21,salary#22,bonus#23,properties#24] orc

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Unit test.

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

No.

@github-actions github-actions bot added the SQL label Nov 21, 2024
@wangyum
Copy link
Member Author

wangyum commented Nov 21, 2024

cc @cloud-fan

Comment on lines +345 to +351
operator.expressions.exists {
case a: Alias
if e.collect { case l: LateralColumnAliasReference => l.nameParts.head }
.contains(a.name) =>
a.exists(_.isInstanceOf[Generator])
case _ => false
} =>
Copy link
Member

Choose a reason for hiding this comment

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

How about to put the condition check to a separate function, see isMapWithStringKey above for instance. This could improve readability, probably.

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.

2 participants