sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ama...@apache.org
Subject [sis] 20/45: WIP(SQLStore): add javadoc, work on filter adaptation api.
Date Tue, 12 Nov 2019 16:44:47 GMT
This is an automated email from the ASF dual-hosted git repository.

amanin pushed a commit to branch refactor/sql-store
in repository https://gitbox.apache.org/repos/asf/sis.git

commit db2b6b670846e68f50b8b75b89d776618f01d73f
Author: Alexis Manin <amanin@apache.org>
AuthorDate: Fri Sep 27 11:58:36 2019 +0200

    WIP(SQLStore): add javadoc, work on filter adaptation api.
---
 .../apache/sis/internal/sql/feature/Analyzer.java  |  2 +-
 .../sis/internal/sql/feature/SQLQueryAdapter.java  | 22 +++++++++++++------
 .../org/apache/sis/internal/sql/feature/Table.java | 19 +++++-----------
 .../apache/sis/internal/storage/SubsetAdapter.java | 25 ++++++++++++++++------
 .../sis/internal/storage/query/SimpleQuery.java    | 12 +++++++----
 5 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Analyzer.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Analyzer.java
index 9348d01..d947ad2 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Analyzer.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Analyzer.java
@@ -592,7 +592,7 @@ final class Analyzer {
 
         @Override
         public Optional<GenericName> getName() throws SQLException {
-            return Optional.of(name);
+            return Optional.ofNullable(name);
         }
 
         @Override
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SQLQueryAdapter.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SQLQueryAdapter.java
index c6b3dc4..0ddde08 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SQLQueryAdapter.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/SQLQueryAdapter.java
@@ -22,14 +22,24 @@ public class SQLQueryAdapter implements SubsetAdapter.AdapterBuilder {
         this.parent = parent;
     }
 
+    /**
+     * No-op implementation. SQL optimisation is dynamically applied through {@link StreamSQL}.
+     * @param offset The offset to handle.
+     * @return Input offset.
+     */
     @Override
     public long offset(long offset) {
-        return offset; // Done by stream overload
+        return offset;
     }
 
+    /**
+     * No-op implementation. SQL optimisation is dynamically applied through {@link StreamSQL}.
+     * @param limit The limit to handle.
+     * @return Input limit.
+     */
     @Override
     public long limit(long limit) {
-        return limit; // Done by stream overload
+        return limit;
     }
 
     @Override
@@ -40,17 +50,17 @@ public class SQLQueryAdapter implements SubsetAdapter.AdapterBuilder {
     @Override
     public boolean sort(SortBy[] comparison) {
         sorting = Arrays.copyOf(comparison, comparison.length);
-        return true;
+        return false;
     }
 
     @Override
-    public SimpleQuery.Column[] select(List<SimpleQuery.Column> columns) {
+    public boolean select(List<SimpleQuery.Column> columns) {
         this.columns = columns.toArray(new SimpleQuery.Column[columns.size()]);
-        return null;
+        return false;
     }
 
     @Override
     public Optional<FeatureSet> build() {
-        throw new UnsupportedOperationException("Not supported yet"); // "Alexis Manin (Geomatys)"
on 18/09/2019
+        return Optional.empty();
     }
 }
diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Table.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Table.java
index 81b8c75..07f658f 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Table.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Table.java
@@ -39,6 +39,7 @@ import org.opengis.util.GenericName;
 import org.apache.sis.internal.metadata.sql.Reflection;
 import org.apache.sis.internal.metadata.sql.SQLBuilder;
 import org.apache.sis.internal.storage.AbstractFeatureSet;
+import org.apache.sis.internal.storage.SubsetAdapter;
 import org.apache.sis.internal.storage.query.SimpleQuery;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.FeatureSet;
@@ -204,22 +205,12 @@ final class Table extends AbstractFeatureSet {
 
     @Override
     public FeatureSet subset(Query query) throws UnsupportedQueryException, DataStoreException
{
-        if (!(query instanceof SimpleQuery)) return super.subset(query);
-        boolean remainingQuery = true;
-        final SimpleQuery q = (SimpleQuery) query;
-        FeatureSet subset = this;
-        final List<SimpleQuery.Column> cols = q.getColumns();
-
-        /**
-         * Once filter has been taken care of, we will be able to check columns to filter.
Note that all filters
-         * managed by database engine can use non-returned columns, but it is not the case
of remaining ones, which
-         * are applied after feature creation, therefore with only filtered columns accessible.
-         */
-        if (cols != null && !cols.isEmpty()) {
-
+        if (query instanceof SimpleQuery) {
+            final SubsetAdapter subsetAdapter = new SubsetAdapter(fs -> new SQLQueryAdapter(this));
+            return subsetAdapter.subset(this, (SimpleQuery) query);
         }
 
-        return remainingQuery ? subset.subset(q) : subset;
+        return super.subset(query);
     }
 
     /**
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/SubsetAdapter.java
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/SubsetAdapter.java
index 08e4310..88f3924 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/SubsetAdapter.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/SubsetAdapter.java
@@ -37,10 +37,8 @@ public final class SubsetAdapter {
 
         if (sortRequired(query) && !driver.sort(query.getSortBy())) remaining.setSortBy(query.getSortBy());
 
-        if (!allColumnsIncluded(query)) {
-            final SimpleQuery.Column[] remainingCols = driver.select(query.getColumns());
-            if (remainingCols != null && remainingCols.length > 0)
-                remaining.setColumns(remainingCols);
+        if (!allColumnsIncluded(query) && !driver.select(query.getColumns())) {
+            remaining.setColumns(query.getColumns().toArray(new SimpleQuery.Column[0]));
         }
 
         final FeatureSet driverSubset = driver.build().orElse(source);
@@ -103,6 +101,17 @@ public final class SubsetAdapter {
          */
         long limit(long limit);
 
+        /**
+         *
+         * @param filter User entity selection criteria.
+         * @return According to driver possibility, one of the following result:
+         * <ul>
+         *     <li>no optimisation is applicable, give back filter received as input.</li>
+         *     <li>All expressed operators can be handled internally, return {@link
Filter#INCLUDE}</li>
+         *     <li>If a part of input filter is manageable, give back a new filter
completing driver intern filtering
+         *     to get result matching source filter.</li>
+         * </ul>
+         */
         Filter filter(final Filter filter);
 
         /**
@@ -116,10 +125,12 @@ public final class SubsetAdapter {
 
         /**
          * Specify a subset of columns to return to the driver.
-         * @param columns The columns
-         * @return
+         * @param columns The columns to fetch in result set. Neither null nor empty list
accepted.
+         * @return True if underlying driver can entirely manage column selection. False
otherwise, meaning that column
+         * selection won't be done, or only partially, and a fallback filter must be applied
over driver feature set to
+         * ensure proper selection.
          */
-        SimpleQuery.Column[] select(List<SimpleQuery.Column> columns);
+        boolean select(List<SimpleQuery.Column> columns);
 
         /**
          * Take a snapshot of all parameters given to query adaptation.
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
index 271e62c..598a338 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/query/SimpleQuery.java
@@ -119,11 +119,15 @@ public class SimpleQuery extends Query {
      */
     @SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter")
     public void setColumns(Column... columns) {
-        columns = columns.clone();
-        for (int i=0; i<columns.length; i++) {
-            ArgumentChecks.ensureNonNullElement("columns", i, columns[i]);
+        if (columns == null || columns.length < 1) {
+            this.columns = null;
+        } else {
+            columns = columns.clone();
+            for (int i = 0; i < columns.length; i++) {
+                ArgumentChecks.ensureNonNullElement("columns", i, columns[i]);
+            }
+            this.columns = columns;
         }
-        this.columns = columns;
     }
 
     /**


Mime
View raw message