diff --git a/src/test/java/org/mobilitydb/spark/GeneratedSqlSurfaceTest.java b/src/test/java/org/mobilitydb/spark/GeneratedSqlSurfaceTest.java index 42e64066..995bf95a 100644 --- a/src/test/java/org/mobilitydb/spark/GeneratedSqlSurfaceTest.java +++ b/src/test/java/org/mobilitydb/spark/GeneratedSqlSurfaceTest.java @@ -465,4 +465,26 @@ void peakCountOverMergedPieces() { + "(SELECT k, tgeompointFromText(s) AS g FROM VALUES " + rows + " AS t(k, s)) " + "WHERE k = 1 GROUP BY k)")); } + + @Test + void aRasterDerivedByArithmeticIsReadAlongATrip() { + // A 3x3 32BF depth raster in SRID 4326 holding 10, 20, 30 / 40, 50, 60 / 70, 80, 90, + // as PostGIS's ST_AsHexWKB writes it. + String depth = "rasterFromHexWKB('0100000100000000000000F03F000000000000F0BF0000000000000000" + + "000000000000084000000000000000000000000000000000E6100000030003000A000000000000204100" + + "00A0410000F04100002042000048420000704200008C420000A0420000B442')"; + String trip = "tgeompointFromText('SRID=4326;[POINT(0.5 2.5)@2001-01-01, " + + "POINT(2.5 2.5)@2001-01-02, POINT(0.5 0.5)@2001-01-03]')"; + // The clearance of a vessel of draught 8.5, as MobilityDB answers rasterValue(trip, + // depth - 8.5) in its raster regression test. + assertEquals("Interp=Step;[1.5@2001-01-01 00:00:00+00, 11.5@2001-01-01 06:00:00+00, " + + "21.5@2001-01-01 18:00:00+00, 41.5@2001-01-02 06:00:00+00, " + + "61.5@2001-01-02 18:00:00+00, 61.5@2001-01-03 00:00:00+00]", + scalar("SELECT asText(rasterValue(" + trip + ", rasterSub(" + depth + ", 8.5)))")); + String read = (String) scalar("SELECT asText(rasterValue(" + trip + ", " + depth + "))"); + assertEquals(read, scalar("SELECT asText(rasterValue(" + trip + ", rasterDiv(rasterAdd(" + + depth + ", " + depth + "), 2.0)))")); + assertEquals(read, scalar("SELECT asText(rasterValue(" + trip + ", rasterDiv(rasterMul(" + + depth + ", " + depth + "), " + depth + ")))")); + } }