fix: temporal_derivative reports value/day to match MobilityDB#46
fix: temporal_derivative reports value/day to match MobilityDB#46estebanzimanyi wants to merge 2 commits into
Conversation
MEOS's temporal_derivative returns slope in value/second (the denominator (inst2->t - inst1->t) / 1000000 converts microseconds to seconds). MobilityDB's SQL wrapper post-multiplies by 86400 to present derivative in value/day, but MobilityDuck called MEOS directly without that scaling — so: SELECT derivative(tfloat '[1@2000-01-01, 4@2000-01-04]'); returned 0.000011574... instead of 1.0. Multiplying the MEOS result by 86400 via mult_tfloat_float aligns MobilityDuck output with MobilityDB regression-test expectations.
The first commit on this branch wrapped temporal_derivative to multiply
by 86400 so derivative(tfloat) reports value/day matching MobilityDB.
That accidentally also scaled speed(tgeompoint) — both were registered
against the same wrapper. The existing test/sql/tgeompoint.test:588
expects speed in distance/second (the raw MEOS unit), so CI started
failing.
Split the wrapper: a shared static helper TemporalDerivativeCore takes
a scale_to_per_day flag. Temporal_derivative passes true; new
Tpoint_speed passes false. tgeompoint.cpp now registers speed(tgeompoint)
against Tpoint_speed.
Verified:
derivative(tfloat '[1@..,4@..]') -> 1 (value/day, MobilityDB)
speed(tgeompoint '{...}') -> 0.000016... (~sqrt(2)/86400, MEOS native)
test/sql/tgeompoint.test passes 148/148 locally.
|
Pushed a follow-up commit fixing CI failure on Root cause: the first commit wrapped Fix: split into a shared static helper Verified:
|
|
I checked against MobilityDB's latest implementation and I couldn't find the multiplication by 86400 (also defined as Current MobilityDuck implementation (before applying the commits in this PR) seems to already match the behavior of MobilityDB, for both MobilityDB: SELECT derivative(tfloat '[1@2000-01-01, 4@2000-01-04]');
-- Interp=Step;[0.000011574074074@2000-01-01 00:00:00+00, 0.000011574074074@2000-01-04 00:00:00+00]
SELECT round(derivative(tfloat '{[1@2000-01-01, 2@2000-01-02, 1@2000-01-03],[3@2000-01-04, 3@2000-01-05]}'), 6);
-- Interp=Step;{[0.000012@2000-01-01 00:00:00+00, 0.000012@2000-01-03 00:00:00+00], [0@2000-01-04 00:00:00+00, 0@2000-01-05 00:00:00+00]}
SELECT round(speed(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]'), 6);
-- Interp=Step;[0.000016@2000-01-01 00:00:00+00, 0.000016@2000-01-03 00:00:00+00]MobilityDuck: SELECT derivative(tfloat '[1@2000-01-01, 4@2000-01-04]');
-- Interp=Step;[0.000011574074074@2000-01-01 00:00:00+00, 0.000011574074074@2000-01-04 00:00:00+00]
SELECT round(derivative(tfloat '{[1@2000-01-01, 2@2000-01-02, 1@2000-01-03],[3@2000-01-04, 3@2000-01-05]}'), 6);
-- Interp=Step;{[0.000012@2000-01-01 00:00:00+00, 0.000012@2000-01-03 00:00:00+00], [0@2000-01-04 00:00:00+00, 0@2000-01-05 00:00:00+00]}
SELECT round(speed(tgeompoint '[Point(1 1)@2000-01-01, Point(2 2)@2000-01-02, Point(1 1)@2000-01-03]'), 6);
-- Interp=Step;[0.000016@2000-01-01 00:00:00+00, 0.000016@2000-01-03 00:00:00+00] |
|
@nhungoc1508 you're right — I checked against the local MobilityDB source and tests, and the premise of this PR is wrong. Verification:
So MobilityDB returns value/second — exactly what MobilityDuck returned before this PR. The two were already in agreement. Root cause of the original report: in PR #23, the parity test Closing this PR. The right follow-up is a small fix on the parity test in PR #23: update the Apologies for the noise — and thanks for catching this before merge. |
Summary
MEOS's `temporal_derivative` returns slope in value/second (`tsequence_derivative` divides the value-change by `(inst2->t - inst1->t) / 1000000` — microseconds → seconds). MobilityDB's SQL wrapper post-multiplies the MEOS result by 86400 to present the derivative in value/day. MobilityDuck was calling MEOS directly without that scaling, so the result diverged from MobilityDB by a factor of 86400.
Reproducer
```sql
SELECT derivative(tfloat '[1@2000-01-01, 4@2000-01-04]');
-- before fix:
-- Interp=Step;[0.000011574074074@2000-01-01, 0.000011574074074@2000-01-04]
-- after fix (matches MobilityDB):
-- Interp=Step;[1@2000-01-01, 1@2000-01-04]
```
Fix
Wrapper-side: scale the MEOS result by 86400 via `mult_tfloat_float` after `temporal_derivative` returns. Three lines in `Temporal_derivative`.
Coordination with MEOS / MobilityDB
The clean long-term fix would be a non-breaking MEOS API like `temporal_derivative_scaled(temp, double scale)` so callers can pick their preferred time unit without each downstream wrapper re-scaling. Filed a comment on MobilityDB PR #782 (which is already touching `tsequence_derivative`) to coordinate. This MobilityDuck-side fix is a workaround until the MEOS API question is settled.
Surfaced by parity work in PR #23 (026_tnumber_mathfuncs.test). The skip block there can be removed in a follow-up once this lands.
Test plan