Skip to content

Conversation

@gengliangwang
Copy link
Member

What changes were proposed in this pull request?

In the current implementation. complex types like Array/Map/StructType are allowed to upcast as StringType.
This is not safe casting. We should disallow it.

How was this patch tested?

Update the existing test case

@gengliangwang
Copy link
Member Author

@cloud-fan

@cloud-fan
Copy link
Contributor

good catch! can we also add an end-to-end test in EncoderResolutionSuite?

@SparkQA
Copy link

SparkQA commented Jul 24, 2019

Test build #108086 has finished for PR 25242 at commit 826570f.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jul 24, 2019

Test build #108108 has finished for PR 25242 at commit f4fa932.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

test("SPARK-28497: complex type is not compatible with string encoder schema") {
val encoder = ExpressionEncoder[String]

{
Copy link
Contributor

Choose a reason for hiding this comment

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

Each block might be easily extracted with inner function to remove duplications. attr (element in attrs), and string representation of attr type are different and remaining is exactly same.

{
val attrs = Seq('a.struct('x.long))
assert(intercept[AnalysisException](encoder.resolveAndBind(attrs)).message ==
s"""
Copy link
Member

Choose a reason for hiding this comment

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

super nit: its ok just check .contains("Cannot up cast a from struct<x:bigint> to string")?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Member Author

Choose a reason for hiding this comment

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

I am OK with either way. I was following the other test cases in the suite. Let me change it to .contains...

val attrs = Seq('a.array(StringType))
assert(intercept[AnalysisException](encoder.resolveAndBind(attrs)).message ==
s"""
|Cannot up cast `a` from array<string> to string.
Copy link
Member

@HyukjinKwon HyukjinKwon Jul 25, 2019

Choose a reason for hiding this comment

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

It doesn't necessarily compare the whole message. We can check if the message contains some keywords.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, it was the same comment as #25242 (comment)

Copy link
Member

@HyukjinKwon HyukjinKwon left a comment

Choose a reason for hiding this comment

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

Looks fine to me too otherwise.

@SparkQA
Copy link

SparkQA commented Jul 25, 2019

Test build #108156 has finished for PR 25242 at commit 6c590a0.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon
Copy link
Member

Merged to master.

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.

7 participants