Skip to content

Commit

Permalink
GIS #462: don't push geo joins if datastore does not support it
Browse files Browse the repository at this point in the history
  • Loading branch information
danylokravchenko committed Feb 24, 2024
1 parent 7ca7a5f commit 564eec3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dbms/src/main/java/org/polypheny/db/PolyphenyDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class PolyphenyDb {
public boolean daemonMode = false;

@Option(name = { "-defaultStore" }, description = "Type of default storeId")
public String defaultStoreName = "postgresql";
public String defaultStoreName = "hsqldb";

@Option(name = { "-defaultSource" }, description = "Type of default source")
public String defaultSourceName = "csv";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static void addTestData() throws SQLException {
try ( JdbcConnection jdbcConnection = new JdbcConnection( false ) ) {
Connection connection = jdbcConnection.getConnection();
try ( Statement statement = connection.createStatement() ) {
statement.executeUpdate( "CREATE TABLE TEST_GIS(ID INTEGER NOT NULL, WKT GEOMETRY, PRIMARY KEY (ID))" );
statement.executeUpdate( "CREATE TABLE TEST_GIS(ID INTEGER NOT NULL, geom GEOMETRY, PRIMARY KEY (ID))" );
statement.executeUpdate( "INSERT INTO TEST_GIS VALUES (1, ST_GeomFromText('POINT (7.852923 47.998949)', 4326))" );
statement.executeUpdate( "INSERT INTO TEST_GIS VALUES (2, ST_GeomFromText('POINT (9.289382 48.741588)', 4326))" );
connection.commit();
Expand Down Expand Up @@ -74,7 +74,7 @@ public void readGeo() throws SQLException {
try ( Statement statement = connection.createStatement() ) {
// scan table for geometries
TestHelper.checkResultSet(
statement.executeQuery( "SELECT WKT FROM TEST_GIS" ),
statement.executeQuery( "SELECT geom FROM TEST_GIS" ),
ImmutableList.of(
new Object[]{ "SRID=4326;POINT (7.852923 47.998949)" },
new Object[]{ "SRID=4326;POINT (9.289382 48.741588)" }
Expand Down Expand Up @@ -181,7 +181,7 @@ public void commonPropertiesFunctions() throws SQLException {
) );
// get the convex hull of the geometry from the database
TestHelper.checkResultSet(
statement.executeQuery( "SELECT ST_ConvexHull(WKT) from TEST_GIS" ),
statement.executeQuery( "SELECT ST_ConvexHull(geom) from TEST_GIS" ),
ImmutableList.of(
new Object[]{ "SRID=4326;POINT (7.852923 47.998949)" },
new Object[]{ "SRID=4326;POINT (9.289382 48.741588)" }
Expand Down Expand Up @@ -297,21 +297,21 @@ public void spatialRelationsFunctions() throws SQLException {
) );
// check that area contains the point
TestHelper.checkResultSet(
statement.executeQuery( "SELECT count(*) from TEST_GIS where ST_Contains(ST_GeomFromText('POLYGON ((9.2 48.8, 10.289382 48.8, 10.289382 47.741588, 9.2 47.741588, 9.2 48.8))', 4326), WKT) and id = 2" ),
statement.executeQuery( "SELECT count(*) from TEST_GIS where ST_Contains(ST_GeomFromText('POLYGON ((9.2 48.8, 10.289382 48.8, 10.289382 47.741588, 9.2 47.741588, 9.2 48.8))', 4326), geom) and id = 2" ),
ImmutableList.of(
new Object[]{ 1 }
) );
// check that point is within area
TestHelper.checkResultSet(
statement.executeQuery( "SELECT count(*) from TEST_GIS where ST_Within(wkt, ST_GeomFromText('POLYGON ((9.2 48.8, 10.289382 48.8, 10.289382 47.741588, 9.2 47.741588, 9.2 48.8))', 4326))" ),
statement.executeQuery( "SELECT count(*) from TEST_GIS where ST_Within(geom, ST_GeomFromText('POLYGON ((9.2 48.8, 10.289382 48.8, 10.289382 47.741588, 9.2 47.741588, 9.2 48.8))', 4326))" ),
ImmutableList.of(
new Object[]{ 1 }
) );
// spatial join
TestHelper.checkResultSet(
statement.executeQuery( "SELECT count(*) from TEST_GIS g1, TEST_GIS g2 where ST_Contains(g1.wkt, g2.wkt)" ),
statement.executeQuery( "SELECT count(*) from TEST_GIS g1, TEST_GIS g2 where ST_Contains(g1.geom, g2.geom)" ),
ImmutableList.of(
new Object[]{ 0 }
new Object[]{ 2 }
) );
}
}
Expand All @@ -323,7 +323,7 @@ public void distanceFunctions() throws SQLException {
Connection connection = polyphenyDbConnection.getConnection();
try ( Statement statement = connection.createStatement() ) {
TestHelper.checkResultSet(
statement.executeQuery( "SELECT count(*) from TEST_GIS where ST_Distance(wkt, ST_GeomFromText('POINT (9.289382 48.741588)', 4326)) < 135555" ),
statement.executeQuery( "SELECT count(*) from TEST_GIS where ST_Distance(geom, ST_GeomFromText('POINT (9.289382 48.741588)', 4326)) < 135555" ),
ImmutableList.of(
new Object[]{ 2 }
) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,38 @@ public static class JdbcJoinRule extends JdbcConverterRule {
public JdbcJoinRule( JdbcConvention out, AlgBuilderFactory algBuilderFactory ) {
super(
Join.class,
(Predicate<AlgNode>) r -> true,
join -> !geoFunctionInJoin( join ) || supportsGeoFunctionInJoin( out.dialect, join ),
Convention.NONE,
out,
algBuilderFactory,
"JdbcJoinRule." + out );
}


private static boolean geoFunctionInJoin( Join join ) {
CheckingGeoFunctionVisitor visitor = new CheckingGeoFunctionVisitor();
for ( RexNode node : join.getChildExps() ) {
node.accept( visitor );
if ( visitor.containsGeoFunction() ) {
return true;
}
}
return false;
}


private static boolean supportsGeoFunctionInJoin( SqlDialect dialect, Join join ) {
CheckingGeoFunctionSupportVisitor visitor = new CheckingGeoFunctionSupportVisitor( dialect );
for ( RexNode node : join.getChildExps() ) {
node.accept( visitor );
if ( visitor.supportsGeoFunction() ) {
return true;
}
}
return false;
}


@Override
public AlgNode convert( AlgNode alg ) {
if ( alg instanceof SemiJoin ) {
Expand Down

0 comments on commit 564eec3

Please sign in to comment.