Skip to content

Answer NULL at the distance sentinel the catalog states through distance_sentinel - #426

Merged
estebanzimanyi merged 1 commit into
MobilityDB:mainfrom
estebanzimanyi:codegen/distance-sentinel-guard
Oct 5, 2026
Merged

estebanzimanyi merged 1 commit into
MobilityDB:mainfrom
estebanzimanyi:codegen/distance-sentinel-guard

Conversation

@estebanzimanyi

Copy link
Copy Markdown
Member

tools/codegen_duck_udfs.py reads the guard if (datum_eq(result, distance_sentinel(basetype),
basetype)), on which a PG wrapper returns NULL for a distance computed in the base type, as the
test r == std::numeric_limits<decltype(r)>::max() on the result in the type MEOS returns, before
its conversion to the declared float, as emit_temporal_box tests the sentinel of a box. The
nearest approach distance between two temporal numbers, and between a temporal number and a
number, is NULL where the two share no time, over tint, tbigint and tfloat.

Why: distance_sentinel answers the maximum of the type the distance is expressed in where no
distance is computed, and NAD_tnumber_tnumber and NAD_tnumber_number return NULL on it; the
catalog carries that guard in shape.nullableResult, while SCALAR_NULL_GUARD read only the
result == DBL_MAX form, so the six nearestApproachDistance functions over numbers returned the
sentinel itself as a distance.

Witness: Gen_nad_tfloat_tfloat returns (double) r with no test, r being what nad_tfloat_tfloat
answers, so for two tfloat values sharing no time the row holds DBL_MAX, and over tint and
tbigint the maxima of int and int64 widened to a double; with this change the row is NULL.

Measured: over the catalog the shared provision derives from MobilityDB master 4c4457d2ec, the
generator writes the same 1972 functions and 7389 registrations, and the six
Gen_nad_{tint_int, tint_tint, tbigint_bigint, tbigint_tbigint, tfloat_float, tfloat_tfloat}
take ExecuteWithNulls and the test; no other function differs. The committed surface carries the
six as the generator writes them; generated_temporal_udfs_2.cpp compiles warning-free.
test/sql/parity/036_tnumber_distance.test states the three NULLs.

…nce_sentinel

tools/codegen_duck_udfs.py reads the guard if (datum_eq(result, distance_sentinel(basetype),
basetype)), on which a PG wrapper returns NULL for a distance computed in the base type, as the
test r == std::numeric_limits<decltype(r)>::max() on the result in the type MEOS returns, before
its conversion to the declared float, as emit_temporal_box tests the sentinel of a box. The
nearest approach distance between two temporal numbers, and between a temporal number and a
number, is NULL where the two share no time, over tint, tbigint and tfloat.

Why: distance_sentinel answers the maximum of the type the distance is expressed in where no
distance is computed, and NAD_tnumber_tnumber and NAD_tnumber_number return NULL on it; the
catalog carries that guard in shape.nullableResult, while SCALAR_NULL_GUARD read only the
result == DBL_MAX form, so the six nearestApproachDistance functions over numbers returned the
sentinel itself as a distance.

Witness: Gen_nad_tfloat_tfloat returns (double) r with no test, r being what nad_tfloat_tfloat
answers, so for two tfloat values sharing no time the row holds DBL_MAX, and over tint and
tbigint the maxima of int and int64 widened to a double; with this change the row is NULL.

Measured: over the catalog the shared provision derives from MobilityDB master 4c4457d2ec, the
generator writes the same 1972 functions and 7389 registrations, and the six
Gen_nad_{tint_int, tint_tint, tbigint_bigint, tbigint_tbigint, tfloat_float, tfloat_tfloat}
take ExecuteWithNulls and the test; no other function differs. The committed surface carries the
six as the generator writes them; generated_temporal_udfs_2.cpp compiles warning-free.
test/sql/parity/036_tnumber_distance.test states the three NULLs.
@estebanzimanyi
estebanzimanyi merged commit 770f54f into MobilityDB:main Oct 5, 2026
9 checks passed
@estebanzimanyi
estebanzimanyi deleted the codegen/distance-sentinel-guard branch October 5, 2026 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant