Skip to content

Commit 31dcb7c

Browse files
Merge pull request #12 from willtemperley/main
ArrowArrayBuilder protocol work. Re-organise IPC related in anticipation of factoring into separate module.
2 parents 4cfb9f7 + ee6e143 commit 31dcb7c

13 files changed

+420
-358
lines changed

Sources/Arrow/ArrowArray.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ public protocol AnyArrowArray {
2424
var bufferData: [Data] { get }
2525
var bufferDataSizes: [Int] { get }
2626
func asAny(_ index: UInt) -> Any?
27+
func asString(_ index: UInt) -> String
2728
}
2829

2930
// MARK: - Core Protocol
3031

3132
/// The interface for Arrow array types.
32-
public protocol ArrowArray<ItemType>: AsString, AnyArrowArray {
33+
public protocol ArrowArray<ItemType>: AnyArrowArray {
3334
associatedtype ItemType
3435
var arrowData: ArrowData { get }
3536
init(_ arrowData: ArrowData) throws(ArrowError)
@@ -38,7 +39,6 @@ public protocol ArrowArray<ItemType>: AsString, AnyArrowArray {
3839

3940
// MARK: - Default Implementations
4041
extension ArrowArray {
41-
4242
public var nullCount: UInt {
4343
arrowData.nullCount
4444
}
@@ -188,8 +188,7 @@ public struct Date32Array: ArrowArray {
188188
let byteOffset = self.arrowData.stride * Int(index)
189189
let milliseconds = self.arrowData.buffers[1].rawPointer.advanced(
190190
by: byteOffset
191-
).load(
192-
as: UInt32.self)
191+
).load(as: UInt32.self)
193192
return Date(timeIntervalSince1970: TimeInterval(milliseconds * 86400))
194193
}
195194
}
@@ -209,8 +208,7 @@ public struct Date64Array: ArrowArray {
209208
let byteOffset = self.arrowData.stride * Int(index)
210209
let milliseconds = self.arrowData.buffers[1].rawPointer.advanced(
211210
by: byteOffset
212-
).load(
213-
as: UInt64.self)
211+
).load(as: UInt64.self)
214212
return Date(timeIntervalSince1970: TimeInterval(milliseconds / 1000))
215213
}
216214
}
@@ -451,7 +449,7 @@ public struct NestedArray: ArrowArray, AnyArrowArray {
451449
switch item {
452450
case nil:
453451
output.append("null")
454-
case let asStringItem as AsString:
452+
case let asStringItem as AnyArrowArray:
455453
output.append(asStringItem.asString(0))
456454
case let someItem?:
457455
output.append("\(someItem)")
@@ -466,7 +464,7 @@ public struct NestedArray: ArrowArray, AnyArrowArray {
466464
var output = "{"
467465
if let children = self.children {
468466
let parts = children.compactMap { child in
469-
(child as? AsString)?.asString(index)
467+
child.asString(index)
470468
}
471469
output.append(parts.joined(separator: ","))
472470
}

0 commit comments

Comments
 (0)