Skip to content

Commit a1936af

Browse files
committed
add TimestampType int handling in EvaluatePython, remove casting to long in Python
1 parent 5b1dd67 commit a1936af

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

python/pyspark/sql/tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,10 @@ def test_time_with_timezone(self):
14381438
# regression test for SPARK-19561
14391439
def test_datetime_at_epoch(self):
14401440
epoch = datetime.datetime.fromtimestamp(0)
1441-
df = self.spark.createDataFrame([Row(date=epoch)])
1442-
self.assertEqual(df.first()['date'], epoch)
1441+
df = self.spark.createDataFrame([Row(date=epoch)]).select('date', lit(epoch).alias('lit_date'))
1442+
first = df.first()
1443+
self.assertEqual(first['date'], epoch)
1444+
self.assertEqual(first['lit_date'], epoch)
14431445

14441446
def test_decimal(self):
14451447
from decimal import Decimal

python/pyspark/sql/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def toInternal(self, dt):
189189
if dt is not None:
190190
seconds = (calendar.timegm(dt.utctimetuple()) if dt.tzinfo
191191
else time.mktime(dt.timetuple()))
192-
return long(seconds) * 1000000 + dt.microsecond
192+
return int(seconds) * 1000000 + dt.microsecond
193193

194194
def fromInternal(self, ts):
195195
if ts is not None:

sql/core/src/main/scala/org/apache/spark/sql/execution/python/EvaluatePython.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ object EvaluatePython {
112112
case (c: Int, DateType) => c
113113

114114
case (c: Long, TimestampType) => c
115+
case (c: Int, TimestampType) => c.toLong
115116

116117
case (c, StringType) => UTF8String.fromString(c.toString)
117118

0 commit comments

Comments
 (0)