Skip to content

Commit 0b3d158

Browse files
Merge branch 'columnar-swift:main' into main
2 parents ccc01e6 + 3e4efa3 commit 0b3d158

File tree

7 files changed

+106
-40
lines changed

7 files changed

+106
-40
lines changed

.swift-format

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"fileScopedDeclarationPrivacy" : {
3+
"accessLevel" : "private"
4+
},
5+
"indentation" : {
6+
"spaces" : 2
7+
},
8+
"indentConditionalCompilationBlocks" : false,
9+
"indentSwitchCaseLabels" : false,
10+
"lineBreakAroundMultilineExpressionChainComponents" : false,
11+
"lineBreakBeforeControlFlowKeywords" : false,
12+
"lineBreakBeforeEachArgument" : false,
13+
"lineBreakBeforeEachGenericRequirement" : false,
14+
"lineLength" : 80,
15+
"maximumBlankLines" : 1,
16+
"multiElementCollectionTrailingCommas" : true,
17+
"noAssignmentInExpressions" : {
18+
"allowedFunctions" : [
19+
"XCTAssertNoThrow"
20+
]
21+
},
22+
"prioritizeKeepingFunctionOutputTogether" : false,
23+
"respectsExistingLineBreaks" : true,
24+
"rules" : {
25+
"AllPublicDeclarationsHaveDocumentation" : false,
26+
"AlwaysUseLiteralForEmptyCollectionInit" : true,
27+
"AlwaysUseLowerCamelCase" : true,
28+
"AmbiguousTrailingClosureOverload" : false,
29+
"BeginDocumentationCommentWithOneLineSummary" : true,
30+
"DoNotUseSemicolons" : true,
31+
"DontRepeatTypeInStaticProperties" : true,
32+
"FileScopedDeclarationPrivacy" : true,
33+
"FullyIndirectEnum" : true,
34+
"GroupNumericLiterals" : true,
35+
"IdentifiersMustBeASCII" : true,
36+
"NeverForceUnwrap" : true,
37+
"NeverUseForceTry" : true,
38+
"NeverUseImplicitlyUnwrappedOptionals" : true,
39+
"NoAccessLevelOnExtensionDeclaration" : true,
40+
"NoAssignmentInExpressions" : true,
41+
"NoBlockComments" : true,
42+
"NoCasesWithOnlyFallthrough" : true,
43+
"NoEmptyTrailingClosureParentheses" : true,
44+
"NoLabelsInCasePatterns" : true,
45+
"NoLeadingUnderscores" : false,
46+
"NoParensAroundConditions" : true,
47+
"NoPlaygroundLiterals" : true,
48+
"NoVoidReturnOnFunctionSignature" : true,
49+
"OmitExplicitReturns" : true,
50+
"OneCasePerLine" : true,
51+
"OneVariableDeclarationPerLine" : true,
52+
"OnlyOneTrailingClosureArgument" : true,
53+
"OrderedImports" : true,
54+
"ReplaceForEachWithForLoop" : true,
55+
"ReturnVoidInsteadOfEmptyTuple" : true,
56+
"TypeNamesShouldBeCapitalized" : true,
57+
"UseEarlyExits" : false,
58+
"UseExplicitNilCheckInConditions" : true,
59+
"UseLetInEveryBoundCaseVariable" : true,
60+
"UseShorthandTypeNames" : true,
61+
"UseSingleLinePropertyGetter" : true,
62+
"UseSynthesizedInitializer" : true,
63+
"UseTripleSlashForDocumentationComments" : true,
64+
"UseWhereClausesInForLoops" : false,
65+
"ValidateDocumentationComments" : true
66+
},
67+
"spacesBeforeEndOfLineComments": 2,
68+
"spacesAroundRangeFormationOperators" : false,
69+
"tabWidth" : 2,
70+
"version" : 1
71+
}

Scripts/format.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
2-
git ls-files -- '*.swift' ':(exclude)Sources/Arrow/Generated/*' | xargs -0 swift format format --parallel --in-place
3-
git ls-files -- '*.swift' ':(exclude)Sources/Arrow/Generated/*' | xargs -0 swift format lint --strict --parallel
2+
git ls-files -- '*.swift' | xargs -0 swift format format --parallel --in-place
3+
git ls-files -- '*.swift' | xargs -0 swift format lint --strict --parallel

Sources/Arrow/ArrowBufferBuilder.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class BaseBufferBuilder {
4949
}
5050
return UInt(data.length * 2)
5151
}
52-
5352
return UInt(len * 2)
5453
}
5554
}
@@ -223,35 +222,31 @@ public class VariableBufferBuilder<T>: ValuesBufferBuilder<T>, ArrowBufferBuilde
223222
isNull = true
224223
binData = Data(bytes: &nullVal, count: MemoryLayout<UInt32>.size)
225224
}
226-
227225
var currentIndex: Int32 = 0
228226
var currentOffset: Int32 = Int32(binData.count)
229227
if index > 0 {
230228
currentIndex = self.offsets.rawPointer.advanced(by: offsetIndex).load(as: Int32.self)
231229
currentOffset += currentIndex
232230
if currentOffset > self.values.length {
233-
self.value_resize(UInt(currentOffset))
231+
self.valueResize(UInt(currentOffset))
234232
}
235233
}
236-
237234
if isNull {
238235
self.nullCount += 1
239236
BitUtility.clearBit(index + self.offset, buffer: self.nulls)
240237
} else {
241238
BitUtility.setBit(index + self.offset, buffer: self.nulls)
242239
}
243-
244240
binData.withUnsafeBytes { bufferPointer in
245241
let rawPointer = bufferPointer.baseAddress!
246242
self.values.rawPointer.advanced(by: Int(currentIndex))
247243
.copyMemory(from: rawPointer, byteCount: binData.count)
248244
}
249-
250245
self.offsets.rawPointer.advanced(by: (offsetIndex + MemoryLayout<Int32>.stride))
251246
.storeBytes(of: currentOffset, as: Int32.self)
252247
}
253248

254-
public func value_resize(_ length: UInt) {
249+
public func valueResize(_ length: UInt) {
255250
if length > self.values.length {
256251
let resizeLength = resizeLength(self.values, len: length)
257252
var values = ArrowBuffer.createBuffer(resizeLength, size: UInt(MemoryLayout<UInt8>.size))

Sources/Arrow/ArrowReader.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2025 The Apache Software Foundation
2+
// Copyright 2025 The Columnar-Swift Contributors
23
//
34
// Licensed under the Apache License, Version 2.0 (the "License");
45
// you may not use this file except in compliance with the License.
@@ -15,10 +16,10 @@
1516
import FlatBuffers
1617
import Foundation
1718

18-
let FILEMARKER = "ARROW1"
19-
let CONTINUATIONMARKER = UInt32(0xFFFF_FFFF)
19+
let fileMarker = "ARROW1"
20+
let continuationMarker = UInt32(0xFFFF_FFFF)
2021

21-
public class ArrowReader { // swiftlint:disable:this type_body_length
22+
public class ArrowReader {
2223
private class RecordBatchData {
2324
let schema: Schema
2425
let recordBatch: FlatRecordBatch
@@ -294,7 +295,7 @@ public class ArrowReader { // swiftlint:disable:this type_body_length
294295
var streamData = input
295296
var schemaMessage: Schema?
296297
while length != 0 {
297-
if length == CONTINUATIONMARKER {
298+
if length == continuationMarker {
298299
offset += Int(MemoryLayout<UInt32>.size)
299300
length = getUInt32(input, offset: offset)
300301
if length == 0 {
@@ -343,11 +344,13 @@ public class ArrowReader { // swiftlint:disable:this type_body_length
343344
return .success(result)
344345
}
345346

346-
/*
347-
This is for reading the Arrow file format. The Arrow file format supports
348-
random accessing the data. The Arrow file format contains a header and
349-
footer around the Arrow streaming format.
350-
*/
347+
/// This is for reading the Arrow file format. The Arrow file format supports
348+
/// random access. The Arrow file format contains a header and footer around
349+
/// the Arrow streaming format.
350+
/// - Parameters:
351+
/// - fileData: the file content
352+
/// - useUnalignedBuffers: to be removed.
353+
/// - Returns: An `ArrowReaderResult` on success, or an `ArrowError` on failure.
351354
public func readFile(
352355
_ fileData: Data,
353356
useUnalignedBuffers: Bool = false
@@ -378,7 +381,7 @@ public class ArrowReader { // swiftlint:disable:this type_body_length
378381
}
379382

380383
var messageOffset: Int64 = 1
381-
if messageLength == CONTINUATIONMARKER {
384+
if messageLength == continuationMarker {
382385
messageOffset += 1
383386
messageLength = fileData.withUnsafeBytes { rawBuffer in
384387
rawBuffer.loadUnaligned(
@@ -424,8 +427,7 @@ public class ArrowReader { // swiftlint:disable:this type_body_length
424427
if !validateFileData(fileData) {
425428
return .failure(.ioError("Not a valid arrow file."))
426429
}
427-
428-
let markerLength = FILEMARKER.utf8.count
430+
let markerLength = fileMarker.utf8.count
429431
let footerLengthEnd = Int(fileData.count - markerLength)
430432
let data = fileData[..<(footerLengthEnd)]
431433
return readFile(data)
@@ -475,6 +477,4 @@ public class ArrowReader { // swiftlint:disable:this type_body_length
475477
return .failure(.unknownError("Unhandled header type: \(message.headerType)"))
476478
}
477479
}
478-
479480
}
480-
// swiftlint:disable:this file_length

Sources/Arrow/ArrowReaderHelper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,10 @@ func validateBufferIndex(_ recordBatch: org_apache_arrow_flatbuf_RecordBatch, in
341341
}
342342

343343
func validateFileData(_ data: Data) -> Bool {
344-
let markerLength = FILEMARKER.utf8.count
344+
let markerLength = fileMarker.utf8.count
345345
let startString = String(decoding: data[..<markerLength], as: UTF8.self)
346346
let endString = String(decoding: data[(data.count - markerLength)...], as: UTF8.self)
347-
return startString == FILEMARKER && endString == FILEMARKER
347+
return startString == fileMarker && endString == fileMarker
348348
}
349349

350350
func getUInt32(_ data: Data, offset: Int) -> UInt32 {

Sources/Arrow/ArrowWriter.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public class ArrowWriter {
152152
let startIndex = writer.count
153153
switch writeRecordBatch(batch: batch) {
154154
case .success(let rbResult):
155-
withUnsafeBytes(of: CONTINUATIONMARKER.littleEndian) {
155+
withUnsafeBytes(of: continuationMarker.littleEndian) {
156156
writer.append(Data($0))
157157
}
158158
withUnsafeBytes(of: rbResult.1.o.littleEndian) {
@@ -397,7 +397,7 @@ public class ArrowWriter {
397397
let writer: any DataWriter = InMemDataWriter()
398398
switch toMessage(info.schema) {
399399
case .success(let schemaData):
400-
withUnsafeBytes(of: CONTINUATIONMARKER.littleEndian) { writer.append(Data($0)) }
400+
withUnsafeBytes(of: continuationMarker.littleEndian) { writer.append(Data($0)) }
401401
withUnsafeBytes(of: UInt32(schemaData.count).littleEndian) { writer.append(Data($0)) }
402402
writer.append(schemaData)
403403
case .failure(let error):
@@ -407,7 +407,7 @@ public class ArrowWriter {
407407
for batch in info.batches {
408408
switch toMessage(batch) {
409409
case .success(let batchData):
410-
withUnsafeBytes(of: CONTINUATIONMARKER.littleEndian) { writer.append(Data($0)) }
410+
withUnsafeBytes(of: continuationMarker.littleEndian) { writer.append(Data($0)) }
411411
withUnsafeBytes(of: UInt32(batchData[0].count).littleEndian) { writer.append(Data($0)) }
412412
writer.append(batchData[0])
413413
writer.append(batchData[1])
@@ -416,7 +416,7 @@ public class ArrowWriter {
416416
}
417417
}
418418

419-
withUnsafeBytes(of: CONTINUATIONMARKER.littleEndian) { writer.append(Data($0)) }
419+
withUnsafeBytes(of: continuationMarker.littleEndian) { writer.append(Data($0)) }
420420
withUnsafeBytes(of: UInt32(0).littleEndian) { writer.append(Data($0)) }
421421
if let memWriter = writer as? InMemDataWriter {
422422
return .success(memWriter.data)
@@ -449,14 +449,14 @@ public class ArrowWriter {
449449
let fileHandle = FileHandle(forUpdatingAtPath: fileName.path)!
450450
defer { fileHandle.closeFile() }
451451

452-
var markerData = FILEMARKER.data(using: .utf8)!
452+
var markerData = fileMarker.data(using: .utf8)!
453453
addPadForAlignment(&markerData)
454454

455455
var writer: any DataWriter = FileDataWriter(fileHandle)
456456
writer.append(markerData)
457457
switch writeFile(&writer, info: info) {
458458
case .success:
459-
writer.append(FILEMARKER.data(using: .utf8)!)
459+
writer.append(fileMarker.data(using: .utf8)!)
460460
case .failure(let error):
461461
return .failure(error)
462462
}

Tests/ArrowTests/ArrayTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
159159
XCTAssertEqual(milliBuilder.length, 3)
160160
XCTAssertEqual(milliBuilder.capacity, 136)
161161
let milliArray = try milliBuilder.finish()
162-
let milliType = milliArray.arrowData.type as! ArrowTypeTime32 // swiftlint:disable:this force_cast
162+
let milliType = milliArray.arrowData.type as! ArrowTypeTime32
163163
XCTAssertEqual(milliType.unit, .milliseconds)
164164
XCTAssertEqual(milliArray.length, 3)
165165
XCTAssertEqual(milliArray[1], 1_000_000)
@@ -173,7 +173,7 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
173173
XCTAssertEqual(secBuilder.length, 3)
174174
XCTAssertEqual(secBuilder.capacity, 136)
175175
let secArray = try secBuilder.finish()
176-
let secType = secArray.arrowData.type as! ArrowTypeTime32 // swiftlint:disable:this force_cast
176+
let secType = secArray.arrowData.type as! ArrowTypeTime32
177177
XCTAssertEqual(secType.unit, .seconds)
178178
XCTAssertEqual(secArray.length, 3)
179179
XCTAssertEqual(secArray[1], nil)
@@ -189,7 +189,7 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
189189
XCTAssertEqual(nanoBuilder.length, 3)
190190
XCTAssertEqual(nanoBuilder.capacity, 264)
191191
let nanoArray = try nanoBuilder.finish()
192-
let nanoType = nanoArray.arrowData.type as! ArrowTypeTime64 // swiftlint:disable:this force_cast
192+
let nanoType = nanoArray.arrowData.type as! ArrowTypeTime64
193193
XCTAssertEqual(nanoType.unit, .nanoseconds)
194194
XCTAssertEqual(nanoArray.length, 3)
195195
XCTAssertEqual(nanoArray[1], nil)
@@ -203,7 +203,7 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
203203
XCTAssertEqual(microBuilder.length, 3)
204204
XCTAssertEqual(microBuilder.capacity, 264)
205205
let microArray = try microBuilder.finish()
206-
let microType = microArray.arrowData.type as! ArrowTypeTime64 // swiftlint:disable:this force_cast
206+
let microType = microArray.arrowData.type as! ArrowTypeTime64
207207
XCTAssertEqual(microType.unit, .microseconds)
208208
XCTAssertEqual(microArray.length, 3)
209209
XCTAssertEqual(microArray[1], 20000)
@@ -220,7 +220,7 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
220220
XCTAssertEqual(secBuilder.length, 3)
221221
XCTAssertEqual(secBuilder.capacity, 264)
222222
let secArray = try secBuilder.finish()
223-
let secType = secArray.arrowData.type as! ArrowTypeTimestamp // swiftlint:disable:this force_cast
223+
let secType = secArray.arrowData.type as! ArrowTypeTimestamp
224224
XCTAssertEqual(secType.unit, .seconds)
225225
XCTAssertNil(secType.timezone)
226226
XCTAssertEqual(secArray.length, 3)
@@ -238,7 +238,7 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
238238
XCTAssertEqual(msBuilder.length, 3)
239239
XCTAssertEqual(msBuilder.capacity, 264)
240240
let msArray = try msBuilder.finish()
241-
let msType = msArray.arrowData.type as! ArrowTypeTimestamp // swiftlint:disable:this force_cast
241+
let msType = msArray.arrowData.type as! ArrowTypeTimestamp
242242
XCTAssertEqual(msType.unit, .milliseconds)
243243
XCTAssertEqual(msType.timezone, "America/New_York")
244244
XCTAssertEqual(msArray.length, 3)
@@ -255,7 +255,7 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
255255
XCTAssertEqual(usBuilder.length, 3)
256256
XCTAssertEqual(usBuilder.capacity, 264)
257257
let usArray = try usBuilder.finish()
258-
let usType = usArray.arrowData.type as! ArrowTypeTimestamp // swiftlint:disable:this force_cast
258+
let usType = usArray.arrowData.type as! ArrowTypeTimestamp
259259
XCTAssertEqual(usType.unit, .microseconds)
260260
XCTAssertEqual(usType.timezone, "UTC")
261261
XCTAssertEqual(usArray.length, 3)
@@ -272,7 +272,7 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
272272
XCTAssertEqual(nsBuilder.length, 3)
273273
XCTAssertEqual(nsBuilder.capacity, 264)
274274
let nsArray = try nsBuilder.finish()
275-
let nsType = nsArray.arrowData.type as! ArrowTypeTimestamp // swiftlint:disable:this force_cast
275+
let nsType = nsArray.arrowData.type as! ArrowTypeTimestamp
276276
XCTAssertEqual(nsType.unit, .nanoseconds)
277277
XCTAssertNil(nsType.timezone)
278278
XCTAssertEqual(nsArray.length, 3)
@@ -281,7 +281,7 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
281281
XCTAssertEqual(nsArray[2], 1_609_545_600_000_000_000)
282282
}
283283

284-
func testStructArray() throws { // swiftlint:disable:this function_body_length
284+
func testStructArray() throws {
285285
class StructTest {
286286
var fieldBool: Bool = false
287287
var fieldInt8: Int8 = 0

0 commit comments

Comments
 (0)