sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ama...@apache.org
Subject [sis] 05/45: fix(SQLStore): allow limit and offset setting when using peek operation on stream
Date Tue, 12 Nov 2019 16:44:32 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 d8bcbc30a49c5792e3cb9fd0ced3091f7c1126f2
Author: Alexis Manin <amanin@apache.org>
AuthorDate: Thu Aug 22 19:49:01 2019 +0200

    fix(SQLStore): allow limit and offset setting when using peek operation on stream
---
 .../apache/sis/internal/sql/feature/StreamSQL.java | 42 +++++++++++++++++++---
 .../java/org/apache/sis/storage/FeatureNaming.java |  5 +--
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/StreamSQL.java
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/StreamSQL.java
index 88c59dd..c93798b 100644
--- a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/StreamSQL.java
+++ b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/StreamSQL.java
@@ -7,6 +7,7 @@ import java.sql.Statement;
 import java.util.concurrent.Callable;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Consumer;
+import java.util.function.DoubleConsumer;
 import java.util.function.DoubleFunction;
 import java.util.function.DoubleUnaryOperator;
 import java.util.function.Function;
@@ -32,6 +33,8 @@ class StreamSQL extends StreamDecoration<Feature> {
     final Features.Builder queryBuilder;
     boolean parallel;
 
+    private Consumer<? super Feature> peekAction;
+
     StreamSQL(final Table source) {
         this(new Features.Builder(source));
     }
@@ -79,8 +82,16 @@ class StreamSQL extends StreamDecoration<Feature> {
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public Stream<Feature> peek(Consumer<? super Feature> action) {
-        return super.peek(action);
+        if (peekAction == null) {
+            peekAction = action;
+        } else {
+            // Safe cast, because Stream values are strongly typed to O.
+            peekAction = peekAction.andThen((Consumer)action);
+        }
+
+        return this;
     }
 
     @Override
@@ -146,8 +157,9 @@ class StreamSQL extends StreamDecoration<Feature> {
     }
 
     private static class MappedStream<I, O> extends StreamDecoration<O> {
-         private final Function<? super I, ? extends O> mapper;
-         Stream<I> source;
+        private final Function<? super I, ? extends O> mapper;
+        private Stream<I> source;
+        private Consumer<? super O> peekAction;
 
         private MappedStream(Function<? super I, ? extends O> mapper, Stream<I>
source) {
             this.mapper = mapper;
@@ -155,6 +167,19 @@ class StreamSQL extends StreamDecoration<Feature> {
         }
 
         @Override
+        @SuppressWarnings("unchecked")
+        public Stream<O> peek(Consumer<? super O> action) {
+            if (peekAction == null) {
+                peekAction = action;
+            } else {
+                // Safe cast, because Stream values are strongly typed to O.
+                peekAction = peekAction.andThen((Consumer)action);
+            }
+
+            return this;
+        }
+
+        @Override
         public Stream<O> distinct() {
             source = source.distinct();
             return this;
@@ -209,7 +234,8 @@ class StreamSQL extends StreamDecoration<Feature> {
             // Break possible infinite loop by sinking source content through its spliterator
(terminal op).
             final Stream<I> sink = StreamSupport.stream(source.spliterator(), source.isParallel());
             sink.onClose(source::close);
-            return sink.map(mapper);
+            final Stream<O> result = sink.map(mapper);
+            return peekAction == null? result : result.peek(peekAction);
         }
     }
 
@@ -218,12 +244,20 @@ class StreamSQL extends StreamDecoration<Feature> {
         Stream<T> source;
         final ToDoubleFunction<T> toDouble;
 
+        private DoubleConsumer peekAction;
+
         private ToDoubleStream(Stream<T> source, ToDoubleFunction<T> toDouble)
{
             this.source = source;
             this.toDouble = toDouble;
         }
 
         @Override
+        public DoubleStream peek(DoubleConsumer action) {
+            peekAction = peekAction == null? action : peekAction.andThen(action);
+            return this;
+        }
+
+        @Override
         public DoubleStream map(DoubleUnaryOperator mapper) {
             return new ToDoubleStream<T>(source, t -> mapper.applyAsDouble(toDouble.applyAsDouble(t)));
         }
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureNaming.java b/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureNaming.java
index 62e9235..e38d57c 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureNaming.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureNaming.java
@@ -36,7 +36,8 @@ import org.apache.sis.internal.storage.Resources;
  * actually puts no restriction on the kind of object associated to {@code GenericName}s;
  * {@link DataStore} implementations are free to choose their internal object.
  * Those objects can be stored and fetched using the {@code String} representation of their
name
- * as given by {@link GenericName#toString()}, or a shortened name when there is no ambiguity.
+ * as given by {@link GenericName#toString()}, or a shortened name when there is no ambiguity.
Note that search is
+ * case sensitive.
  *
  * <div class="note"><b>Example:</b>
  * a data store may contain a {@code FeatureType} named {@code "foo:bar"}.
@@ -146,7 +147,7 @@ public class FeatureNaming<E> {
     }
 
     /**
-     * Returns the value associated to the given name.
+     * Returns the value associated to the given name. Case sensitive.
      *
      * @param  store  the data store for which to get a value, or {@code null} if unknown.
      * @param  name   the name for which to get a value.


Mime
View raw message