sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject [sis] 01/01: FeatureSet : support simple query using a property unknowned by the feature type
Date Mon, 19 Oct 2020 12:09:38 GMT
This is an automated email from the ASF dual-hosted git repository.

jsorel pushed a commit to branch feat/featureset-subset-abstract
in repository https://gitbox.apache.org/repos/asf/sis.git

commit f153f69befcf0792922d1372082c2bfddd8fbf10
Author: jsorel <johann.sorel@geomatys.com>
AuthorDate: Mon Oct 19 14:04:23 2020 +0200

    FeatureSet : support simple query using a property unknowned by the feature type
---
 .../java/org/apache/sis/filter/LeafExpression.java | 28 +++++++------
 .../internal/storage/query/SimpleQueryTest.java    | 46 ++++++++++++++++++----
 2 files changed, 54 insertions(+), 20 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/filter/LeafExpression.java b/core/sis-feature/src/main/java/org/apache/sis/filter/LeafExpression.java
index ef2affd..f624a56 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/filter/LeafExpression.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/filter/LeafExpression.java
@@ -16,28 +16,26 @@
  */
 package org.apache.sis.filter;
 
-import java.util.Map;
 import java.util.Collection;
 import java.util.Collections;
-import org.apache.sis.util.Classes;
-import org.apache.sis.util.iso.Names;
+import java.util.Map;
+import org.apache.sis.feature.builder.FeatureTypeBuilder;
+import org.apache.sis.feature.builder.PropertyTypeBuilder;
+import org.apache.sis.internal.feature.FeatureExpression;
+import org.apache.sis.internal.filter.Node;
 import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.Classes;
 import org.apache.sis.util.ObjectConverters;
 import org.apache.sis.util.UnconvertibleObjectException;
 import org.apache.sis.util.collection.WeakValueHashMap;
-import org.apache.sis.internal.feature.FeatureExpression;
-import org.apache.sis.internal.filter.Node;
-import org.apache.sis.feature.builder.FeatureTypeBuilder;
-import org.apache.sis.feature.builder.PropertyTypeBuilder;
-
-// Branch-dependent imports
+import org.apache.sis.util.iso.Names;
+import org.opengis.feature.AttributeType;
 import org.opengis.feature.Feature;
 import org.opengis.feature.FeatureType;
-import org.opengis.feature.PropertyType;
-import org.opengis.feature.AttributeType;
 import org.opengis.feature.IdentifiedType;
 import org.opengis.feature.Operation;
 import org.opengis.feature.PropertyNotFoundException;
+import org.opengis.feature.PropertyType;
 import org.opengis.filter.expression.Expression;
 import org.opengis.filter.expression.ExpressionVisitor;
 
@@ -156,7 +154,13 @@ abstract class LeafExpression extends Node implements Expression, FeatureExpress
          */
         @Override
         public PropertyTypeBuilder expectedType(final FeatureType valueType, final FeatureTypeBuilder
addTo) {
-            PropertyType type = valueType.getProperty(name);        // May throw IllegalArgumentException.
+            PropertyType type;
+            try {
+                type = valueType.getProperty(name);
+            } catch (IllegalArgumentException ex) {
+                // the property does not exist but may be defined on a yet unknown child
type.
+                return addTo.addAttribute(Object.class).setName(name).setMinimumOccurs(0);
+            }
             while (type instanceof Operation) {
                 final IdentifiedType result = ((Operation) type).getResult();
                 if (result != type && result instanceof PropertyType) {
diff --git a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/SimpleQueryTest.java
b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/SimpleQueryTest.java
index f29bb82..968f82d 100644
--- a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/SimpleQueryTest.java
+++ b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/query/SimpleQueryTest.java
@@ -16,28 +16,25 @@
  */
 package org.apache.sis.internal.storage.query;
 
-import java.util.List;
 import java.util.Arrays;
+import java.util.List;
 import java.util.stream.Collectors;
 import org.apache.sis.feature.builder.FeatureTypeBuilder;
+import org.apache.sis.filter.DefaultFilterFactory;
 import org.apache.sis.internal.storage.MemoryFeatureSet;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.FeatureSet;
-import org.apache.sis.test.TestUtilities;
 import org.apache.sis.test.TestCase;
-import org.junit.Test;
-
+import org.apache.sis.test.TestUtilities;
 import static org.junit.Assert.*;
-
-// Branch-dependent imports
+import org.junit.Test;
+import org.opengis.feature.AttributeType;
 import org.opengis.feature.Feature;
 import org.opengis.feature.FeatureType;
 import org.opengis.feature.PropertyType;
-import org.opengis.feature.AttributeType;
 import org.opengis.filter.Filter;
 import org.opengis.filter.MatchAction;
 import org.opengis.filter.sort.SortOrder;
-import org.apache.sis.filter.DefaultFilterFactory;
 
 
 /**
@@ -194,4 +191,37 @@ public final strictfp class SimpleQueryTest extends TestCase {
         assertEquals(3, result.getPropertyValue("renamed1"));
         assertEquals("a literal", result.getPropertyValue("computed"));
     }
+
+    /**
+     * Verifies the effect of {@link SimpleQuery#setColumns(SimpleQuery.Column...)} on an
abstract feature type.
+     * We expect the column to be defined even if the property name is undefined on the feature
type.
+     * This case happens when the FeatureSet contains features with inherited types.
+     *
+     * @throws DataStoreException if an error occurred while executing the query.
+     */
+    @Test
+    public void testColumnsAbstractType() throws DataStoreException {
+        final DefaultFilterFactory factory = new DefaultFilterFactory();
+        query.setColumns(new SimpleQuery.Column(factory.property("value1"),   (String) null),
+                         new SimpleQuery.Column(factory.property("unknown"), "unexpected"));
+        query.setLimit(1);
+
+        final FeatureSet fs = query.execute(featureSet);
+        final Feature result = TestUtilities.getSingleton(fs.features(false).collect(Collectors.toList()));
+
+        // Check result type.
+        final FeatureType resultType = result.getType();
+        assertEquals("Test", resultType.getName().toString());
+        assertEquals(2, resultType.getProperties(true).size());
+        final PropertyType pt1 = resultType.getProperty("value1");
+        final PropertyType pt2 = resultType.getProperty("unexpected");
+        assertTrue(pt1 instanceof AttributeType);
+        assertTrue(pt2 instanceof AttributeType);
+        assertEquals(Integer.class, ((AttributeType) pt1).getValueClass());
+        assertEquals(Object.class, ((AttributeType) pt2).getValueClass());
+
+        // Check feature.
+        assertEquals(3, result.getPropertyValue("value1"));
+        assertEquals(null, result.getPropertyValue("unexpected"));
+    }
 }


Mime
View raw message