From d29d4872a7c3cd2a77c8d27a99d0e5244af111e8 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Thu, 19 Nov 2026 09:43:24 +0100 Subject: [PATCH] Run the three abstract tests resolution 6 corrects beside the published ones Resolution 6 of the wiki page of Part 1 corrects three abstract tests of Annex A: A.20 validates the type against TemporalGeometrySequence and the member against geometrySequence, the schema its own Table A.7 cites; A.26 requests /velocity and A.27 /acceleration, the resources they are named for; and A.27 is run under the interpolations it names. ats_part1_corrected_test.go holds them as rows keyed by the identifier of the test each corrects, beside atsPart1, each naming the test that reads the answer it states, and checks that each corrects a test Annex A holds, that its request is routed and never to /distance, and that the test it names exists. The acceleration query resolves the geometry as the other queries do, reads its interpolation with interp, and states why that interpolation has no acceleration curve: Linear, Step, Discrete, and a single instant. interp joins the generated featureFunctions, so the catalog states it over 21 of the 23 temporal types and the query is refused for a collection of a type MobilityDB states no interp over; catalog_gen.go is regenerated from the catalog of MobilityDB master 843bec5d09. Witness. The query answered 501 before reading anything, so a Step or a Discrete geometry received the reason of a Linear one, and the acceleration of a collection, feature or geometry that does not exist answered 501 where every other query answers 404. Measured. go test passes; the corrected A.27 answers 501 with its own reason under each of Linear, Step, Discrete and None, 500 for a name MEOS does not carry, and 404 for the acceleration of a geometry the feature does not hold. --- ats_part1_corrected_test.go | 189 +++++++++++++++++++++++++++++++++++ ats_tpgeometry_query_test.go | 10 +- catalog_gen.go | 42 ++++---- main.go | 44 ++++++-- tools/codegen/main.go | 2 +- 5 files changed, 256 insertions(+), 31 deletions(-) create mode 100644 ats_part1_corrected_test.go diff --git a/ats_part1_corrected_test.go b/ats_part1_corrected_test.go new file mode 100644 index 0000000..e813df5 --- /dev/null +++ b/ats_part1_corrected_test.go @@ -0,0 +1,189 @@ +// The three abstract tests of Annex A as resolution 6 of the wiki page +// "Implementing OGC API — Moving Features in MobilityDB" corrects them, as +// executable rows beside the published ones in atsPart1. +// +// A published row is read as the standard writes it; a corrected row is read as +// the candidate resolution offered to the Standards Working Group writes it, and +// is discharged by the answer that corrected test method states. Each corrected +// row keeps the identifier of the abstract test it corrects, so the two readings +// of one test sit side by side and a correction never stands for a test Annex A +// does not hold. +// +// ⛔ A CORRECTED ROW IS EVIDENCE FOR THE RESOLUTION, NOT A CHANGE TO THE CLAIM. +// Conformance is still judged by atsPart1; these rows show the corrected methods +// can be run against an implementation and what it answers to them. +package main + +import ( + "bytes" + "encoding/json" + "net/http/httptest" + "os" + "path/filepath" + "strings" + "testing" +) + +// atsCorrection is one abstract test of Annex A as resolution 6 corrects it. +type atsCorrection struct { + id string // the identifier of the abstract test it corrects, a row of atsPart1 + method, path string // the request the corrected test method issues, with sample identifiers + purpose string // the corrected test purpose, abridged + dischargedBy string // the test that reads the answer it states +} + +// atsPart1Corrected holds the corrections of resolution 6: A.20 validated against +// the schema its own Table A.7 cites, and A.26 and A.27 issuing the request for +// the resource each is named for, A.27 under each interpolation it names. +var atsPart1Corrected = []atsCorrection{ + {"/conf/movingfeatures/tgsequence-get-success", "GET", "/collections/ships/items/1/tgsequence", + "type is TemporalGeometrySequence and geometrySequence holds TemporalPrimitiveGeometry items", + "TestATSTGSequenceGetSuccess"}, + {"/conf/movingfeatures/tpgeometry-query-velocity", "GET", "/collections/ships/items/1/tgsequence/1/velocity", + "a Velocity query at /velocity returns a TReal time-to-velocity curve", + "TestATSTPGeometryQueryDistanceAndVelocity"}, + {"/conf/movingfeatures/tpgeometry-query-acceleration", "GET", "/collections/ships/items/1/tgsequence/1/acceleration", + "an Acceleration query at /acceleration returns a TReal curve under an interpolation where one exists, " + + "and states why none exists under every other", + "TestATSCorrectedAccelerationByInterpolation"}, +} + +// Every corrected row corrects an abstract test Annex A holds, once. +func TestATSCorrectedRowsCorrectAnnexA(t *testing.T) { + inAnnexA := map[string]bool{} + for _, a := range atsPart1 { + inAnnexA[a.id] = true + } + seen := map[string]bool{} + for _, c := range atsPart1Corrected { + if !inAnnexA[c.id] { + t.Errorf("%s corrects no abstract test of Annex A", c.id) + } + if seen[c.id] { + t.Errorf("%s is corrected twice", c.id) + } + seen[c.id] = true + } + if len(atsPart1Corrected) != 3 { + t.Errorf("resolution 6 corrects 3 abstract tests (A.20, A.26, A.27); the registry holds %d", + len(atsPart1Corrected)) + } +} + +// The request each corrected method issues is one the service routes, and the +// routing pattern names the resource the test is named for rather than standing +// in for it: the velocity and acceleration requests reach the query route with +// their own query type, never /distance. +func TestATSCorrectedRoutes(t *testing.T) { + mux := newMux() + for _, c := range atsPart1Corrected { + req := httptest.NewRequest(c.method, "http://mfapi"+c.path, nil) + _, pattern := mux.Handler(req) + if pattern == "" { + t.Errorf("%s: %s %s is not routed", c.id, c.method, c.path) + continue + } + if strings.HasSuffix(c.path, "/distance") { + t.Errorf("%s: the corrected method still requests /distance", c.id) + } + } +} + +// Every corrected row names a test that a test file declares, as +// #TestATSEveryAnsweredRowIsDischarged holds every published row stating a response. +func TestATSCorrectedRowsAreDischarged(t *testing.T) { + files, err := filepath.Glob("*_test.go") + if err != nil { + t.Fatal(err) + } + var src []byte + for _, f := range files { + b, err := os.ReadFile(f) + if err != nil { + t.Fatal(err) + } + src = append(src, b...) + } + for _, c := range atsPart1Corrected { + if c.dischargedBy == "" { + t.Errorf("%s names no test that reads its answer", c.id) + continue + } + if !bytes.Contains(src, []byte("func "+c.dischargedBy+"(")) { + t.Errorf("%s names %s, which no test file declares", c.id, c.dischargedBy) + } + } +} + +// The corrected A.27, under each interpolation MobilityDB carries. None of them +// makes acceleration a curve, so each answers 501 with the reason for that +// interpolation; the standard's Quadratic and Cubic, under which the quantity is +// a curve, are no interpolation MEOS names, so no geometry the service holds can +// reach the 200 branch, and accelerationNotDerivable covering every name MEOS +// carries is what this test pins. +func TestATSCorrectedAccelerationByInterpolation(t *testing.T) { + for _, c := range []struct { + interp string + says []string + }{ + {"Linear", []string{"derivab", "Step", "vertices"}}, + {"Step", []string{"derivab", "constant between its instants", "jumps"}}, + {"Discrete", []string{"derivab", "at its instants alone"}}, + {"None", []string{"derivab", "single instant"}}, + } { + t.Run(c.interp, func(t *testing.T) { + withBackend(atsQueryBackendInterp(c.interp), func() { + rec := atsQuery(t, "acceleration") + if rec.Code != 501 { + t.Fatalf("status = %d, want 501 (body %s)", rec.Code, rec.Body.String()) + } + var e struct { + Description string `json:"description"` + } + if err := json.Unmarshal(rec.Body.Bytes(), &e); err != nil { + t.Fatal(err) + } + for _, want := range c.says { + if !strings.Contains(e.Description, want) { + t.Errorf("the 501 for a %s geometry does not say %q: %s", c.interp, want, e.Description) + } + } + }) + }) + } + if len(accelerationNotDerivable) != 4 { + t.Errorf("accelerationNotDerivable states %d interpolations; MEOS names 4 (None, Discrete, Step, Linear)", + len(accelerationNotDerivable)) + } +} + +// An interpolation MEOS does not name is an error of the service, not a 501 +// stating a reason nobody wrote. +func TestATSCorrectedAccelerationUnknownInterpolation(t *testing.T) { + withBackend(atsQueryBackendInterp("Cubic"), func() { + if rec := atsQuery(t, "acceleration"); rec.Code != 500 { + t.Errorf("an interpolation MEOS does not name answers %d, want 500", rec.Code) + } + }) +} + +// The acceleration of a geometry the service does not hold is 404, as for the +// other queries: the 501 states why an existing geometry has no acceleration, and +// answering it for a feature that does not exist would state that of nothing. +func TestATSCorrectedAccelerationOfNothingIsNotFound(t *testing.T) { + f := atsCollectionsBackend() + f.answers = append(f.answers, fakeAnswer{match: "SELECT numSequences(", rows: [][]any{{1}}}) + withBackend(f, func() { + req := httptest.NewRequest("GET", "/collections/ships/items/1/tgsequence/7/acceleration", nil) + req.SetPathValue("cid", "ships") + req.SetPathValue("fid", "1") + req.SetPathValue("tgid", "7") + req.SetPathValue("qtype", "acceleration") + rec := httptest.NewRecorder() + tgSequenceQuery(rec, req) + if rec.Code != 404 { + t.Errorf("the acceleration of temporal geometry #7 of a feature holding 1 answers %d, want 404 (%s)", + rec.Code, rec.Body.String()) + } + }) +} diff --git a/ats_tpgeometry_query_test.go b/ats_tpgeometry_query_test.go index deb081f..ad7184c 100644 --- a/ats_tpgeometry_query_test.go +++ b/ats_tpgeometry_query_test.go @@ -28,14 +28,22 @@ import ( ) // atsQueryBackend answers what tgSequenceQuery reads, with an MF-JSON moving -// float standing in for the derived curve MobilityDB computes. +// float standing in for the derived curve MobilityDB computes, over a linearly +// interpolated temporal primitive geometry. func atsQueryBackend() *fakeBackend { + return atsQueryBackendInterp("Linear") +} + +// atsQueryBackendInterp is #atsQueryBackend over a temporal primitive geometry +// whose interpolation interp() answers as interp. +func atsQueryBackendInterp(interp string) *fakeBackend { const mffloat = `{"type":"MovingFloat","datetimes":["2026-01-01T00:00:00+00","2026-01-01T00:10:00+00"],` + `"values":[0,1234.5],"interpolation":"Linear"}` f := atsCollectionsBackend() f.answers = append(f.answers, fakeAnswer{match: "SELECT numSequences(", rows: [][]any{{1}}}, fakeAnswer{match: "SELECT asMFJSON(", rows: [][]any{{mffloat}}}, + fakeAnswer{match: "SELECT interp(", rows: [][]any{{interp}}}, ) return f } diff --git a/catalog_gen.go b/catalog_gen.go index c5ef189..4146d55 100644 --- a/catalog_gen.go +++ b/catalog_gen.go @@ -30,29 +30,29 @@ type TemporalType struct { // temporalTypes is every temporal type MEOS declares, ordered by name. var temporalTypes = []TemporalType{ - {Name: "tbigint", Base: "int8", Box: "tbox", MFJSON: "MovingBigInteger", Spatial: false, Number: true, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "tbigintFromMFJSON", "tbox", "timeSpan", "tsample"}}, - {Name: "tbool", Base: "bool", Box: "tstzspan", MFJSON: "MovingBoolean", Spatial: false, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "tboolFromMFJSON", "timeSpan", "tsample"}}, - {Name: "tcbuffer", Base: "cbuffer", Box: "stbox", MFJSON: "MovingCircularBuffer", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "eIntersects", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "stbox", "tcbufferFromMFJSON", "timeSpan", "transform", "tsample"}}, + {Name: "tbigint", Base: "int8", Box: "tbox", MFJSON: "MovingBigInteger", Spatial: false, Number: true, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "tbigintFromMFJSON", "tbox", "timeSpan", "tsample"}}, + {Name: "tbool", Base: "bool", Box: "tstzspan", MFJSON: "MovingBoolean", Spatial: false, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "tboolFromMFJSON", "timeSpan", "tsample"}}, + {Name: "tcbuffer", Base: "cbuffer", Box: "stbox", MFJSON: "MovingCircularBuffer", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "eIntersects", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "stbox", "tcbufferFromMFJSON", "timeSpan", "transform", "tsample"}}, {Name: "tdouble2", Base: "double2", Box: "tstzspan", MFJSON: "", Spatial: false, Number: false, Linear: true, Funcs: []string(nil)}, {Name: "tdouble3", Base: "double3", Box: "tstzspan", MFJSON: "", Spatial: false, Number: false, Linear: true, Funcs: []string(nil)}, {Name: "tdouble4", Base: "double4", Box: "tstzspan", MFJSON: "", Spatial: false, Number: false, Linear: true, Funcs: []string(nil)}, - {Name: "tfloat", Base: "float8", Box: "tbox", MFJSON: "MovingFloat", Spatial: false, Number: true, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "tbox", "tfloatFromMFJSON", "timeSpan", "tsample"}}, - {Name: "tgeogpoint", Base: "geography", Box: "stbox", MFJSON: "MovingPoint", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", "deleteTime", "eIntersects", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "speed", "stbox", "tgeogpointFromMFJSON", "timeSpan", "trajectory", "transform", "tsample"}}, - {Name: "tgeography", Base: "geography", Box: "stbox", MFJSON: "MovingGeometry", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "eIntersects", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "stbox", "tgeographyFromMFJSON", "timeSpan", "transform", "tsample"}}, - {Name: "tgeometry", Base: "geometry", Box: "stbox", MFJSON: "MovingGeometry", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "eIntersects", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "stbox", "tgeometryFromMFJSON", "timeSpan", "transform", "tsample"}}, - {Name: "tgeompoint", Base: "geometry", Box: "stbox", MFJSON: "MovingPoint", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", "deleteTime", "eIntersects", "extent", "getTime", "merge", "numInstants", "numSequences", "rasterTileValue", "rasterValue", "sequenceN", "setSRID", "speed", "stbox", "tgeompointFromMFJSON", "timeSpan", "trajectory", "transform", "tsample"}}, - {Name: "th3index", Base: "h3index", Box: "stbox", MFJSON: "MovingH3Index", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "stbox", "th3indexFromMFJSON", "timeSpan", "tsample"}}, - {Name: "tint", Base: "int4", Box: "tbox", MFJSON: "MovingInteger", Spatial: false, Number: true, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "tbox", "timeSpan", "tintFromMFJSON", "tsample"}}, - {Name: "tjsonb", Base: "jsonb", Box: "tstzspan", MFJSON: "MovingJsonb", Spatial: false, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "timeSpan", "tjsonbFromMFJSON", "tsample"}}, - {Name: "tnpoint", Base: "npoint", Box: "stbox", MFJSON: "MovingNetworkPoint", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "speed", "stbox", "timeSpan", "tnpointFromMFJSON", "trajectory", "tsample"}}, - {Name: "tpcpatch", Base: "pcpatch", Box: "tpcbox", MFJSON: "MovingPCPatch", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "timeSpan", "tpcbox", "tpcpatchFromMFJSON", "tsample"}}, - {Name: "tpcpoint", Base: "pcpoint", Box: "tpcbox", MFJSON: "MovingPCPoint", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "timeSpan", "tpcbox", "tpcpointFromMFJSON", "tsample"}}, - {Name: "tpose", Base: "pose", Box: "stbox", MFJSON: "MovingPose", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "speed", "stbox", "timeSpan", "tposeFromMFJSON", "trajectory", "transform", "tsample"}}, - {Name: "tposechain", Base: "posechain", Box: "stbox", MFJSON: "MovingPoseChain", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "eIntersects", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "stbox", "timeSpan", "tposechainFromMFJSON", "transform", "tsample"}}, - {Name: "tquadbin", Base: "quadbin", Box: "stbox", MFJSON: "MovingQuadbin", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "stbox", "timeSpan", "tquadbinFromMFJSON", "tsample"}}, - {Name: "trgeometry", Base: "pose", Box: "stbox", MFJSON: "MovingRigidGeometry", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", "deleteTime", "eIntersects", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "speed", "stbox", "timeSpan", "transform", "trgeometryFromMFJSON"}}, - {Name: "ts2cell", Base: "s2cell", Box: "stbox", MFJSON: "MovingS2Cell", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "stbox", "timeSpan", "ts2cellFromMFJSON", "tsample"}}, - {Name: "ttext", Base: "text", Box: "tstzspan", MFJSON: "MovingText", Spatial: false, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "merge", "numInstants", "numSequences", "sequenceN", "timeSpan", "tsample", "ttextFromMFJSON"}}, + {Name: "tfloat", Base: "float8", Box: "tbox", MFJSON: "MovingFloat", Spatial: false, Number: true, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "tbox", "tfloatFromMFJSON", "timeSpan", "tsample"}}, + {Name: "tgeogpoint", Base: "geography", Box: "stbox", MFJSON: "MovingPoint", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", "deleteTime", "eIntersects", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "speed", "stbox", "tgeogpointFromMFJSON", "timeSpan", "trajectory", "transform", "tsample"}}, + {Name: "tgeography", Base: "geography", Box: "stbox", MFJSON: "MovingGeometry", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "eIntersects", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "stbox", "tgeographyFromMFJSON", "timeSpan", "transform", "tsample"}}, + {Name: "tgeometry", Base: "geometry", Box: "stbox", MFJSON: "MovingGeometry", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "eIntersects", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "stbox", "tgeometryFromMFJSON", "timeSpan", "transform", "tsample"}}, + {Name: "tgeompoint", Base: "geometry", Box: "stbox", MFJSON: "MovingPoint", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", "deleteTime", "eIntersects", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "rasterTileValue", "rasterValue", "sequenceN", "setSRID", "speed", "stbox", "tgeompointFromMFJSON", "timeSpan", "trajectory", "transform", "tsample"}}, + {Name: "th3index", Base: "h3index", Box: "stbox", MFJSON: "MovingH3Index", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "stbox", "th3indexFromMFJSON", "timeSpan", "tsample"}}, + {Name: "tint", Base: "int4", Box: "tbox", MFJSON: "MovingInteger", Spatial: false, Number: true, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "tbox", "timeSpan", "tintFromMFJSON", "tsample"}}, + {Name: "tjsonb", Base: "jsonb", Box: "tstzspan", MFJSON: "MovingJsonb", Spatial: false, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "timeSpan", "tjsonbFromMFJSON", "tsample"}}, + {Name: "tnpoint", Base: "npoint", Box: "stbox", MFJSON: "MovingNetworkPoint", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "speed", "stbox", "timeSpan", "tnpointFromMFJSON", "trajectory", "tsample"}}, + {Name: "tpcpatch", Base: "pcpatch", Box: "tpcbox", MFJSON: "MovingPCPatch", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "timeSpan", "tpcbox", "tpcpatchFromMFJSON", "tsample"}}, + {Name: "tpcpoint", Base: "pcpoint", Box: "tpcbox", MFJSON: "MovingPCPoint", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "timeSpan", "tpcbox", "tpcpointFromMFJSON", "tsample"}}, + {Name: "tpose", Base: "pose", Box: "stbox", MFJSON: "MovingPose", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "speed", "stbox", "timeSpan", "tposeFromMFJSON", "trajectory", "transform", "tsample"}}, + {Name: "tposechain", Base: "posechain", Box: "stbox", MFJSON: "MovingPoseChain", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "eIntersects", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "stbox", "timeSpan", "tposechainFromMFJSON", "transform", "tsample"}}, + {Name: "tquadbin", Base: "quadbin", Box: "stbox", MFJSON: "MovingQuadbin", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "stbox", "timeSpan", "tquadbinFromMFJSON", "tsample"}}, + {Name: "trgeometry", Base: "pose", Box: "stbox", MFJSON: "MovingRigidGeometry", Spatial: true, Number: false, Linear: true, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", "deleteTime", "eIntersects", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "setSRID", "speed", "stbox", "timeSpan", "transform", "trgeometryFromMFJSON"}}, + {Name: "ts2cell", Base: "s2cell", Box: "stbox", MFJSON: "MovingS2Cell", Spatial: true, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "stbox", "timeSpan", "ts2cellFromMFJSON", "tsample"}}, + {Name: "ttext", Base: "text", Box: "tstzspan", MFJSON: "MovingText", Spatial: false, Number: false, Linear: false, Funcs: []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "deleteTime", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "sequenceN", "timeSpan", "tsample", "ttextFromMFJSON"}}, } // boxFunctions are, per bounding box type of a temporal type, the @@ -66,7 +66,7 @@ var boxFunctions = map[string][]string{ // featureFunctions are the SQL functions the tier applies to a feature's // temporal geometry, the set each TemporalType's Funcs is read from. -var featureFunctions = []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", "deleteTime", "eIntersects", "extent", "getTime", "merge", "numInstants", "numSequences", "rasterTileValue", "rasterValue", "sequenceN", "setSRID", "speed", "timeSpan", "trajectory", "transform", "tsample"} +var featureFunctions = []string{"appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", "deleteTime", "eIntersects", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "rasterTileValue", "rasterValue", "sequenceN", "setSRID", "speed", "timeSpan", "trajectory", "transform", "tsample"} // temporalTypeByName indexes temporalTypes by the MEOS type name. var temporalTypeByName = func() map[string]*TemporalType { diff --git a/main.go b/main.go index 780a228..7c57ebc 100644 --- a/main.go +++ b/main.go @@ -1187,18 +1187,28 @@ func tgSequence(w http.ResponseWriter, r *http.Request) { writeRaw(w, 200, ogcify(string(body))) } +// accelerationNotDerivable states, per interpolation interp() answers, why a +// temporal primitive geometry of that interpolation has no acceleration curve: +// MobilityDB interpolates a position as Discrete, Step or Linear, and under none +// of them is the second derivative of position a curve. The standard's Quadratic +// and Cubic, the motion curves under which it is, are no interpolation MEOS +// carries (MEOS_INTERPTYPE_NAMES). +var accelerationNotDerivable = map[string]string{ + "Linear": "acceleration is not derivable: linearly interpolated position gives a piecewise-constant (Step) speed, whose derivative is zero within each segment and undefined at the vertices", + "Step": "acceleration is not derivable: Step interpolated position is constant between its instants and jumps at each, so its velocity is zero between the instants and undefined at them", + "Discrete": "acceleration is not derivable: Discrete interpolated position is defined at its instants alone, so it has no derivative between them", + "None": "acceleration is not derivable: a position at a single instant has no derivative", +} + // tgSequenceQuery serves the OGC TemporalGeometry derived queries. distance and // velocity are exact MobilityDB functions; raster, a MobilityAPI query type, is -// the values the rasters of a raster collection give along it (#rasterQuery); acceleration is NOT_IMPLEMENTED -// because with linearly interpolated position the speed is piecewise-constant, -// so its derivative is zero within each segment and undefined at the vertices. +// the values the rasters of a raster collection give along it (#rasterQuery). +// acceleration is NOT_IMPLEMENTED for every interpolation MobilityDB carries, and +// the answer states why for the interpolation of the geometry asked for +// (#accelerationNotDerivable), once the geometry is found to exist. func tgSequenceQuery(w http.ResponseWriter, r *http.Request) { q := strings.ToLower(r.PathValue("qtype")) - if q == "acceleration" { - httpErr(w, 501, "acceleration is not derivable: linearly interpolated position gives a piecewise-constant (Step) speed, whose derivative is zero within each segment and undefined at the vertices") - return - } - if q != "velocity" && q != "distance" && q != "raster" { + if q != "velocity" && q != "distance" && q != "raster" && q != "acceleration" { httpErr(w, 404, "unknown query type: "+q) return } @@ -1235,6 +1245,24 @@ func tgSequenceQuery(w http.ResponseWriter, r *http.Request) { writeRasterQuery(w, r, tbl, tg) return } + if q == "acceleration" { + if typ := collectionType(r.Context(), r.PathValue("cid")); !typeHas(typ, "interp") { + httpErr(w, 400, "acceleration is not defined for a collection of "+typ+": MobilityDB states no interp over it") + return + } + var interp string + if err := db.QueryRow(r.Context(), "SELECT interp(sequenceN(trip, "+itoa(tg)+")) FROM "+ident(tbl)+" WHERE id=$1", fid).Scan(&interp); err != nil { + httpErr(w, 400, err.Error()) + return + } + reason, ok := accelerationNotDerivable[interp] + if !ok { + httpErr(w, 500, "interp answered "+interp+", which is no interpolation MEOS names") + return + } + httpErr(w, 501, reason) + return + } // The query is the function its expression applies to trip, defined for a // collection whose type MobilityDB states that function over. spec := tProps[q] diff --git a/tools/codegen/main.go b/tools/codegen/main.go index a1fee56..b81a40e 100644 --- a/tools/codegen/main.go +++ b/tools/codegen/main.go @@ -95,7 +95,7 @@ type serialization struct { // the functions the tier's SQL calls. var featureFunctions = []string{ "appendInstant", "asBinary", "asMFJSON", "atTime", "cumulativeLength", - "deleteTime", "eIntersects", "extent", "getTime", "merge", "numInstants", + "deleteTime", "eIntersects", "extent", "getTime", "interp", "merge", "numInstants", "numSequences", "rasterTileValue", "rasterValue", "sequenceN", "setSRID", "speed", "timeSpan", "trajectory", "transform", "tsample", }