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 {
429429 values. append ( array. asAny ( i) as? Decimal )
430430 case . primitiveInfo( . date32) :
431431 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) )
432448 case ArrowType . ArrowBinary:
433449 values. append ( ( array as! AsString ) . asString ( i) . utf8)
434450 case . complexInfo( . strct) :
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ public struct Row: Sendable, Equatable {
7171 return a == b
7272 } else if let a = x as? Decimal , let b = y as? Decimal {
7373 return a == b
74+ } else if let a = x as? Date , let b = y as? Date {
75+ return a == b
7476 } else if let a = x as? String , let b = y as? String {
7577 return a == b
7678 } else {
Original file line number Diff line number Diff line change @@ -932,6 +932,19 @@ struct DataFrameTests {
932932 #expect( try await df. collect ( ) == expected)
933933 await spark. stop ( )
934934 }
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+ }
935948 #endif
936949
937950 @Test
You can’t perform that action at this time.
0 commit comments