From 98a92903670d67e5fa7e4815f999a29d8541a581 Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Wed, 30 Sep 2026 15:38:16 +0200 Subject: [PATCH] Build the value set of a temporal with the set constructor of its base type The value_set of TFloat, TText, TGeomPoint and TGeogPoint passes the array the MEOS tfloat_values, ttext_values or tgeo_values returns, and its count, to floatset_make, textset_make or geoset_make, and wraps the set in FloatSet, TextSet, GeometrySet or GeographySet. The spatial ones round the set to their precision argument with set_round. Witness. Each appended to a StringBuilder declared null, so each threw a NullPointerException on any input. TText returned an anonymous Set whose inner was the text array itself, and the spatial ones rebuilt their set from point text, which carries no SRID. Measured. Against the catalog and libmeos of MobilityDB 8a23781e4c with MEOS-API 8dddf59, the testValueSet tests of TFloatTest, TTextTest, TGeomPointTest and TGeogPointTest read {1.5, 2.5}, {"AAA", "BBB"}, SRID=3812;{"POINT(1.12 1)", "POINT(2 2)"} from a point at 1.123456 rounded to 2 digits, and SRID=4326;{"POINT(1 1)", "POINT(2 2)"}. The build succeeds and the suites run 106 and 1,810 tests, all passing. Why. MEOS builds a set from the values of its base type, and a set built that way holds every value exactly, the SRID included. --- .../main/java/types/basic/tfloat/TFloat.java | 21 ++------- .../types/basic/tpoint/tgeog/TGeogPoint.java | 23 ++------- .../types/basic/tpoint/tgeom/TGeomPoint.java | 23 ++------- .../main/java/types/basic/ttext/TText.java | 47 ++----------------- .../src/test/java/basic/TFloatTest.java | 8 +++- .../src/test/java/basic/TGeogPointTest.java | 11 ++++- .../src/test/java/basic/TGeomPointTest.java | 10 ++++ jmeos-core/src/test/java/basic/TTextTest.java | 8 ++++ 8 files changed, 50 insertions(+), 101 deletions(-) diff --git a/jmeos-core/src/main/java/types/basic/tfloat/TFloat.java b/jmeos-core/src/main/java/types/basic/tfloat/TFloat.java index a64bf7a4e..bdf6b7ee2 100644 --- a/jmeos-core/src/main/java/types/basic/tfloat/TFloat.java +++ b/jmeos-core/src/main/java/types/basic/tfloat/TFloat.java @@ -235,24 +235,9 @@ default float end_value(){ tint_values */ default FloatSet value_set(){ - // Create a JNR-FFI runtime instance - Runtime runtime = Runtime.getSystemRuntime(); - // Allocate memory for an integer (4 bytes) but do not set a value - Pointer intPointer = Memory.allocate(runtime, 4); - Pointer resPointer = GeneratedFunctions.tfloat_values(this.getNumberInner(), intPointer); - StringBuilder sb = null; - sb.append("{"); - int count= intPointer.getInt(0); - for (int i=0;i pointList= new ArrayList<>(); - int count= intPointer.getInt(0); - StringBuilder sb = null; - sb.append("{"); - for(int i=0;i pointList= new ArrayList<>(); - int count= intPointer.getInt(0); - StringBuilder sb = null; - sb.append("{"); - for(int i=0;i value_set(){ - // Create a JNR-FFI runtime instance - Runtime runtime = Runtime.getSystemRuntime(); - // Allocate memory for an integer (4 bytes) but do not set a value - Pointer intPointer = Memory.allocate(runtime, 4); - Pointer resPointer= GeneratedFunctions.ttext_values(this.getTextInner(), intPointer); - StringBuilder sb= null; - sb.append("{"); - int count= intPointer.getInt(0); - for(int i=0; i() { - @Override - public Pointer get_inner() { - return resPointer; - } - - @Override - public Pointer createInner(Pointer inner) { - return inner; - } - - @Override - public Pointer createStringInner(String str) { - return GeneratedFunctions.ttext_in(str); - } - - @Override - public String start_element() throws ParseException { - return GeneratedFunctions.text_to_cstring(GeneratedFunctions.ttext_min_value(getTextInner())); - } - - @Override - public String end_element() throws ParseException { - return GeneratedFunctions.text_to_cstring(GeneratedFunctions.ttext_max_value(getTextInner())); - } - }; + Pointer countPointer = Memory.allocate(Runtime.getSystemRuntime(), Integer.BYTES); + Pointer values = GeneratedFunctions.ttext_values(this.getTextInner(), countPointer); + return new TextSet(GeneratedFunctions.textset_make(values, countPointer.getInt(0))); } /** diff --git a/jmeos-core/src/test/java/basic/TFloatTest.java b/jmeos-core/src/test/java/basic/TFloatTest.java index 30db5c132..71fec5b0c 100644 --- a/jmeos-core/src/test/java/basic/TFloatTest.java +++ b/jmeos-core/src/test/java/basic/TFloatTest.java @@ -889,4 +889,10 @@ void testEverGreater(Temporal source, String type, float arg, boolean expected) } -} \ No newline at end of file + @org.junit.jupiter.api.Test + void testValueSet() { + GeneratedFunctions.meos_initialize_timezone("UTC"); + assertEquals("{1.5, 2.5}", GeneratedFunctions.set_out(new TFloatSeq( + "[1.5@2019-09-01, 2.5@2019-09-02, 1.5@2019-09-03]").value_set().get_inner(), 15)); + } +} diff --git a/jmeos-core/src/test/java/basic/TGeogPointTest.java b/jmeos-core/src/test/java/basic/TGeogPointTest.java index bfc338751..2babf689c 100644 --- a/jmeos-core/src/test/java/basic/TGeogPointTest.java +++ b/jmeos-core/src/test/java/basic/TGeogPointTest.java @@ -1086,4 +1086,13 @@ void testAppendSequence(Temporal source, String type, TGeogPointSeq tgeoseq, Tem } -} \ No newline at end of file + + + @org.junit.jupiter.api.Test + void testValueSet() throws ParseException { + GeneratedFunctions.meos_initialize_timezone("UTC"); + TGeogPointSeq source = new TGeogPointSeq("[Point(1 1)@2019-09-01, Point(2 2)@2019-09-02]"); + assertEquals("SRID=4326;{\"POINT(1 1)\", \"POINT(2 2)\"}", + GeneratedFunctions.spatialset_as_ewkt(source.value_set(6).get_inner(), 6)); + } +} diff --git a/jmeos-core/src/test/java/basic/TGeomPointTest.java b/jmeos-core/src/test/java/basic/TGeomPointTest.java index 76fcc9b42..fe98e563c 100644 --- a/jmeos-core/src/test/java/basic/TGeomPointTest.java +++ b/jmeos-core/src/test/java/basic/TGeomPointTest.java @@ -1146,4 +1146,14 @@ void testValuesStboxesMakeSimple() { assertEquals("[POINT(2 0)@2019-09-03 00:00:00+00, POINT(0 2)@2019-09-04 00:00:00+00]", simple.get(1).to_string()); } + + + @org.junit.jupiter.api.Test + void testValueSet() throws ParseException { + GeneratedFunctions.meos_initialize_timezone("UTC"); + TGeomPointSeq source = new TGeomPointSeq( + "SRID=3812;[Point(1.123456 1)@2019-09-01, Point(2 2)@2019-09-02, Point(1.123456 1)@2019-09-03]"); + assertEquals("SRID=3812;{\"POINT(1.12 1)\", \"POINT(2 2)\"}", + GeneratedFunctions.spatialset_as_ewkt(source.value_set(2).get_inner(), 6)); + } } diff --git a/jmeos-core/src/test/java/basic/TTextTest.java b/jmeos-core/src/test/java/basic/TTextTest.java index 9a33a0d4a..5dd531b88 100644 --- a/jmeos-core/src/test/java/basic/TTextTest.java +++ b/jmeos-core/src/test/java/basic/TTextTest.java @@ -603,4 +603,12 @@ public void testAppendSeq(Temporal base, TSequence base2, Temporal tseq, String assertEquals(((TTextSeqSet)base.append_sequence(base2)).to_string(), ((TTextSeqSet) tseq).to_string()); } } + + + @org.junit.jupiter.api.Test + void testValueSet() { + GeneratedFunctions.meos_initialize_timezone("UTC"); + assertEquals("{\"AAA\", \"BBB\"}", + new TTextSeq("[BBB@2019-09-01, AAA@2019-09-02, BBB@2019-09-03]").value_set().toString()); + } }