-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-31710][SQL] Fail casting numeric to timestamp by default #28593
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
Changes from all commits
bb1efa2
1459d5b
88c40fe
8d1deee
df22083
a02c6c7
e61c484
d99cc30
0436611
0a1a6a5
ed80c84
bae99b1
39da7be
39ca87c
0189b91
2c29c5b
fd3efa2
69198c6
c3b3c89
38f6e64
43f9b4e
852d730
2e55be3
7637256
87cada7
13ae816
4abd8d3
b13316f
50cc0cf
22638e4
b1dda01
38f0e76
e478c90
7348917
e50e5cb
2344e1f
c3546eb
c7cf8b9
5f138af
77a339a
3a3b93e
a6b4f74
1b52fd6
293fa9f
9cf87e8
cb21d5d
726371c
8ed4fc4
96c197c
3d1819d
be88f01
fd7815a
e14c4f9
7cb0a54
7ad82da
00ed960
664277e
6d9eecb
b8b2919
eeb0a61
409c821
ec2cf54
3fd6d02
fd677c9
108dfea
47f210c
860500d
4c7ddb4
b43a140
1d5c750
7b26d0c
c7f2a9b
8a5e9be
93b1f63
a6a9bd4
a5b5474
4fecf9b
f995f46
c8d5aa5
b4f4d53
f4556a4
f4da70b
7132fca
7ffcde2
f84caa1
6d56a83
5716f40
64acff3
d26bd34
9545c9f
01f42e6
e29409d
183d418
1764c76
74eb6ca
5f06714
8fe1960
ffa3079
bc4b62c
08aee30
12b4239
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1427,6 +1427,19 @@ def to_utc_timestamp(timestamp, tz): | |
return Column(sc._jvm.functions.to_utc_timestamp(_to_java_column(timestamp), tz)) | ||
|
||
|
||
@since(3.1) | ||
def timestamp_seconds(col): | ||
""" | ||
>>> from pyspark.sql.functions import timestamp_seconds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you set the session timezone? It caused SPARK-32088 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks HyukjinKwon, will fix soon |
||
>>> time_df = spark.createDataFrame([(1230219000,)], ['unix_time']) | ||
>>> time_df.select(timestamp_seconds(time_df.unix_time).alias('ts')).collect() | ||
[Row(ts=datetime.datetime(2008, 12, 25, 7, 30))] | ||
""" | ||
|
||
sc = SparkContext._active_spark_context | ||
return Column(sc._jvm.functions.timestamp_seconds(_to_java_column(col))) | ||
|
||
|
||
@since(2.0) | ||
@ignore_unicode_prefix | ||
def window(timeColumn, windowDuration, slideDuration=None, startTime=None): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,8 @@ object Cast { | |
case (StringType, TimestampType) => true | ||
case (BooleanType, TimestampType) => true | ||
case (DateType, TimestampType) => true | ||
case (_: NumericType, TimestampType) => true | ||
case (_: NumericType, TimestampType) => | ||
GuoPhilipse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SQLConf.get.getConf(SQLConf.LEGACY_ALLOW_CAST_NUMERIC_TO_TIMESTAMP) | ||
|
||
case (StringType, DateType) => true | ||
case (TimestampType, DateType) => true | ||
|
@@ -266,7 +267,15 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit | |
TypeCheckResult.TypeCheckSuccess | ||
} else { | ||
TypeCheckResult.TypeCheckFailure( | ||
s"cannot cast ${child.dataType.catalogString} to ${dataType.catalogString}") | ||
if (child.dataType.isInstanceOf[NumericType] && dataType.isInstanceOf[TimestampType]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, we need the check here? I think its okay just to update our migration guide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's better to let users know why it's wrong and how to fix, in the error message. |
||
s"cannot cast ${child.dataType.catalogString} to ${dataType.catalogString}," + | ||
"you can enable the casting by setting " + | ||
s"${SQLConf.LEGACY_ALLOW_CAST_NUMERIC_TO_TIMESTAMP.key} to true," + | ||
"but we strongly recommend using function " + | ||
"TIMESTAMP_SECONDS/TIMESTAMP_MILLIS/TIMESTAMP_MICROS instead." | ||
} else { | ||
s"cannot cast ${child.dataType.catalogString} to ${dataType.catalogString}" | ||
}) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3358,6 +3358,15 @@ object functions { | |
window(timeColumn, windowDuration, windowDuration, "0 second") | ||
} | ||
|
||
/** | ||
* Creates timestamp from the number of seconds since UTC epoch. | ||
* @group = datetime_funcs | ||
* @since = 3.1.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
|
||
*/ | ||
def timestamp_seconds(e: Column): Column = withExpr { | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SecondsToTimestamp(e.expr) | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////////////////////////// | ||
// Collection functions | ||
////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
Uh oh!
There was an error while loading. Please reload this page.