Uh oh!
There was an error while loading. Please reload this page.
[SPARK-21739][SQL]Cast expression should initialize timezoneId when it is called statically to convert something into TimestampType - #18960
[SPARK-21739][SQL]Cast expression should initialize timezoneId when it is called statically to convert something into TimestampType#18960DonnyZone wants to merge 7 commits into
Conversation
DonnyZone
commented
Aug 16, 2017
gatorsmile
commented
Aug 16, 2017
ok to test |
gatorsmile
commented
Aug 16, 2017
Also cc @ueshin |
| private def castFromString(value: String, dataType: DataType) = { | ||
| Cast(Literal(value), dataType).eval(null) | ||
| Cast(Literal(value), dataType, Option(SQLConf.get.sessionLocalTimeZone)).eval(null) |
There was a problem hiding this comment.
BTW, is it elegant to initialize a CastSupport (DataSourceAnalysis rule or DataSourceStrategy) here, in which we still need to pass SQLConf?
There was a problem hiding this comment.
Here, we can obtain SQLConf directly with sparkSession.sessionState.conf
| val partOrdinal = partitionKeys.indexOf(attr) | ||
| row(ordinal) = Cast(Literal(rawPartValues(partOrdinal)), attr.dataType).eval(null) | ||
| row(ordinal) = Cast(Literal(rawPartValues(partOrdinal)), attr.dataType, | ||
| Option(SQLConf.get.sessionLocalTimeZone)).eval(null) |
There was a problem hiding this comment.
We also need a test case for verifying this.
There was a problem hiding this comment.
Do you mean a test case for HadoopTableReader? a little confusing
SparkQA
commented
Aug 16, 2017
Test build #80748 has finished for PR 18960 at commit
|
gatorsmile
commented
Aug 16, 2017
retest this please |
SparkQA
commented
Aug 17, 2017
Test build #80754 has finished for PR 18960 at commit
|
SparkQA
commented
Aug 17, 2017
Test build #80760 has finished for PR 18960 at commit
|
| } | ||
| } | ||
| test("SPARK-21739: Cast expression should initialize timezoneId " + |
There was a problem hiding this comment.
This test can pass without the change in TableReader.scala. We need another test case.
There was a problem hiding this comment.
Oh, it should select the TimestampType column. Thanks for reminder, I will fix it.
| checkAnswer(sql("select value from table_with_timestamp_partition " + | ||
| "where ts = '2010-01-02 00:00:00.000'"), Row(2)) | ||
| sql("DROP TABLE IF EXISTS table_with_timestamp_partition") |
There was a problem hiding this comment.
use WithTable. You can check how we do it in the other test cases
DonnyZone
commented
Aug 17, 2017
Test case updated. |
DonnyZone
commented
Aug 17, 2017
Moreover, how about using |
SparkQA
commented
Aug 17, 2017
Test build #80779 has finished for PR 18960 at commit
|
SparkQA
commented
Aug 17, 2017
Test build #80786 has finished for PR 18960 at commit
|
Could you check the changes I made below? 081d57a Thanks! |
SparkQA
commented
Aug 18, 2017
Test build #80818 has finished for PR 18960 at commit
|
gatorsmile
commented
Aug 18, 2017
LGTM |
gatorsmile
commented
Aug 18, 2017
Thanks! Merging to master/2.2 |
…it is called statically to convert something into TimestampType ## What changes were proposed in this pull request? https://issues.apache.org/jira/projects/SPARK/issues/SPARK-21739 This issue is caused by introducing TimeZoneAwareExpression. When the **Cast** expression converts something into TimestampType, it should be resolved with setting `timezoneId`. In general, it is resolved in LogicalPlan phase. However, there are still some places that use Cast expression statically to convert datatypes without setting `timezoneId`. In such cases, `NoSuchElementException: None.get` will be thrown for TimestampType. This PR is proposed to fix the issue. We have checked the whole project and found two such usages(i.e., in`TableReader` and `HiveTableScanExec`). ## How was this patch tested? unit test Author: donnyzone <wellfengzhu@gmail.com> Closes#18960 from DonnyZone/spark-21739. (cherry picked from commit 310454b) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
…it is called statically to convert something into TimestampType ## What changes were proposed in this pull request? https://issues.apache.org/jira/projects/SPARK/issues/SPARK-21739 This issue is caused by introducing TimeZoneAwareExpression. When the **Cast** expression converts something into TimestampType, it should be resolved with setting `timezoneId`. In general, it is resolved in LogicalPlan phase. However, there are still some places that use Cast expression statically to convert datatypes without setting `timezoneId`. In such cases, `NoSuchElementException: None.get` will be thrown for TimestampType. This PR is proposed to fix the issue. We have checked the whole project and found two such usages(i.e., in`TableReader` and `HiveTableScanExec`). ## How was this patch tested? unit test Author: donnyzone <wellfengzhu@gmail.com> Closesapache#18960 from DonnyZone/spark-21739. (cherry picked from commit 310454b) Signed-off-by: gatorsmile <gatorsmile@gmail.com>
What changes were proposed in this pull request?
https://issues.apache.org/jira/projects/SPARK/issues/SPARK-21739
This issue is caused by introducing TimeZoneAwareExpression.
When the Cast expression converts something into TimestampType, it should be resolved with setting
timezoneId. In general, it is resolved in LogicalPlan phase.However, there are still some places that use Cast expression statically to convert datatypes without setting
timezoneId. In such cases,NoSuchElementException: None.getwill be thrown for TimestampType.This PR is proposed to fix the issue. We have checked the whole project and found two such usages(i.e., in
TableReaderandHiveTableScanExec).How was this patch tested?
unit test