- 
                Notifications
    
You must be signed in to change notification settings  - Fork 25.6k
 
Push down loading of singleton dense double based field types to the … #133397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b15bf8a
              e06f7ae
              96a83e9
              e04f0a7
              4b767b9
              9ac64b0
              e44deae
              51226c9
              72fe3ec
              33f6ee6
              37b6128
              c3b3e2b
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 133397 | ||
| summary: Push down loading of singleton dense double based field types to the … | ||
| area: "Compute Engine, Codec" | ||
| type: enhancement | ||
| issues: [] | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -398,6 +398,12 @@ private static class SingletonDoubles extends BlockDocValuesReader { | |
| 
     | 
||
| @Override | ||
| public BlockLoader.Block read(BlockFactory factory, Docs docs, int offset, boolean nullsFiltered) throws IOException { | ||
| if (docValues instanceof BlockLoader.OptionalColumnAtATimeReader direct) { | ||
| BlockLoader.Block result = direct.tryReadDoubles(factory, docs, offset, toDouble); | ||
                
       | 
||
| if (result != null) { | ||
| return result; | ||
| } | ||
| } | ||
| try (BlockLoader.DoubleBuilder builder = factory.doublesFromDocValues(docs.count() - offset)) { | ||
| for (int i = offset; i < docs.count(); i++) { | ||
| int doc = docs.get(i); | ||
| 
          
            
          
           | 
    ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -68,6 +68,16 @@ interface OptionalColumnAtATimeReader { | |
| */ | ||
| @Nullable | ||
| BlockLoader.Block tryRead(BlockFactory factory, Docs docs, int offset) throws IOException; | ||
| 
     | 
||
| /** | ||
| * Specialization for doubles. | ||
| * Returns {@code null} if unable to load values as doubles. | ||
| */ | ||
| @Nullable | ||
| default BlockLoader.Block tryReadDoubles(BlockFactory factory, Docs docs, int offset, BlockDocValuesReader.ToDouble toDouble) | ||
| throws IOException { | ||
| return null; | ||
| } | ||
| } | ||
| 
     | 
||
| interface RowStrideReader extends Reader { | ||
| 
          
            
          
           | 
    @@ -537,6 +547,7 @@ interface IntBuilder extends Builder { | |
| * Specialized builder for collecting dense arrays of long values. | ||
| */ | ||
| interface SingletonLongBuilder extends Builder { | ||
| void setToDouble(BlockDocValuesReader.ToDouble toDouble); | ||
                
       | 
||
| 
     | 
||
| SingletonLongBuilder appendLong(long value); | ||
| 
     | 
||
| 
          
            
          
           | 
    ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| 
     | 
||
| package org.elasticsearch.compute.data; | ||
| 
     | 
||
| // begin generated imports | ||
| import org.apache.lucene.util.RamUsageEstimator; | ||
| import org.elasticsearch.common.unit.ByteSizeValue; | ||
| import org.elasticsearch.core.ReleasableIterator; | ||
| 
     | 
||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
| // end generated imports | ||
| 
     | 
||
| /** | ||
| * Vector implementation that converts long to double values on-the-fly. | ||
| */ | ||
| final class DoubleOverLongArrayVector extends AbstractVector implements DoubleVector { | ||
| 
     | 
||
| static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(DoubleOverLongArrayVector.class) | ||
| // TODO: remove these extra bytes once `asBlock` returns a block with a separate reference to the vector. | ||
| + RamUsageEstimator.shallowSizeOfInstance(DoubleVectorBlock.class) | ||
| // TODO: remove this if/when we account for memory used by Pages | ||
| + Block.PAGE_MEM_OVERHEAD_PER_BLOCK; | ||
| 
     | 
||
| private final long[] values; | ||
| private final BlockUtils.ToDouble toDouble; | ||
| 
     | 
||
| DoubleOverLongArrayVector(long[] values, BlockUtils.ToDouble toDouble, int positionCount, BlockFactory blockFactory) { | ||
                
       | 
||
| super(positionCount, blockFactory); | ||
| this.values = values; | ||
| this.toDouble = toDouble; | ||
| } | ||
| 
     | 
||
| @Override | ||
| public DoubleBlock asBlock() { | ||
| return new DoubleVectorBlock(this); | ||
| } | ||
| 
     | 
||
| @Override | ||
| public double getDouble(int position) { | ||
| return toDouble.convert(values[position]); | ||
| } | ||
| 
     | 
||
| @Override | ||
| public ElementType elementType() { | ||
| return ElementType.DOUBLE; | ||
| } | ||
| 
     | 
||
| @Override | ||
| public boolean isConstant() { | ||
| return false; | ||
| } | ||
| 
     | 
||
| @Override | ||
| public DoubleVector filter(int... positions) { | ||
| try (DoubleVector.Builder builder = blockFactory().newDoubleVectorBuilder(positions.length)) { | ||
| for (int pos : positions) { | ||
| builder.appendDouble(toDouble.convert((values[pos]))); | ||
| } | ||
| return builder.build(); | ||
| } | ||
| } | ||
| 
     | 
||
| @Override | ||
| public DoubleBlock keepMask(BooleanVector mask) { | ||
| if (getPositionCount() == 0) { | ||
| incRef(); | ||
| return new DoubleVectorBlock(this); | ||
| } | ||
| if (mask.isConstant()) { | ||
| if (mask.getBoolean(0)) { | ||
| incRef(); | ||
| return new DoubleVectorBlock(this); | ||
| } | ||
| return (DoubleBlock) blockFactory().newConstantNullBlock(getPositionCount()); | ||
| } | ||
| try (DoubleBlock.Builder builder = blockFactory().newDoubleBlockBuilder(getPositionCount())) { | ||
| // TODO if X-ArrayBlock used BooleanVector for it's null mask then we could shuffle references here. | ||
| for (int p = 0; p < getPositionCount(); p++) { | ||
| if (mask.getBoolean(p)) { | ||
| builder.appendDouble(getDouble(p)); | ||
| } else { | ||
| builder.appendNull(); | ||
| } | ||
| } | ||
| return builder.build(); | ||
| } | ||
| } | ||
| 
     | 
||
| @Override | ||
| public ReleasableIterator<DoubleBlock> lookup(IntBlock positions, ByteSizeValue targetBlockSize) { | ||
| return new DoubleLookup(asBlock(), positions, targetBlockSize); | ||
| } | ||
| 
     | 
||
| private static long ramBytesEstimated(long[] values) { | ||
| return BASE_RAM_BYTES_USED + RamUsageEstimator.sizeOf(values); | ||
| } | ||
| 
     | 
||
| @Override | ||
| public long ramBytesUsed() { | ||
| return ramBytesEstimated(values); | ||
| } | ||
| 
     | 
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (obj instanceof DoubleVector that) { | ||
| return DoubleVector.equals(this, that); | ||
| } | ||
| return false; | ||
| } | ||
| 
     | 
||
| @Override | ||
| public int hashCode() { | ||
| return DoubleVector.hash(this); | ||
| } | ||
| 
     | 
||
| @Override | ||
| public String toString() { | ||
| String valuesString = IntStream.range(0, getPositionCount()) | ||
| .limit(10) | ||
| .mapToObj(n -> String.valueOf(toDouble.convert(values[n]))) | ||
| .collect(Collectors.joining(", ", "[", getPositionCount() > 10 ? ", ...]" : "]")); | ||
| return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", values=" + valuesString + ']'; | ||
| } | ||
| 
     | 
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.