sis-commits mailing list archives

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

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

commit 97e798b647373322d91a6f3ab8e2c533d806bc48
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 |  8 ++++-
 .../internal/storage/query/SimpleQueryTest.java    | 35 +++++++++++++++++++++-
 2 files changed, 41 insertions(+), 2 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..bdc80dd 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
@@ -156,7 +156,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..c7c4e5b 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
@@ -44,7 +44,7 @@ import org.apache.sis.filter.DefaultFilterFactory;
  * Tests {@link SimpleQuery} and (indirectly) {@link FeatureSubset}.
  *
  * @author  Johann Sorel (Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   1.0
  * @module
  */
@@ -194,4 +194,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 {@link 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 property values.
+        assertEquals(3,    result.getPropertyValue("value1"));
+        assertEquals(null, result.getPropertyValue("unexpected"));
+    }
 }


Mime
View raw message