liran-funaro commented on a change in pull request #10593:
URL: https://github.com/apache/druid/pull/10593#discussion_r541911202



##########
File path: 
processing/src/main/java/org/apache/druid/segment/generator/DataGenerator.java
##########
@@ -143,4 +151,54 @@ private long nextTimestamp()
     }
   }
 
+  /**
+   * Initialize a Java Stream generator for InputRow from this DataGenerator.
+   *
+   * @param numOfRows the number of rows to generate
+   * @return a generator
+   */
+  private Stream<InputRow> generator(int numOfRows)
+  {
+    return Stream.generate(this::nextRow).limit(numOfRows);
+  }
+
+  /**
+   * Add rows form any generator to an index.

Review comment:
       Fixed

##########
File path: 
processing/src/test/java/org/apache/druid/segment/incremental/IncrementalIndexCreator.java
##########
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.segment.incremental;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.cfg.MapperConfig;
+import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
+import com.fasterxml.jackson.databind.introspect.AnnotatedClassResolver;
+import com.fasterxml.jackson.databind.jsontype.NamedType;
+import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
+import org.apache.druid.jackson.DefaultObjectMapper;
+import org.apache.druid.java.util.common.io.Closer;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * An incremental-index creator for parameterized incremental-index tests.
+ * It lists all the available incremental-index implementations, and 
responsible to create and close incremental-index
+ * instances during the tests.
+ */
+public class IncrementalIndexCreator implements Closeable
+{
+  public static final ObjectMapper JSON_MAPPER = new DefaultObjectMapper();
+
+  /**
+   * Allows adding support for testing unregistered indexes.
+   * It is used by Druid's extensions for the incremental-index.
+   *
+   * @param c    an index spec class
+   * @param name an index spec name
+   */
+  public static void addIndexSpec(Class<?> c, String name)
+  {
+    JSON_MAPPER.registerSubtypes(new NamedType(c, name));
+  }
+
+  static {
+    // The off-heap incremental-index is not registered for production, but we 
want to include it in the tests.
+    
IncrementalIndexCreator.addIndexSpec(OffheapIncrementalIndexTestSpec.class, 
OffheapIncrementalIndexTestSpec.TYPE);
+  }
+
+  /**
+   * Fetch all the available incremental-index implementations.
+   * It can be used to parametrize the test. If more parameters are needed, 
use indexTypeCartesianProduct().
+   * @see #indexTypeCartesianProduct(Collection[]).
+   *
+   * @return a list of all the incremental-index implementations types (String)
+   */
+  public static List<String> getAppendableIndexTypes()
+  {
+    SubtypeResolver resolver = JSON_MAPPER.getSubtypeResolver();
+    MapperConfig<?> config = JSON_MAPPER.getDeserializationConfig();
+    AnnotatedClass cls = 
AnnotatedClassResolver.resolveWithoutSuperTypes(config, 
AppendableIndexSpec.class);
+    Collection<NamedType> types = 
resolver.collectAndResolveSubtypesByClass(config, cls);
+    return 
types.stream().map(NamedType::getName).filter(Objects::nonNull).distinct().collect(Collectors.toList());
+  }
+
+  public interface IndexCreator
+  {
+    /**
+     * Build an index given a builder and args.
+     *
+     * @param builder an incremental index builder supplied by the framework
+     * @param args a list of arguments that are used to configure the builder
+     * @return a new instance of an incremental-index
+     */
+    IncrementalIndex<?> createIndex(AppendableIndexBuilder builder, Object... 
args);
+  }
+
+  private final Closer closer = Closer.create();
+
+  private final AppendableIndexSpec appendableIndexSpec;
+
+  private final IndexCreator indexCreator;
+
+  /**
+   * Initialize the creator.
+   *
+   * @param spec a spec that can generate a incremental-index builder
+   * @param indexCreator a function that generate an index given a builder and 
arguments
+   */
+  public IncrementalIndexCreator(AppendableIndexSpec spec, IndexCreator 
indexCreator)
+  {
+    this.appendableIndexSpec = spec;
+    this.indexCreator = indexCreator;
+  }
+
+  /**
+   * Initialize the creator.
+   *
+   * @param indexType an index type (name)
+   * @param indexCreator a function that generate an index given a builder and 
arguments
+   */
+  public IncrementalIndexCreator(String indexType, IndexCreator indexCreator) 
throws JsonProcessingException
+  {
+    this(parseIndexType(indexType), indexCreator);
+  }
+
+  /**
+   * Generate an AppendableIndexSpec from index type.
+   *
+   * @param indexType an index type
+   * @return AppendableIndexSpec instance of this type
+   * @throws JsonProcessingException if failed to to parse the index
+   */
+  public static AppendableIndexSpec parseIndexType(String indexType) throws 
JsonProcessingException
+  {
+    return JSON_MAPPER.readValue(
+        String.format(Locale.ENGLISH, "{\"type\": \"%s\"}", indexType),

Review comment:
       Fixed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to