From a8062ba66e8c019e63a023b069025e5b67dcf589 Mon Sep 17 00:00:00 2001 From: Martin Traverso Date: Wed, 30 Aug 2023 09:26:04 -0700 Subject: [PATCH] Fix NPE for spatial left join The failure started happening with the update to fastutil 8.5.12 in 5e9bb46e0a48fe94c1a7e0f9b726e1020a94c85b --- .../io/trino/operator/PagesRTreeIndex.java | 2 +- .../plugin/geospatial/TestSpatialJoins.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/trino-main/src/main/java/io/trino/operator/PagesRTreeIndex.java b/core/trino-main/src/main/java/io/trino/operator/PagesRTreeIndex.java index eadd8ae1cad7..37ea2290c91f 100644 --- a/core/trino-main/src/main/java/io/trino/operator/PagesRTreeIndex.java +++ b/core/trino-main/src/main/java/io/trino/operator/PagesRTreeIndex.java @@ -174,7 +174,7 @@ public int[] findJoinPositions(int probePosition, Page probe, int probeGeometryC } }); - return matchingPositions.toIntArray(null); + return matchingPositions.toIntArray(); } private boolean testReferencePoint(Envelope probeEnvelope, OGCGeometry buildGeometry, int partition) diff --git a/plugin/trino-geospatial/src/test/java/io/trino/plugin/geospatial/TestSpatialJoins.java b/plugin/trino-geospatial/src/test/java/io/trino/plugin/geospatial/TestSpatialJoins.java index 8af1726a43b0..95e2334f0aa2 100644 --- a/plugin/trino-geospatial/src/test/java/io/trino/plugin/geospatial/TestSpatialJoins.java +++ b/plugin/trino-geospatial/src/test/java/io/trino/plugin/geospatial/TestSpatialJoins.java @@ -18,6 +18,7 @@ import io.trino.plugin.hive.metastore.Database; import io.trino.plugin.hive.metastore.HiveMetastore; import io.trino.spi.security.PrincipalType; +import io.trino.sql.query.QueryAssertions; import io.trino.testing.AbstractTestQueryFramework; import io.trino.testing.DistributedQueryRunner; import org.testng.annotations.Test; @@ -29,6 +30,7 @@ import static io.trino.plugin.hive.metastore.file.TestingFileHiveMetastore.createTestingFileHiveMetastore; import static io.trino.testing.TestingSession.testSessionBuilder; import static java.lang.String.format; +import static org.assertj.core.api.Assertions.assertThat; public class TestSpatialJoins extends AbstractTestQueryFramework @@ -399,4 +401,21 @@ public void testSpatialJoinOverFullJoinWithOrPredicate() "ON ST_Contains(ST_GeometryFromText(b.wkt), ST_Point(a.latitude1, a.longitude1)) OR ST_Contains(ST_GeometryFromText(b.wkt), ST_Point(a.latitude2, a.longitude2))", "VALUES ('x', 'a'), ('y', 'b'), ('y', 'c'), (NULL, 'd'), (NULL, 'empty'), ('z', NULL), (NULL, 'null'), ('null', NULL)"); } + + @Test + public void testLeftJoin() + { + assertThat(new QueryAssertions(getQueryRunner()).query(""" + WITH + points(lat, lon) AS ( VALUES (0.5, 0.5), (2, 2) ), + polygons(id, x) AS ( VALUES (1, ST_GeometryFromText('POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))')) ) + SELECT id, lat, lon + FROM points LEFT JOIN polygons ON st_contains(x, ST_Point(lat, lon)) + """)) + .matches(""" + VALUES + (1, 0.5, 0.5), + (NULL, 2, 2) + """); + } }