Skip to content

Conversation

mihailotim-db
Copy link
Contributor

What changes were proposed in this pull request?

Improve error message when input of GetStructField is not StructType

Why are the changes needed?

Previously we threw a class cast exception.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added a test case.

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

No

@github-actions github-actions bot added the SQL label Aug 27, 2025
@@ -148,7 +148,10 @@ trait ExtractValue extends Expression with QueryErrorsBase {
case class GetStructField(child: Expression, ordinal: Int, name: Option[String] = None)
extends UnaryExpression with ExtractValue {

lazy val childSchema = child.dataType.asInstanceOf[StructType]
Copy link
Contributor

Choose a reason for hiding this comment

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

The assumption is that the child must be StructType so that we will construct GetStructField.

@@ -148,7 +148,10 @@ trait ExtractValue extends Expression with QueryErrorsBase {
case class GetStructField(child: Expression, ordinal: Int, name: Option[String] = None)
extends UnaryExpression with ExtractValue {

lazy val childSchema = child.dataType.asInstanceOf[StructType]
lazy val childSchema = child.dataType match {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure that this is a error message improvement and not an actual bug in the analyzer? It might be that somehow we don't apply type coercion correctly or similar, right?

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