Skip to content

Conversation

@gengliangwang
Copy link
Member

@gengliangwang gengliangwang commented Nov 20, 2020

What changes were proposed in this pull request?

After #30260, there are some type conversions disallowed under ANSI mode.
We should tell users what they can do if they have to use the disallowed casting.

Why are the changes needed?

Make it more user-friendly.

Does this PR introduce any user-facing change?

Yes, the error message is improved on casting failure when ANSI mode is enabled

How was this patch tested?

Unit tests.

@github-actions github-actions bot added the SQL label Nov 20, 2020
@gengliangwang
Copy link
Member Author

Since there is no alternative function for converting timestamp to numeric, I will work on another one before continuing this one.

@SparkQA
Copy link

SparkQA commented Nov 20, 2020

Test build #131399 has finished for PR 30440 at commit 18cecbb.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 23, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/36161/

@SparkQA
Copy link

SparkQA commented Nov 23, 2020

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/36161/

@SparkQA
Copy link

SparkQA commented Nov 23, 2020

Test build #131559 has finished for PR 30440 at commit 1100cc6.

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

@SparkQA
Copy link

SparkQA commented Nov 24, 2020

Test build #131593 has finished for PR 30440 at commit 1100cc6.

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

@gengliangwang gengliangwang changed the title [WIP] [SPARK-33496][SQL]Improve error message of ANSI explicit cast [SPARK-33496][SQL]Improve error message of ANSI explicit cast Nov 24, 2020
// scalastyle:off line.size.limit
s"""
| cannot cast ${from.catalogString} to ${to.catalogString},
| you can enable the casting by setting ${SQLConf.LEGACY_ALLOW_CAST_NUMERIC_TO_TIMESTAMP.key}
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we remove LEGACY_ALLOW_CAST_NUMERIC_TO_TIMESTAMP? It's true by default and I don't see why it's needed since we have ansi mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1, we can have another PR for it

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 do it first? then we don't need to change this part again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I have just created #30493

Copy link
Member

@maropu maropu left a comment

Choose a reason for hiding this comment

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

Minor comments and the other parts look fine.

s"""
| cannot cast ${from.catalogString} to ${to.catalogString},
| you can enable the casting by setting ${SQLConf.LEGACY_ALLOW_CAST_NUMERIC_TO_TIMESTAMP.key}
| to true, but we strongly recommend using function TIMESTAMP_SECONDS/TIMESTAMP_MILLIS/TIMESTAMP_MICROS instead.
Copy link
Member

Choose a reason for hiding this comment

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

nit: function -> functions?

override def canCast(from: DataType, to: DataType): Boolean = AnsiCast.canCast(from, to)

// For now, this expression is only used in table insertion.
// If there are more scenarios for this expression, we should update the error message on type
Copy link
Member

Choose a reason for hiding this comment

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

nit: a unnecessary space found in expression, we

// scalastyle:off line.size.limit
s"""
| cannot cast ${from.catalogString} to ${from.catalogString}.
| We strongly recommend using function TIMESTAMP_SECONDS/TIMESTAMP_MILLIS/TIMESTAMP_MICROS instead.
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 describing it like To convert values from ${...} to ${...}, you can use functions TIMESTAMP_SECONDS/TIMESTAMP_MILLIS/TIMESTAMP_MICROS instead. ?

case (_: NumericType, TimestampType) =>
// scalastyle:off line.size.limit
s"""
| cannot cast ${from.catalogString} to ${from.catalogString}.
Copy link
Member

Choose a reason for hiding this comment

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

from.catalogString -> to.catalogString for the latter one.

@gengliangwang
Copy link
Member Author

@cloud-fan @maropu Thanks for the suggestions. I have addressed them.

@SparkQA
Copy link

SparkQA commented Nov 24, 2020

Test build #131652 has finished for PR 30440 at commit e762162.

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

@gengliangwang
Copy link
Member Author

retest this please.

@SparkQA
Copy link

SparkQA commented Nov 24, 2020

Test build #131664 has finished for PR 30440 at commit e762162.

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

@gengliangwang
Copy link
Member Author

retest this please.

@SparkQA
Copy link

SparkQA commented Nov 25, 2020

Test build #131721 has finished for PR 30440 at commit e762162.

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

@HyukjinKwon
Copy link
Member

retest this please.

@gengliangwang gengliangwang force-pushed the improveAnsiCastErrorMSG branch from e762162 to bb5b219 Compare November 25, 2020 09:16
@SparkQA
Copy link

SparkQA commented Nov 25, 2020

Test build #131756 has finished for PR 30440 at commit e762162.

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

@gengliangwang
Copy link
Member Author

retest this please.

case (_: ArrayType, StringType) =>
s"""
| cannot cast ${from.catalogString} to ${to.catalogString} with ANSI mode on.
| If you have to cast ${from.catalogString} to ${to.catalogString}, you can use the function array_join or set $fallbackConfKey as $fallbackConfValue.
Copy link
Contributor

@cloud-fan cloud-fan Nov 25, 2020

Choose a reason for hiding this comment

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

upper case the function name?

@SparkQA
Copy link

SparkQA commented Nov 25, 2020

Test build #131764 has finished for PR 30440 at commit bb5b219.

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

@gengliangwang
Copy link
Member Author

@maropu @cloud-fan Thanks for the review!
Merging to master

@SparkQA
Copy link

SparkQA commented Nov 25, 2020

Test build #131772 has finished for PR 30440 at commit bb5b219.

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

@AmplabJenkins
Copy link

Build finished.

@AmplabJenkins
Copy link

Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/36375/

@SparkQA
Copy link

SparkQA commented Nov 25, 2020

Test build #131777 has finished for PR 30440 at commit acfa5d0.

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

@AmplabJenkins
Copy link

Build finished.

@AmplabJenkins
Copy link

Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/131777/

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.

6 participants