Skip to content

feat(bindings): tspatial direction predicates (above/below/front/back/left/right + over* variants)#39

Merged
nhungoc1508 merged 6 commits into
mainfrom
feat/tspatial-direction-predicates
Apr 27, 2026
Merged

feat(bindings): tspatial direction predicates (above/below/front/back/left/right + over* variants)#39
nhungoc1508 merged 6 commits into
mainfrom
feat/tspatial-direction-predicates

Conversation

@estebanzimanyi

Copy link
Copy Markdown
Member

Summary

Adds ScalarFunction registrations for tgeompoint × {STBox, tgeompoint} direction predicates wrapping MEOS *_tspatial_stbox / *_stbox_tspatial / *_tspatial_tspatial. 36 registrations total (12 directions × 3 type-pair shapes).

Direction Operator Named function
left / right << / >>
overleft / overright &< / &>
above / below above(...) / below(...)
front / back front(...) / back(...)
overabove / overbelow overabove(...) / overbelow(...)
overfront / overback overfront(...) / overback(...)

The above/below/front/back operators in MobilityDB (|>>, <<|, <</, />>, &</, /&>, etc.) contain | and / characters that DuckDB's parser does not accept inside operator names, so those use named functions instead.

Each direction emits 3 wrappers via DEFINE_TSPATIAL_STBOX_POS(name, meos_fn):

  • name##_tspatial_stbox
  • name##_stbox_tspatial
  • name##_tspatial_tspatial

These reuse the existing TempBoxBoolPred<STBox> / BoxTempBoolPred<STBox> / TempTempBoolPred helpers — STBox blob layout matches the templated Box* malloc/memcpy path used for TBox.

Semantics

  • above / below operate on the Y axis
  • left / right on the X axis
  • front / back on the Z axis (require 3D Point Z(x y z) or STBox Z(...))

Test plan

@estebanzimanyi estebanzimanyi force-pushed the feat/tspatial-direction-predicates branch from b9481c8 to 503f913 Compare April 25, 2026 15:03
@estebanzimanyi estebanzimanyi changed the base branch from feat/tnumber-numspan-tbox-posops to feat/tnumber-numspan-tbox-bbox-predicates April 25, 2026 15:03
@estebanzimanyi estebanzimanyi force-pushed the feat/tnumber-numspan-tbox-bbox-predicates branch from a0d024f to c74c29c Compare April 25, 2026 15:04
@estebanzimanyi estebanzimanyi force-pushed the feat/tspatial-direction-predicates branch from 503f913 to 76cf4da Compare April 25, 2026 15:04
@estebanzimanyi estebanzimanyi force-pushed the feat/tnumber-numspan-tbox-bbox-predicates branch from c74c29c to 546fd1b Compare April 25, 2026 15:07
@estebanzimanyi estebanzimanyi force-pushed the feat/tspatial-direction-predicates branch from 76cf4da to c1a429a Compare April 25, 2026 15:08
@estebanzimanyi estebanzimanyi force-pushed the feat/tnumber-numspan-tbox-bbox-predicates branch from 546fd1b to d4095f2 Compare April 25, 2026 15:16
@estebanzimanyi estebanzimanyi force-pushed the feat/tspatial-direction-predicates branch from c1a429a to f7345ea Compare April 25, 2026 15:17
Combines the tnumber numeric surface:

- Arithmetic operators: +, -, *, / for {tint, tfloat} × {scalar, tnumber}
  (24 registrations) using TemporalBinaryV<T> dispatch
- Unary functions: abs, derivative, degrees, radians (12 registrations)
  using TemporalUnary
- Distance: <-> for tnumber × tnumber and nad / nearestApproachDistance
  named functions

Each function family routes through one of the existing templated
helpers so each ScalarFunction body is a single-line lambda calling
the corresponding MEOS *_tnumber_tnumber / arithop_tnumber_number
entrypoint.
Combines temporal × {Temporal, tstzspan, tstzspanset, timestamptz} time-
domain predicates:

- Topological: @>, <@, &&, -|- (96 registrations across all temporal
  base types and time-shape pairs)
- Time-position: before, after, overbefore, overafter (named functions)

All wrappers route through TempTempBoolPred / TempBoxBoolPred<Span> /
BoxTempBoolPred<Span> with single-line lambdas dispatching to MEOS
*_temporal_temporal / *_tstzspan_temporal / *_temporal_tstzspan etc.
…, ge)

Adds ever/always comparison predicates between Temporal values and base
scalars across all 6 comparison ops × 6 base types (int, bigint, float,
text, geometry, geography where applicable).

Uses the EverAlwaysValTemp<T> templated helper. Functions are exposed as
named SQL forms (`ever_eq`, `always_eq`, `ever_ne`, `always_ne`,
`ever_lt`, `always_lt`, `ever_le`, `always_le`, `ever_gt`, `always_gt`,
`ever_ge`, `always_ge`) — DuckDB's parser does not accept the MobilityDB
`?=`, `%=`, `?<`, `%<`, etc. operator forms.
@estebanzimanyi estebanzimanyi force-pushed the feat/tnumber-numspan-tbox-bbox-predicates branch from d4095f2 to dbfa16e Compare April 27, 2026 12:55
@estebanzimanyi estebanzimanyi force-pushed the feat/tspatial-direction-predicates branch from f7345ea to 770b899 Compare April 27, 2026 12:56
Adds 8 ScalarFunction registrations for temporal similarity:

  frechetDistance(t1, t2)      -> DOUBLE
  discreteFrechet(t1, t2)      -> DOUBLE  (alias of frechetDistance)
  dynTimeWarp(t1, t2)          -> DOUBLE
  hausdorffDistance(t1, t2)    -> DOUBLE

For each: (tint, tint) and (tfloat, tfloat) registrations.

MEOS bindings:
  temporal_frechet_distance, temporal_dyntimewarp_distance,
  temporal_hausdorff_distance.

Implementation uses 3 thin wrappers + a single TempTempDoublePred
templated helper.

similarityPath (table-returning, alignment) is intentionally NOT
included — needs DuckDB TableFunction infrastructure (separate
follow-up tracked in PR #23).

Smoke test:
  SELECT frechetDistance(tfloat '[1@01-01, 2@01-02]', tfloat '[2@01-01, 3@01-02]');     -- 1.0
  SELECT discreteFrechet(tfloat '[1@01-01, 2@01-02]', tfloat '[2@01-01, 3@01-02]');     -- 1.0
  SELECT dynTimeWarp(tfloat '[1@01-01, 2@01-02]', tfloat '[2@01-01, 3@01-02]');         -- 2.0
  SELECT hausdorffDistance(tfloat '[1@01-01, 5@01-05]', tfloat '[3@01-01, 3@01-05]');   -- 2.0

Stacked on PR #35 (ever/always ordering).

Full suite passes (747 assertions, 13 test cases).
Combines topological (@>, <@, &&, -|-) and position (<<, >>, &<, &>)
predicates between tnumber and numspan/tbox, plus tnumber × tnumber
variants. Adds 96 topological + 40 position registrations using shared
TempBoxBoolPred<Span|TBox> / BoxTempBoolPred<Span|TBox> /
TempTempBoolPred helpers and DEFINE_NUMSPAN_*/DEFINE_TBOX_*/DEFINE_TNUM_*
generation macros.
@estebanzimanyi estebanzimanyi force-pushed the feat/tnumber-numspan-tbox-bbox-predicates branch from dbfa16e to 55250f4 Compare April 27, 2026 13:26
… pairs)

Adds ScalarFunction registrations for tgeompoint × {STBox, tgeompoint}
direction predicates wrapping MEOS *_tspatial_stbox / *_stbox_tspatial /
*_tspatial_tspatial. 36 registrations total:

- left/right/overleft/overright as <<, >>, &<, &> operators
- above/below/front/back/overabove/overbelow/overfront/overback as
  named functions (DuckDB parser rejects |>>, <<|, &</, /&> et al.)

Above/below operate on Y; left/right on X; front/back on Z (require
3D points or STBox with Z dimension).
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.

2 participants