Skip to content

feat(bindings): tnumber distance — <->, nad, nearestApproachDistance#31

Closed
estebanzimanyi wants to merge 1 commit into
feat/tnumber-unaryfrom
feat/tnumber-distance
Closed

feat(bindings): tnumber distance — <->, nad, nearestApproachDistance#31
estebanzimanyi wants to merge 1 commit into
feat/tnumber-unaryfrom
feat/tnumber-distance

Conversation

@estebanzimanyi

Copy link
Copy Markdown
Member

Summary

Adds 10 ScalarFunction registrations for tnumber distance:

SQL MEOS Returns
tint <-> tint tdistance_tnumber_tnumber tint
tfloat <-> tfloat tdistance_tnumber_tnumber tfloat
nad(tint, INTEGER) nad_tint_int INTEGER
nad(tint, tint) nad_tint_tint INTEGER
nad(tfloat, DOUBLE) nad_tfloat_float DOUBLE
nad(tfloat, tfloat) nad_tfloat_tfloat DOUBLE
nearestApproachDistance(...) (4 aliases for the nad set) (matching)

Implementation uses templated helpers from PR #27 plus per-call BinaryExecutor blocks for the scalar-returning nad variants.

Intentionally NOT registered (documented MEOS-side issue)

Value-distance variants <-> for (tint, INTEGER) / (INTEGER, tint) / (tfloat, DOUBLE) / (DOUBLE, tfloat). In the installed MEOS library, tdistance_tfloat_float / tdistance_tint_int return the temporal's own value at each instant rather than the |t.value - v| absolute difference. Smoke verified:

SELECT 5.0::DOUBLE <-> tfloat '5.0@2000-01-01';   -- returns 5.0, expected 0.0
SELECT 100.0::DOUBLE <-> tfloat '2.5@2000-01-01'; -- returns 2.5, expected 97.5

The wrapper implementations stay in the header and .cpp so the registrations can be uncommented in src/temporal/temporal.cpp once the MEOS upstream is fixed.

Smoke test (working surface)

SELECT tfloat '[1@01-01, 5@01-05]' <-> tfloat '[3@01-01, 3@01-05]';
-- [2@01-01, 0@01-03, 2@01-05]   (linear-interpolated, touches 0 at midpoint)

SELECT nad(tint '[1@01-01, 5@01-05]', 3);
-- 0

SELECT nad(tfloat '[1@01-01, 5@01-05]', tfloat '[3@01-01, 3@01-05]');
-- 0.0

Test plan

Dependencies

Stacked on PR #30 (tnumber unary). Merge order: #27#29#30 → this.

…tApproachDistance

Adds 10 ScalarFunction registrations:

  tint   <-> tint    -> tint        (MEOS: tdistance_tnumber_tnumber)
  tfloat <-> tfloat  -> tfloat

  nad(tint, INTEGER)             -> INTEGER  (MEOS: nad_tint_int)
  nad(tint, tint)                -> INTEGER  (MEOS: nad_tint_tint)
  nad(tfloat, DOUBLE)            -> DOUBLE   (MEOS: nad_tfloat_float)
  nad(tfloat, tfloat)            -> DOUBLE   (MEOS: nad_tfloat_tfloat)
  nearestApproachDistance(...)   -> ...      (4 aliases for the nad set)

Implementation uses templated helpers from PR #27 plus per-call
BinaryExecutor blocks for the scalar-returning nad variants.

Value-distance variants `<->` for (tint, INTEGER) / (INTEGER, tint) /
(tfloat, DOUBLE) / (DOUBLE, tfloat) are intentionally NOT registered:
in the installed MEOS library, tdistance_tfloat_float / tint_int
return the temporal's own value at each instant rather than the
|t.value - v| absolute difference. Smoke verified:
  SELECT 5.0::DOUBLE <-> tfloat '5.0@2000-01-01';
    -> 5.0 (expected 0.0)
  SELECT 100.0::DOUBLE <-> tfloat '2.5@2000-01-01';
    -> 2.5 (expected 97.5)
The Tdistance_*_value/Tdistance_value_* implementations stay in the
header and .cpp so the registrations can be uncommented in
src/temporal/temporal.cpp once the MEOS upstream is fixed.

Smoke (working):
  SELECT tfloat '[1@01-01, 5@01-05]' <-> tfloat '[3@01-01, 3@01-05]';
    -> [2@01-01, 0@01-03, 2@01-05]
  SELECT nad(tint '[1@01-01, 5@01-05]', 3);
    -> 0
  SELECT nad(tfloat '[1@01-01, 5@01-05]', tfloat '[3@01-01, 3@01-05]');
    -> 0.0

Stacked on PR #30 (tnumber unary).

Full suite passes (747 assertions, 13 test cases).
@estebanzimanyi

Copy link
Copy Markdown
Member Author

Consolidated into #43 (tnumber numeric functions — arithmetic + unary + distance).

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