Skip to content

Commit

Permalink
GIS #462: exclude geo operations from being pushed down in sql filter
Browse files Browse the repository at this point in the history
  • Loading branch information
danylokravchenko committed Jan 17, 2024
1 parent 9015dbc commit 34b043d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ public void distanceFunctions() throws SQLException {
try ( TestHelper.JdbcConnection polyphenyDbConnection = new TestHelper.JdbcConnection( true ) ) {
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" ),
ImmutableList.of(
new Object[]{ 2 }
) );
// calculate the distance between two points
TestHelper.checkResultSet(
statement.executeQuery( "SELECT ST_Distance(ST_GeomFromText('POINT (7.852923 47.998949)', 4326), ST_GeomFromText('POINT (9.289382 48.741588)', 4326))" ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ private static boolean supportsGeoFunction( SqlDialect dialect, Project project
}


private static boolean geoFunctionInProject( Project project ) {
private static boolean geoFunctionInProject( AlgNode project ) {
CheckingGeoFunctionVisitor visitor = new CheckingGeoFunctionVisitor();
for ( RexNode node : project.getChildExps() ) {
node.accept( visitor );
Expand Down Expand Up @@ -577,6 +577,7 @@ public JdbcFilterRule( JdbcConvention out, AlgBuilderFactory algBuilderFactory )
!userDefinedFunctionInFilter( filter )
&& !knnFunctionInFilter( filter )
&& !multimediaFunctionInFilter( filter )
&& (!geoFunctionInFilter( filter ) || supportsGeoFunctionInFilter( out.dialect, filter ))
&& !DocumentRules.containsJson( filter )
&& !DocumentRules.containsDocument( filter )
&& (out.dialect.supportsNestedArrays() || (!itemOperatorInFilter( filter ) && isStringComparableArrayType( filter )))),
Expand Down Expand Up @@ -615,6 +616,30 @@ private static boolean multimediaFunctionInFilter( Filter filter ) {
}


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


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


private static boolean itemOperatorInFilter( Filter filter ) {
CheckingItemOperatorVisitor visitor = new CheckingItemOperatorVisitor();
for ( RexNode node : filter.getChildExps() ) {
Expand Down Expand Up @@ -697,7 +722,7 @@ public static class JdbcAggregateRule extends JdbcConverterRule {
* Creates a JdbcAggregateRule.
*/
public JdbcAggregateRule( JdbcConvention out, AlgBuilderFactory algBuilderFactory ) {
super( Aggregate.class, (Predicate<AlgNode>) r -> true, Convention.NONE, out, algBuilderFactory, "JdbcAggregateRule." + out );
super( Aggregate.class, aggregate -> true, Convention.NONE, out, algBuilderFactory, "JdbcAggregateRule." + out );
}


Expand Down

0 comments on commit 34b043d

Please sign in to comment.