You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The in-memory contiguous buffers allow constant-time random access.
28
+
29
+
Every Arrow array supports nullable elements. This is encoded as an optional bit-packed validity buffer aka null array aka bitfield.
30
+
In psuedocode, bitfield[index] == 0 means null or invalid, and bitfield[index] == 1 means not null or valid.
31
+
Fixed-width types are encoded back-to-back, with placeholder values for nulls. For example the array:
32
+
33
+
```swift
34
+
let swiftArray: [Int8?] = [1, nil, 2, 3, nil, 4]
35
+
let arrayBuilder: ArrayBuilderFixedWidth<Int8> = .init()
36
+
for value in swiftArray {
37
+
iflet value {
38
+
arrayBuilder.append(value)
39
+
} else {
40
+
arrayBuilder.appendNull()
41
+
}
42
+
}
43
+
let arrowArray = arrayBuilder.finish()
44
+
for i in0..<swiftArray.count {
45
+
#expect(arrowArray[i] == swiftArray[i])
46
+
}
47
+
```
48
+
49
+
would be backed by a values buffer of `Int8`:
50
+
51
+
`[1, 0, 2, 3, 0, 4]`
52
+
53
+
and a bit-packed validity buffer of UInt8:
54
+
`[45]` or `[b00101101]`
55
+
56
+
Note the validity buffer may be empty if all values are null, or all values are non null.
57
+
58
+
Arrow Arrays of variable-length types such as `String` have an offsets buffer. For example:
59
+
60
+
```swift
61
+
let swiftArray: [String?] = ["ab", nil, "c", "", "."]
62
+
let arrayBuilder: ArrayBuilderVariable<String> = .init()
63
+
for value in swiftArray {
64
+
iflet value {
65
+
arrayBuilder.append(value)
66
+
} else {
67
+
arrayBuilder.appendNull()
68
+
}
69
+
}
70
+
let arrowArray = arrayBuilder.finish()
71
+
#expect(arrowArray[0] =="ab")
72
+
#expect(arrowArray[1] ==nil)
73
+
#expect(arrowArray[2] =="c")
74
+
#expect(arrowArray[3] =="")
75
+
#expect(arrowArray[4] ==".")
76
+
```
77
+
78
+
would have an offsets array of array length + 1 integers:
79
+
`[0, 2, 2, 3, 3, 4]`
80
+
81
+
This is a lookup into the value array, i.e.:
82
+
83
+
```swift
84
+
let values: [UInt8] = [97, 98, 99, 46]
85
+
print(values[0..<2]) // [97, 98]
86
+
print(values[2..<2]) // []
87
+
print(values[2..<3]) // [99]
88
+
print(values[3..<4]) // [46]
89
+
```
90
+
91
+
In practice, buffers can be any contingous storage. In Swift-Arrow, arrays created in memory are usually backed by pointers, whereas arrays loaded from IPC files are backed by memory-mapped `Data` instances.
92
+
93
+
Arrays can be configured to use different buffer types, by specifying the types as
this allows the buffer types to be user-specified, e.g.:
97
+
```
98
+
typealias ArrowArrayUtf8 = ArrowArrayVariable<
99
+
FixedWidthBufferIPC<Int32>,
100
+
VariableLengthBufferIPC<String>
101
+
>
102
+
``
103
+
104
+
105
+
## Relationship to Arrow-Swift
106
+
9
107
This project is based on Arrow-Swift, the official Swift implementation of Apache Arrow. The decision was made to at least temporarily operate independently of the Apache Software Foundation (ASF). Currently there are no active ASF maintaners with knowledge of Swift, and the only [Apache approved CI for Swift](https://github.com/apache/infrastructure-actions/blob/main/approved_patterns.yml) is [setup-swift which is unmaintained](https://github.com/swift-actions/setup-swift/issues), leading to intermittent CI failures. This has led to delays in much-needed fixes being implemented.
10
108
11
109
The intention is to continue contributing to the official Apache-Swift repository, however changes can be iterated on more quickly here.
0 commit comments