@@ -32,6 +32,7 @@ import org.apache.arrow.vector.VarCharVector
32
32
import org.apache.arrow.vector.VectorSchemaRoot
33
33
import org.apache.arrow.vector.complex.StructVector
34
34
import org.apache.arrow.vector.ipc.ArrowFileReader
35
+ import org.apache.arrow.vector.ipc.ArrowReader
35
36
import org.apache.arrow.vector.ipc.ArrowStreamReader
36
37
import org.apache.arrow.vector.types.pojo.Field
37
38
import org.apache.arrow.vector.util.DateUtility
@@ -262,17 +263,7 @@ internal fun DataFrame.Companion.readArrowIPCImpl(
262
263
allocator : RootAllocator = Allocator .ROOT ,
263
264
nullability : NullabilityOptions = NullabilityOptions .Infer ,
264
265
): AnyFrame {
265
- ArrowStreamReader (channel, allocator).use { reader ->
266
- val flattened = buildList {
267
- val root = reader.vectorSchemaRoot
268
- val schema = root.schema
269
- while (reader.loadNextBatch()) {
270
- val df = schema.fields.map { f -> readField(root, f, nullability) }.toDataFrame()
271
- add(df)
272
- }
273
- }
274
- return flattened.concatKeepingSchema()
275
- }
266
+ return readArrowReaderImpl(ArrowStreamReader (channel, allocator), nullability)
276
267
}
277
268
278
269
/* *
@@ -283,14 +274,36 @@ internal fun DataFrame.Companion.readArrowFeatherImpl(
283
274
allocator : RootAllocator = Allocator .ROOT ,
284
275
nullability : NullabilityOptions = NullabilityOptions .Infer ,
285
276
): AnyFrame {
286
- ArrowFileReader (channel, allocator).use { reader ->
277
+ return readArrowReaderImpl(ArrowFileReader (channel, allocator), nullability)
278
+ }
279
+
280
+ /* *
281
+ * Read [Arrow any format](https://arrow.apache.org/docs/java/ipc.html#reading-writing-ipc-formats) data from existing [reader]
282
+ */
283
+ internal fun DataFrame.Companion.readArrowReaderImpl (
284
+ reader : ArrowReader ,
285
+ nullability : NullabilityOptions = NullabilityOptions .Infer
286
+ ): AnyFrame {
287
+ reader.use {
287
288
val flattened = buildList {
288
- reader.recordBlocks.forEach { block ->
289
- reader.loadRecordBatch(block)
290
- val root = reader.vectorSchemaRoot
291
- val schema = root.schema
292
- val df = schema.fields.map { f -> readField(root, f, nullability) }.toDataFrame()
293
- add(df)
289
+ when (reader) {
290
+ is ArrowFileReader -> {
291
+ reader.recordBlocks.forEach { block ->
292
+ reader.loadRecordBatch(block)
293
+ val root = reader.vectorSchemaRoot
294
+ val schema = root.schema
295
+ val df = schema.fields.map { f -> readField(root, f, nullability) }.toDataFrame()
296
+ add(df)
297
+ }
298
+ }
299
+ is ArrowStreamReader -> {
300
+ val root = reader.vectorSchemaRoot
301
+ val schema = root.schema
302
+ while (reader.loadNextBatch()) {
303
+ val df = schema.fields.map { f -> readField(root, f, nullability) }.toDataFrame()
304
+ add(df)
305
+ }
306
+ }
294
307
}
295
308
}
296
309
return flattened.concatKeepingSchema()
0 commit comments