File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -429,6 +429,22 @@ public actor DataFrame: Sendable {
429
429
values. append ( array. asAny ( i) as? Decimal )
430
430
case . primitiveInfo( . date32) :
431
431
values. append ( array. asAny ( i) as! Date )
432
+ case . timeInfo( . timestamp) :
433
+ let timestampType = column. data. type as! ArrowTypeTimestamp
434
+ assert ( timestampType. timezone == " Etc/UTC " )
435
+ let timestamp = array. asAny ( i) as! Int64
436
+ let timeInterval =
437
+ switch timestampType. unit {
438
+ case . seconds:
439
+ TimeInterval ( timestamp)
440
+ case . milliseconds:
441
+ TimeInterval ( timestamp) / 1_000
442
+ case . microseconds:
443
+ TimeInterval ( timestamp) / 1_000_000
444
+ case . nanoseconds:
445
+ TimeInterval ( timestamp) / 1_000_000_000
446
+ }
447
+ values. append ( Date ( timeIntervalSince1970: timeInterval) )
432
448
case ArrowType . ArrowBinary:
433
449
values. append ( ( array as! AsString ) . asString ( i) . utf8)
434
450
case . complexInfo( . strct) :
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ public struct Row: Sendable, Equatable {
71
71
return a == b
72
72
} else if let a = x as? Decimal , let b = y as? Decimal {
73
73
return a == b
74
+ } else if let a = x as? Date , let b = y as? Date {
75
+ return a == b
74
76
} else if let a = x as? String , let b = y as? String {
75
77
return a == b
76
78
} else {
Original file line number Diff line number Diff line change @@ -932,6 +932,19 @@ struct DataFrameTests {
932
932
#expect( try await df. collect ( ) == expected)
933
933
await spark. stop ( )
934
934
}
935
+
936
+ @Test
937
+ func timestamp( ) async throws {
938
+ let spark = try await SparkSession . builder. getOrCreate ( )
939
+ let df = try await spark. sql (
940
+ " SELECT TIMESTAMP '2025-05-01 16:23:40', TIMESTAMP '2025-05-01 16:23:40.123456' " )
941
+ let expected = [
942
+ Row (
943
+ Date ( timeIntervalSince1970: 1746116620.0 ) , Date ( timeIntervalSince1970: 1746116620.123456 ) )
944
+ ]
945
+ #expect( try await df. collect ( ) == expected)
946
+ await spark. stop ( )
947
+ }
935
948
#endif
936
949
937
950
@Test
You can’t perform that action at this time.
0 commit comments