State the codec each class reads and writes its values with - #157
Merged
estebanzimanyi merged 1 commit intoOct 1, 2026
Merged
estebanzimanyi merged 1 commit into
estebanzimanyi merged 1 commit into
Conversation
typeEncodings states, for each class, the public functions a binding
reads and writes a value with and the trailing inputs each takes, read
once the SQL signatures and the bound literals are in the catalog
(parser/codecs.py, after the bound literals resolve).
A class several SQL types share reads and writes each type through that
type's own public function: readers and writers map the SQL type a
function's signature returns or takes to the function, Set {text:
{intset: intset_in, floatset: floatset_in, ...}}, and that encoding has
no single decoder or encoder. Within one SQL type the function the
encoding table names first wins (cbuffer_out before cbuffer_as_ewkt),
then the one serving fewer SQL types (cbufferset_out before
spatialset_out); two that tie stop the catalog. An encoding whose
functions carry no SQL signature keeps the function the C shapes give
it, as GSERIALIZED does, its geometry and geography being PostGIS's
types.
The hex-WKB writer is a class's wkb encoder, its size an out-parameter
of the function's shape.outParams. Its variant is the value the type's
own send binds, WKB_EXTENDED or 0, else the value its SQL hex writer
passes when the byte order is left out: asHexWKB(raster, endian DEFAULT
'') passes 0, so Raster writes through raster_as_hexwkb. Every decoder,
encoder, reader and writer states its trailing inputs by name with the
value a binding passes, in decoderAux, encoderAux, readerAux and
writerAux, and the byte codec its variant in bytes.encoderAux: a
binding fills each parameter by name and refuses one the catalog does
not fill.
A slot whose header names a type of its own over a width, a typedef
neither PostgreSQL nor the C standard defines whose chain reaches a C
standard integer, keeps that name as typedef beside canonical, which
states the width: {canonical: uint64_t, typedef: H3Index}. H3Index,
Quadbin and S2CellId are classes of their own, read and written by their
own functions.
Why. A binding read every set from text through bigintset_in and wrote
every temporal value through the internal temporal_out: the per-class
pick was right for one SQL type and wrong for the others, and the
generic functions that would serve all of them are internal. A cell
read as a bare uint64_t accepts values no cell is.
Measured. Over MobilityDB 72abdf86c2: Set reads and writes 18 SQL types,
Span and SpanSet 5 each, Temporal writes 20 and reads 17 from text and
5 from MF-JSON; the classes stating a hex-WKB writer go from 2 to 19;
H3Index, Quadbin and S2CellId join the 27 classes; 229 slots carry a
typedef, every one a cell id. GSERIALIZED, TimeTzADT, NumericData,
TInstant, TSequence and TSequenceSet keep the codec they state, and
beside typeEncodings, struct serialization and typedef the catalog is
byte for byte the one derived without this change. tpose_in,
tposechain_in, trgeometry_in and 15 of the 20 *_from_mfjson readers
carry no SQL signature, so no SQL type keys them.
Witness. tests/test_codecs.py reads and writes each set type through its
own function, a type through its narrower writer, the hex writer with
the variant its send binds and, without a send, the SQL writer's
default, a cell as a class of its own, and stops on two readers alike
for one type; over the catalog, every stated trailing input names a
parameter of its function, carries a value and is no out-parameter.
tests/test_typerecover.py finds typedef on the three cell ids alone.
tests/test_engine_integration.py reads and writes tbool, tint, tfloat
and ttext through the reader and writer the catalog states for each.
The suite floor goes from 368 to 377.
estebanzimanyi
force-pushed
the
catalog/codecs-every-class-states
branch
from
October 1, 2026 10:58
fc1e950 to
058d607
Compare
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.
typeEncodings states, for each class, the public functions a binding
reads and writes a value with and the trailing inputs each takes, read
once the SQL signatures and the bound literals are in the catalog
(parser/codecs.py, after the bound literals resolve).
A class several SQL types share reads and writes each type through that
type's own public function: readers and writers map the SQL type a
function's signature returns or takes to the function, Set {text:
{intset: intset_in, floatset: floatset_in, ...}}, and that encoding has
no single decoder or encoder. Within one SQL type the function the
encoding table names first wins (cbuffer_out before cbuffer_as_ewkt),
then the one serving fewer SQL types (cbufferset_out before
spatialset_out); two that tie stop the catalog. An encoding whose
functions carry no SQL signature keeps the function the C shapes give
it, as GSERIALIZED does, its geometry and geography being PostGIS's
types.
The hex-WKB writer is a class's wkb encoder, its size an out-parameter
of the function's shape.outParams. Its variant is the value the type's
own send binds, WKB_EXTENDED or 0, else the value its SQL hex writer
passes when the byte order is left out: asHexWKB(raster, endian DEFAULT
'') passes 0, so Raster writes through raster_as_hexwkb. Every decoder,
encoder, reader and writer states its trailing inputs by name with the
value a binding passes, in decoderAux, encoderAux, readerAux and
writerAux, and the byte codec its variant in bytes.encoderAux: a
binding fills each parameter by name and refuses one the catalog does
not fill.
A slot whose header names a type of its own over a width, a typedef
neither PostgreSQL nor the C standard defines whose chain reaches a C
standard integer, keeps that name as typedef beside canonical, which
states the width: {canonical: uint64_t, typedef: H3Index}. H3Index,
Quadbin and S2CellId are classes of their own, read and written by their
own functions.
Why. A binding read every set from text through bigintset_in and wrote
every temporal value through the internal temporal_out: the per-class
pick was right for one SQL type and wrong for the others, and the
generic functions that would serve all of them are internal. A cell
read as a bare uint64_t accepts values no cell is.
Measured. Over MobilityDB 72abdf86c2: Set reads and writes 18 SQL types,
Span and SpanSet 5 each, Temporal writes 20 and reads 17 from text and
5 from MF-JSON; the classes stating a hex-WKB writer go from 2 to 19;
H3Index, Quadbin and S2CellId join the 27 classes; 229 slots carry a
typedef, every one a cell id. GSERIALIZED, TimeTzADT, NumericData,
TInstant, TSequence and TSequenceSet keep the codec they state, and
beside typeEncodings, struct serialization and typedef the catalog is
byte for byte the one derived without this change. tpose_in,
tposechain_in, trgeometry_in and 15 of the 20 *_from_mfjson readers
carry no SQL signature, so no SQL type keys them.
Witness. tests/test_codecs.py reads and writes each set type through its
own function, a type through its narrower writer, the hex writer with
the variant its send binds and, without a send, the SQL writer's
default, a cell as a class of its own, and stops on two readers alike
for one type; over the catalog, every stated trailing input names a
parameter of its function, carries a value and is no out-parameter.
tests/test_typerecover.py finds typedef on the three cell ids alone.
tests/test_engine_integration.py reads and writes tbool, tint, tfloat
and ttext through the reader and writer the catalog states for each.
The suite floor goes from 368 to 377.