Skip to content

Commit

Permalink
apacheGH-36544: [Swift] Add/change some init methods to public access
Browse files Browse the repository at this point in the history
  • Loading branch information
abandy committed Jul 7, 2023
1 parent dd36705 commit 9da86dc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
9 changes: 9 additions & 0 deletions swift/Arrow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/
.netrc
Package.resolved
18 changes: 9 additions & 9 deletions swift/Arrow/Sources/Arrow/ArrowArrayBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ import Foundation
public class ArrowArrayBuilder<T: ArrowBufferBuilder, U: ArrowArray<T.ItemType>> {
let type: ArrowType
let bufferBuilder: T
var length: UInt {get{return self.bufferBuilder.length}}
var capacity: UInt {get{return self.bufferBuilder.capacity}}
var nullCount : UInt {get{return self.bufferBuilder.nullCount}}
var offset: UInt {get{return self.bufferBuilder.offset}}
public var length: UInt {get{return self.bufferBuilder.length}}
public var capacity: UInt {get{return self.bufferBuilder.capacity}}
public var nullCount : UInt {get{return self.bufferBuilder.nullCount}}
public var offset: UInt {get{return self.bufferBuilder.offset}}

fileprivate init(_ type: ArrowType) throws {
self.type = type;
self.bufferBuilder = try T()
}

func append(_ val: T.ItemType?) {
public func append(_ val: T.ItemType?) {
self.bufferBuilder.append(val)
}

func finish() throws -> ArrowArray<T.ItemType> {
public func finish() throws -> ArrowArray<T.ItemType> {
let buffers = self.bufferBuilder.finish();
let arrowData = try ArrowData(self.type, buffers: buffers, nullCount: self.nullCount, stride: self.getStride())
return U(arrowData)
}

func getStride() -> Int {
public func getStride() -> Int {
MemoryLayout<T.ItemType>.stride
}
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public class Date32ArrayBuilder : ArrowArrayBuilder<Date32BufferBuilder, Date32A
try self.init(ArrowType(ArrowType.ArrowDate32))
}

override func getStride() -> Int {
public override func getStride() -> Int {
MemoryLayout<Int32>.stride
}
}
Expand All @@ -84,7 +84,7 @@ public class Date64ArrayBuilder : ArrowArrayBuilder<Date64BufferBuilder, Date64A
try self.init(ArrowType(ArrowType.ArrowDate64))
}

override func getStride() -> Int {
public override func getStride() -> Int {
MemoryLayout<Int64>.stride
}
}
Expand Down
2 changes: 2 additions & 0 deletions swift/Arrow/Sources/Arrow/ArrowReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class ArrowReader {
public var batches = [RecordBatch]()
}

public init() {}

private func loadSchema(_ schema: org_apache_arrow_flatbuf_Schema) -> Result<ArrowSchema, ArrowError> {
let builder = ArrowSchema.Builder()
for index in 0 ..< schema.fieldsCount {
Expand Down
2 changes: 2 additions & 0 deletions swift/Arrow/Sources/Arrow/ArrowSchema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class ArrowSchema {
public class Builder {
private var fields: [ArrowField] = []

public init() {}

@discardableResult
public func addField(_ field: ArrowField) -> Builder {
fields.append(field)
Expand Down
12 changes: 8 additions & 4 deletions swift/Arrow/Sources/Arrow/ArrowTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public class ArrowTable {
let schemaBuilder = ArrowSchema.Builder()
var columns = [ArrowColumn]()

public init() {}

@discardableResult
public func addColumn<T>(_ fieldName: String, arrowArray: ArrowArray<T>) throws -> Builder {
return self.addColumn(fieldName, chunked: try ChunkedArray([arrowArray]))
Expand Down Expand Up @@ -121,10 +123,10 @@ public class ArrowTable {
}

public class RecordBatch {
let schema: ArrowSchema
var columnCount: UInt {get{return UInt(self.columns.count)}}
let columns: [ArrowArrayHolder]
let length: UInt
public let schema: ArrowSchema
public var columnCount: UInt {get{return UInt(self.columns.count)}}
public let columns: [ArrowArrayHolder]
public let length: UInt
public init(_ schema: ArrowSchema, columns: [ArrowArrayHolder]) {
self.schema = schema
self.columns = columns
Expand All @@ -135,6 +137,8 @@ public class RecordBatch {
let schemaBuilder = ArrowSchema.Builder()
var columns = [ArrowArrayHolder]()

public init() {}

@discardableResult
public func addColumn(_ fieldName: String, arrowArray: ArrowArrayHolder) -> Builder {
let field = ArrowField(fieldName, type: arrowArray.type, isNullable: arrowArray.nullCount != 0)
Expand Down
2 changes: 2 additions & 0 deletions swift/Arrow/Sources/Arrow/ArrowWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class ArrowWriter {
}
}

public init() {}

private func writeField(_ fbb: inout FlatBufferBuilder, field: ArrowField) -> Result<Offset, ArrowError> {
let nameOffset = fbb.create(string: field.name)
let fieldTypeOffsetResult = toFBType(&fbb, arrowType: field.type)
Expand Down

0 comments on commit 9da86dc

Please sign in to comment.