Add nodes to convert between csp structs and arrow record batches#680
Open
arhamchopra wants to merge 3 commits intomainfrom
Open
Add nodes to convert between csp structs and arrow record batches#680arhamchopra wants to merge 3 commits intomainfrom
arhamchopra wants to merge 3 commits intomainfrom
Conversation
Signed-off-by: Arham Chopra <arham.chopra@cubistsystematic.com>
7341648 to
78acf28
Compare
Signed-off-by: Arham Chopra <arham.chopra@cubistsystematic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
record_batches_to_structandstruct_to_record_batchesnodesTwo new C++-backed nodes for bidirectional conversion between
csp.Structand ArrowRecordBatch:struct_to_record_batches—ts[List[T]]→ts[List[pa.RecordBatch]]record_batches_to_struct—ts[List[pa.RecordBatch]]→ts[List[T]]Both use the Arrow C Data Interface (PyCapsule protocol) to cross the Python/C++ boundary without serialization overhead. Scalar and temporal fields are read/written entirely in C++. Numpy array fields use bulk memory transfers rather than per-element iteration.
Supported types
bool,int8/16/32/64,uint8/16/32/64,double,str,bytes,datetime,timedelta,date,time,csp.Enum, nestedcsp.Struct,Numpy1DArray[T], andNumpyNDArray[T].Performance
Read and write paths are columnar: each column is processed in a single
readAll()/writeAll()call per batch rather than row-by-row virtual dispatch, reducing virtual call count from N×M (rows × columns) to M. ThereadAll()path uses anull_count==0fast path that skips per-row validity checks entirely. Fixed-size writers useUnsa feAppendafter a singleReserve()to skip per-row capacity and status checks. Nested struct readers pre-allocate all child structs before delegating to childreadAll()calls column by column.Throughput on 100k numeric rows (int64 + float64): ~6.4M rows/sec read, ~800k rows/sec write (write dominated by CSP graph overhead).
Stress tests comparing reading compressed parquet files through both the Parquet adapter (
ParquetReader.subscribe_all) and the Arrow path (RecordBatchPullInputAdapter→record_batches_to_struct):Arrow's advantage grows with larger batches per timestamp. The 1-row-per-timestamp case exposes per-tick overhead from
RecordBatchPullInputAdaptercreating and converting individual single-row batches — the Parquet adapter handles this natively since its C++ reader emits one struct per row without intermediate Arrow batches.Example