Github user ilooner commented on a diff in the pull request:

    https://github.com/apache/drill/pull/984#discussion_r145574915
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/TopN/TopNBatch.java
 ---
    @@ -335,20 +336,42 @@ private void purge() throws SchemaChangeException {
         logger.debug("Took {} us to purge", 
watch.elapsed(TimeUnit.MICROSECONDS));
       }
     
    -  public PriorityQueue createNewPriorityQueue(FragmentContext context, 
List<Ordering> orderings,
    -                                                     VectorAccessible 
batch, MappingSet mainMapping, MappingSet leftMapping, MappingSet rightMapping)
    -          throws ClassTransformationException, IOException, 
SchemaChangeException{
    -    CodeGenerator<PriorityQueue> cg = 
CodeGenerator.get(PriorityQueue.TEMPLATE_DEFINITION, 
context.getFunctionRegistry(), context.getOptions());
    +  private PriorityQueue createNewPriorityQueue(VectorAccessible batch, int 
limit)
    +    throws SchemaChangeException, ClassTransformationException, 
IOException {
    +    return createNewPriorityQueue(
    +      mainMapping, leftMapping, rightMapping, context.getOptionSet(), 
context.getFunctionRegistry(), context.getDrillbitContext().getCompiler(),
    +      config.getOrderings(), batch, unionTypeEnabled, codegenDump, limit, 
oContext.getAllocator(), schema.getSelectionVectorMode());
    +  }
    +
    +  public static MappingSet createMainMappingSet() {
    +    return new MappingSet((String) null, null, 
ClassGenerator.DEFAULT_SCALAR_MAP, ClassGenerator.DEFAULT_SCALAR_MAP);
    +  }
    +
    +  public static MappingSet createLeftMappingSet() {
    +    return new MappingSet("leftIndex", null, 
ClassGenerator.DEFAULT_SCALAR_MAP, ClassGenerator.DEFAULT_SCALAR_MAP);
    +  }
    +
    +  public static MappingSet createRightMappingSet() {
    +    return new MappingSet("rightIndex", null, 
ClassGenerator.DEFAULT_SCALAR_MAP, ClassGenerator.DEFAULT_SCALAR_MAP);
    +  }
    +
    +  public static PriorityQueue createNewPriorityQueue(
    +    MappingSet mainMapping, MappingSet leftMapping, MappingSet 
rightMapping,
    --- End diff --
    
    We cannot declare the MappingSets as constants because they contain some 
internal state (the mappingIndex field). If they were constants the state could 
become corrupt in the case where multiple queries run and create PriorityQueues 
on the same node simultaneously, so we have to create new MappingSets each time 
we create a new priority queue.


---

Reply via email to