Repository navigation
Column frames: rid and list-of-number columns travel in binary kinds, not JSON - #394
Conversation
54cf84a to
b04e107
Compare
3a341c5 to
6ab2265
Compare
…#388, #315) A RID, a list, a map or a mixed column was one tagged JSON array of the column (the json kind), parsed per cell in Python. The decoder now also reads rid (bucket and position, two int64 per row) and li8 or lf8 (int32 offsets, a bitmap of null elements, one flat int64 or float64 array) and still reads json for those columns, so a frame of an older writer decodes as before. to_columns gives Python lists of exact int or float and, for a rid column, the wheel's own RID object (the native wheel builds its RID from the pair; the JVM bridge puts the engine's RID objects into a side array in row order, so the JVM wheel still hands out the engine's own RID). to_arrow gives a string column of #bucket:position for RIDs, as the column of RID objects degraded to before, and list<int64> or list<double> over the frame's own offsets and flat array for the lists, with no per-element Python object. The head frame the native wheel writes in Python for the first reply is unchanged (json, the values themselves). tests/test_column_frames.py builds frames by hand (no database) and decodes them: rid, li8 and lf8 with nulls, empty lists, None inside, NaN, the infinities, -0.0 and integers beyond 2**53, against the JSON form of the same column, and a json frame of RIDs, lists and maps still reads.
The bridge jar wrote a column of record links and a column of lists as one tagged JSON array (json). It now writes rid for a column of valid RIDs (two int64 per row, and the engine's RID objects go into the side array in row order from the index the column header names as side) and li8 or lf8 for a column of lists of integers or of floats (int32 offsets, a bitmap of null elements, one flat int64 or float64 array). Maps, nested lists, lists of strings, booleans or RIDs, lists that mix ints and floats, a list of nothing but nulls, an invalid RID (negative bucket or position), a column that mixes kinds and a column with more than 2**27 list elements in one frame stay json. The decoder of the commit before reads both forms. The native library's writer is not part of this change.
… output of the released wheels (refs #388, #315) tests/test_frame_rid_list_kinds.py reads the kind of each column from the frame headers (KINDS says per writer what it writes: the JVM bridge the new kinds, the native library json), compares the four columnar readers with the row route (to_list) cell by cell including the type and text of every RID, and with the stored output of the released wheels. A binary column has to show its kind in at least one frame and be json or that kind in all, because a read ends with an empty frame and the native wheel decodes its Python-written head frame (always json) after the library's frames. tests/fixtures/frame_kinds_post3.json is the output of the released 26.11.1.post3 wheels (JSON route, one entry per wheel) for the tables of the test, dumped before the change by a throwaway run on a branch cut from the tag and never generated from this code. It holds the type, the row count and the sha256 of the exact values per column: the first dump also had a 24-value sample per column, which a script deleted (a key removed, nothing recomputed), and the file is formatted with prettier as the pre-commit check of main requires.
6ab2265 to
f1ec4a3
Compare
|
I rebased this onto
Limits: one host and one run of 16 rounds; the JVM wheel only (the native writer is a separate pull request, #450, stacked on this one); a small result table of one I am updating the description with this and taking the PR out of draft so CI runs on it. |
What does this PR do?
A column of record links or of lists of numbers inside a binary column frame was one tagged JSON array of the column (the
jsonkind), parsed per cell in Python. This is rank 10 of #388. The JVM writer (ColumnBatcherof the bridge jar) now writes two more column kinds, and the one shared decoderarcadedb/_columnar.pyreads them. The native writer (ColumnFramesof the native image) is in #450, stacked on this pull request, so this one changes no native code:rid: two int64 per row, the bucket and the position of a record link.to_arrowgives a string column of#bucket:position, as the column of RID objects degraded to before.to_columnsandto_dataframegive the wheel's own RID object: the native wheel builds itsRIDfrom the pair, and the JVM bridge puts the engine's RID objects into the side array in row order (the header names where they start,side), so the JVM wheel still hands out the engine's own RID, which a bucket and a position cannot be turned back into on the Python side without the database.to_arrownever touches the side array.li8andlf8: a list of int64 or of float64 per row. The buffer is int32 offsets (rows + 1), a bitmap with one bit per element of the flat array for a null element, then the flat int64 or float64 array of every list's elements. A null row is the frame's null bit, an empty list is two equal offsets,Noneinside a list is a bit of the bitmap. NaN, the infinities and-0.0are float64 values.to_columnsgives Python lists of exactintorfloat,to_arrowgiveslist<int64>orlist<double>over the frame's own offsets and flat array.What keeps the
jsonkind: maps, nested lists, lists of strings, booleans or RIDs, a list that mixes ints and floats (each element keeps its own type there), a list of nothing but nulls or empty lists (Arrow types itlist<null>, an element type cannot be read from it), embedded records, a RID that is not valid (negative bucket or position), a column that mixes kinds (a column of int lists in one row and float lists in another isjson),Set, primitive arrays, and a column with more than 2**27 list elements in one frame (int32 offsets). The decoder keeps readingjsonfor RID and list columns, so a frame of an older writer still decodes. The first 256 rows of a native result are written as a frame in Python from the JSON reply (the values themselves,jsonkind); that code is unchanged, and the decoder gives the same values and the same Arrow types for both forms.Related issues
Refs #388 and #315.
Performance changes
Measured with a paired A/B on the mini:
arcadedb-jvm26.11.1.post4with the Python files ofsrc/arcadedband the bridge jar swapped per arm (the jar compiled from each arm'ssrc/javaagainst the wheel's own jars): A is the tip ofmain076d6d5674, B is this PRf1ec4a3c6c, and C is A again as the control. 16 rounds, one JVM and one fresh database per arm and round, interleaved cycles, the trimmed mean of the timed reads per case, a bootstrap 95% interval over the rounds, and the rule of #317, read row by row: a row counts only when its own control is inside 0.97 to 1.03. The process was confined to the two cores of one compare lane of the mini (Cpus_allowed_list: 0,2), no other study ran, and the host worker recorded 0 ms of thermal throttle.to_arrowandto_polarsridridlinklinkintlistintlistfloatlistfloatlistto_columnsandto_dataframeridridlinklinkintlistintlistfloatlistfloatlistto_arrowandto_polars, record links and RIDs: at 100 rows B/A is 0.439 to 0.571 over 4 rows (2 readable: 0.439 to 0.447); at 100,000 rows 0.209 to 0.239 over 8 rows (7 readable: 0.209 to 0.239).to_arrowandto_polars, lists of integers and of floats: at 100,000 rows B/A is 0.321 to 0.361 over 4 rows (none readable) for integers and 0.224 to 0.228 over 4 rows (none readable) for floats.to_columnsandto_dataframe, record links and RIDs: at 100 rows and more B/A is 0.782 to 0.875 over 10 rows (4 readable: 0.800 to 0.875).to_columnsandto_dataframe, lists: floats 0.483 to 0.650 over 5 rows (none readable); integers at 100,000 rows 0.939 to 1.019 over 3 rows (none readable). Integer lists are the one shape that does not gain at 100,000 rows in the objects family, which I expected from reading the decoder (it slices per row in Python andjson.loadsis C), not from a measurement of the decoder.jsonkind): B/A is 0.941 to 1.056 over 45 rows (11 readable: 0.976 to 0.999). No row points to a regression.jsonframes, B getsrid,li8andlf8where this PR writes them, and the values and Arrow types every reader returns are equal in all arms.Limits: one host and one run of 16 rounds; the JVM wheel only (the native writer is a separate pull request, #450, stacked on this one); a small result table of one
@ridor link column, an 8-element list, or a scalar column, per shape.The figure as registered before the run: the operation is a columnar read of one query through
to_columns(),to_arrow(),to_dataframe()andto_polars(), one read of the whole result per operation, at 1, 100 and 100,000 rows plus abatch_sizethat splits 100,000 rows into 10 frames, for aSELECT @ridcolumn, a link property, an int list column and a float list column, with the shapes that keepjson(a map, a nested list, a scalar-only result) as controls.Docs
No page under
docs/orREADME.mddescribes the frame kinds; the module docstrings ofarcadedb/_columnar.py,ColumnFrames.javaandColumnBatcher.javaand the one ofarcadedb/_native/colframes.pyare updated.How I checked it
tests/test_column_frames.py(hand-built frames, no database):rid,li8andlf8with nulls, empty lists,Noneinside, NaN, the infinities,-0.0and integers beyond 2**53; the decoder against the JSON form of the same column (values, Python types, Arrow type); the hook that makes the RID objects; and ajsonframe of RIDs, lists and maps still reads. Six of the seven fail on the decoder of the tag.tests/test_frame_rid_list_kinds.py(both wheels, no branch on the backend except the stored output): which kind each shape gets, read from the frame headers (this fails while a writer still writesjson), the four readers against the row route (to_list) cell by cell including the type and text of every RID, and against the stored output of the released wheels.Checklist
uvx pre-commit run --files <changed files>passes