File size: 596 Bytes
9ff4bea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Internal Arrow utilities."""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    import datafusion
    import pyarrow as pa


def to_record_batch(table: pa.RecordBatch | list[pa.RecordBatch] | datafusion.DataFrame) -> pa.RecordBatch:
    """Convert various table types to a single RecordBatch."""

    import pyarrow as pa

    if isinstance(table, pa.RecordBatch):
        return table
    elif isinstance(table, list):
        return pa.concat_batches(table)
    else:
        # datafusion.DataFrame
        return pa.concat_batches(table.collect())