This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit f072a37f8cd31461a3f9ea4a55146ee9aa37a79b Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Sun Dec 26 23:45:14 2021 +0100 Add a test and comment explaining why resolving links is an important optimization. It makes the difference between using or not a database index. --- .../src/main/java/org/apache/sis/filter/PropertyValue.java | 6 ++++-- .../java/org/apache/sis/internal/sql/feature/FeatureStream.java | 2 ++ .../src/test/java/org/apache/sis/storage/sql/SQLStoreTest.java | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/filter/PropertyValue.java b/core/sis-feature/src/main/java/org/apache/sis/filter/PropertyValue.java index 8a20ddc..89714ff 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/filter/PropertyValue.java +++ b/core/sis-feature/src/main/java/org/apache/sis/filter/PropertyValue.java @@ -167,8 +167,10 @@ abstract class PropertyValue<V> extends LeafExpression<Feature,V> implements Val } /** - * If the evaluated property is a link, replaces this expression - * by a more direct reference to the target property. + * If the evaluated property is a link, replaces this expression by a more direct reference + * to the target property. This optimization is important for allowing {@code SQLStore} to + * put the column name in the SQL {@code WHERE} clause. It makes the difference between + * using or not the database index. */ @Override public Expression<Feature,?> optimize(final Optimization optimization) { diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/FeatureStream.java b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/FeatureStream.java index 2660249..850cde5 100644 --- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/FeatureStream.java +++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/FeatureStream.java @@ -405,6 +405,8 @@ final class FeatureStream extends DeferredStream<Feature> { /** * Returns a string representation of this stream for debugging purposes. + * The returned string tells whether filtering and sorting are done using + * SQL statement, Java code, or a mix of both. */ @Override public String toString() { diff --git a/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/SQLStoreTest.java b/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/SQLStoreTest.java index a1ee95e..f36f861 100644 --- a/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/SQLStoreTest.java +++ b/storage/sis-sqlstore/src/test/java/org/apache/sis/storage/sql/SQLStoreTest.java @@ -445,11 +445,20 @@ public final strictfp class SQLStoreTest extends TestCase { final FeatureSet countries = dataset.findResource("Countries"); final FeatureQuery query = new FeatureQuery(); query.setSelection(FF.equal(FF.property("sis:identifier"), FF.literal("CAN"))); + final String executionMode; final Object[] names; try (Stream<Feature> features = countries.subset(query).features(false)) { + executionMode = features.toString(); names = features.map(f -> f.getPropertyValue(desiredProperty)).toArray(); } assertArrayEquals(expectedValues, names); + /* + * Verify that the query is executed with a SQL statement, not with Java code. + * The use of SQL is made possible by the replacement of "sis:identifier" link + * by a reference to "code" column. If that replacement is not properly done, + * then the "predicates" value would be "Java" instead of "SQL". + */ + assertEquals("FeatureStream[table=“Countries”, predicates=“SQL”]", executionMode); } /**