abandy commented on code in PR #35985:
URL: https://github.com/apache/arrow/pull/35985#discussion_r1225504775
##########
swift/Arrow/Tests/ArrowTests/ArrayTests.swift:
##########
@@ -125,6 +125,62 @@ final class ArrayTests: XCTestCase {
XCTAssertEqual(date64Array.length, 3)
XCTAssertEqual(date64Array[1], date2)
XCTAssertEqual(date64Array[0]!, date1)
+ }
+
+ func testBinaryArray() throws {
+ let binaryBuilder = try ArrowArrayBuilders.loadBinaryArrayBuilder();
+ for i in 0..<100 {
+ if i % 10 == 9 {
+ binaryBuilder.append(nil)
+ } else {
+ binaryBuilder.append(("test" + String(i)).data(using:.utf8))
+ }
+ }
+ XCTAssertEqual(binaryBuilder.nullCount, 10)
+ XCTAssertEqual(binaryBuilder.length, 100)
+ XCTAssertEqual(binaryBuilder.capacity, 648)
+ let binaryArray = try binaryBuilder.finish()
+ XCTAssertEqual(binaryArray.length, 100)
+ for i in 0..<binaryArray.length {
+ if i % 10 == 9 {
+ XCTAssertEqual(try binaryArray.isNull(i), true)
+ } else {
+ let stringData = String(bytes: binaryArray[i]!, encoding:
.utf8)
+ XCTAssertEqual(stringData, "test" + String(i))
+ }
+ }
+ }
+
+ func testTime32Array() throws {
+ let time32Builder = try
ArrowArrayBuilders.loadTime32ArrayBuilder(.Milliseconds);
Review Comment:
Will do.
##########
swift/Arrow/Sources/Arrow/ArrowWriterHelper.swift:
##########
@@ -34,16 +35,21 @@ func toFBTypeEnum(_ infoType: ArrowType.Info) ->
Result<org_apache_arrow_flatbuf
return .success(org_apache_arrow_flatbuf_Type_.floatingpoint)
} else if infoType == ArrowType.ArrowString {
return .success(org_apache_arrow_flatbuf_Type_.utf8)
+ } else if infoType == ArrowType.ArrowBinary {
+ return .success(org_apache_arrow_flatbuf_Type_.binary)
} else if infoType == ArrowType.ArrowBool {
return .success(org_apache_arrow_flatbuf_Type_.bool)
} else if infoType == ArrowType.ArrowDate32 || infoType ==
ArrowType.ArrowDate64 {
return .success(org_apache_arrow_flatbuf_Type_.date)
+ } else if infoType == ArrowType.ArrowTime32 || infoType ==
ArrowType.ArrowTime64 {
+ return .success(org_apache_arrow_flatbuf_Type_.time)
}
-
- return .failure(.unknownType)
+
Review Comment:
Will remove.
##########
swift/Arrow/Sources/Arrow/ArrowType.swift:
##########
@@ -116,17 +154,21 @@ public class ArrowType {
return ArrowType.ArrowUnknown
}
}
+
+
Review Comment:
Will remove.
##########
swift/Arrow/Sources/Arrow/ArrowArray.swift:
##########
@@ -182,3 +182,52 @@ public class Date64Array: ArrowArray<Date> {
}
}
}
+
+public class Time32Array: FixedArray<Time32> {}
+public class Time64Array: FixedArray<Time64> {}
+
+public class BinaryArray: ArrowArray<Data> {
+ public struct Options {
+ public var printAsHex = false
+ public var printEncoding: String.Encoding = .utf8;
+ }
+
+ public var options = Options()
+
+ public override subscript(_ index: UInt) -> Data? {
+ get{
+ let offsetIndex = MemoryLayout<Int32>.stride * Int(index)
+ if self.arrowData.isNull(index) {
+ return nil
+ }
+
+ let offsets = self.arrowData.buffers[1]
+ let values = self.arrowData.buffers[2]
+
+ var startIndex: Int32 = 0
+ if index > 0 {
+ startIndex = offsets.rawPointer.advanced(by:
offsetIndex).load(as: Int32.self)
+ }
+
+ let endIndex = offsets.rawPointer.advanced(by: offsetIndex +
MemoryLayout<Int32>.stride ).load(as: Int32.self)
+ let arrayLength = Int(endIndex - startIndex);
+ let rawPointer = values.rawPointer.advanced(by:
Int(startIndex)).bindMemory(to: UInt8.self, capacity: arrayLength)
+ let buffer = UnsafeBufferPointer<UInt8>(start: rawPointer, count:
arrayLength);
+ let byteArray = Array(buffer)
+ return Data(byteArray)
+ }
+ }
+
+ public override func asString(_ index: UInt) -> String {
+ if self[index] == nil {
+ return ""
+ }
+
+ let data = self[index]!
+ if(options.printAsHex) {
Review Comment:
Will update.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]