Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESQL: Add Block#lookup method (#107982)
This adds a method to build a new `Block` by looking up the values in an existing `Block`. Like `BlockHash#lookup` this returns a `ReleasableIterator`. This should allow us to load values using the results of `BlockHash#lookup`.
- Loading branch information
Showing
38 changed files
with
1,090 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...gin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/BooleanLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* 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; | ||
|
||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
import org.elasticsearch.compute.operator.Operator; | ||
import org.elasticsearch.core.ReleasableIterator; | ||
import org.elasticsearch.core.Releasables; | ||
|
||
/** | ||
* Generic {@link Block#lookup} implementation {@link BooleanBlock}s. | ||
* This class is generated. Do not edit it. | ||
*/ | ||
final class BooleanLookup implements ReleasableIterator<BooleanBlock> { | ||
private final BooleanBlock values; | ||
private final IntBlock positions; | ||
private final long targetByteSize; | ||
private int position; | ||
|
||
private boolean first; | ||
private int valuesInPosition; | ||
|
||
BooleanLookup(BooleanBlock values, IntBlock positions, ByteSizeValue targetBlockSize) { | ||
values.incRef(); | ||
positions.incRef(); | ||
this.values = values; | ||
this.positions = positions; | ||
this.targetByteSize = targetBlockSize.getBytes(); | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return position < positions.getPositionCount(); | ||
} | ||
|
||
@Override | ||
public BooleanBlock next() { | ||
try (BooleanBlock.Builder builder = positions.blockFactory().newBooleanBlockBuilder(positions.getTotalValueCount())) { | ||
int count = 0; | ||
while (position < positions.getPositionCount()) { | ||
int start = positions.getFirstValueIndex(position); | ||
int end = start + positions.getValueCount(position); | ||
valuesInPosition = 0; | ||
for (int i = start; i < end; i++) { | ||
copy(builder, positions.getInt(i)); | ||
} | ||
switch (valuesInPosition) { | ||
case 0 -> builder.appendNull(); | ||
case 1 -> builder.appendBoolean(first); | ||
default -> builder.endPositionEntry(); | ||
} | ||
position++; | ||
// TOOD what if the estimate is super huge? should we break even with less than MIN_TARGET? | ||
if (++count > Operator.MIN_TARGET_PAGE_SIZE && builder.estimatedBytes() < targetByteSize) { | ||
break; | ||
} | ||
} | ||
return builder.build(); | ||
} | ||
} | ||
|
||
private void copy(BooleanBlock.Builder builder, int valuePosition) { | ||
if (valuePosition >= values.getPositionCount()) { | ||
return; | ||
} | ||
int start = values.getFirstValueIndex(valuePosition); | ||
int end = start + values.getValueCount(valuePosition); | ||
for (int i = start; i < end; i++) { | ||
if (valuesInPosition == 0) { | ||
first = values.getBoolean(i); | ||
valuesInPosition++; | ||
continue; | ||
} | ||
if (valuesInPosition == 1) { | ||
builder.beginPositionEntry(); | ||
builder.appendBoolean(first); | ||
} | ||
if (valuesInPosition > Block.MAX_LOOKUP) { | ||
// TODO replace this with a warning and break | ||
throw new IllegalArgumentException("Found a single entry with " + valuesInPosition + " entries"); | ||
} | ||
builder.appendBoolean(values.getBoolean(i)); | ||
valuesInPosition++; | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
Releasables.close(values, positions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...in/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/BytesRefLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.lucene.util.BytesRef; | ||
import org.elasticsearch.common.unit.ByteSizeValue; | ||
import org.elasticsearch.compute.operator.Operator; | ||
import org.elasticsearch.core.ReleasableIterator; | ||
import org.elasticsearch.core.Releasables; | ||
|
||
/** | ||
* Generic {@link Block#lookup} implementation {@link BytesRefBlock}s. | ||
* This class is generated. Do not edit it. | ||
*/ | ||
final class BytesRefLookup implements ReleasableIterator<BytesRefBlock> { | ||
private final BytesRef firstScratch = new BytesRef(); | ||
private final BytesRef valueScratch = new BytesRef(); | ||
private final BytesRefBlock values; | ||
private final IntBlock positions; | ||
private final long targetByteSize; | ||
private int position; | ||
|
||
private BytesRef first; | ||
private int valuesInPosition; | ||
|
||
BytesRefLookup(BytesRefBlock values, IntBlock positions, ByteSizeValue targetBlockSize) { | ||
values.incRef(); | ||
positions.incRef(); | ||
this.values = values; | ||
this.positions = positions; | ||
this.targetByteSize = targetBlockSize.getBytes(); | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return position < positions.getPositionCount(); | ||
} | ||
|
||
@Override | ||
public BytesRefBlock next() { | ||
try (BytesRefBlock.Builder builder = positions.blockFactory().newBytesRefBlockBuilder(positions.getTotalValueCount())) { | ||
int count = 0; | ||
while (position < positions.getPositionCount()) { | ||
int start = positions.getFirstValueIndex(position); | ||
int end = start + positions.getValueCount(position); | ||
valuesInPosition = 0; | ||
for (int i = start; i < end; i++) { | ||
copy(builder, positions.getInt(i)); | ||
} | ||
switch (valuesInPosition) { | ||
case 0 -> builder.appendNull(); | ||
case 1 -> builder.appendBytesRef(first); | ||
default -> builder.endPositionEntry(); | ||
} | ||
position++; | ||
// TOOD what if the estimate is super huge? should we break even with less than MIN_TARGET? | ||
if (++count > Operator.MIN_TARGET_PAGE_SIZE && builder.estimatedBytes() < targetByteSize) { | ||
break; | ||
} | ||
} | ||
return builder.build(); | ||
} | ||
} | ||
|
||
private void copy(BytesRefBlock.Builder builder, int valuePosition) { | ||
if (valuePosition >= values.getPositionCount()) { | ||
return; | ||
} | ||
int start = values.getFirstValueIndex(valuePosition); | ||
int end = start + values.getValueCount(valuePosition); | ||
for (int i = start; i < end; i++) { | ||
if (valuesInPosition == 0) { | ||
first = values.getBytesRef(i, firstScratch); | ||
valuesInPosition++; | ||
continue; | ||
} | ||
if (valuesInPosition == 1) { | ||
builder.beginPositionEntry(); | ||
builder.appendBytesRef(first); | ||
} | ||
if (valuesInPosition > Block.MAX_LOOKUP) { | ||
// TODO replace this with a warning and break | ||
throw new IllegalArgumentException("Found a single entry with " + valuesInPosition + " entries"); | ||
} | ||
builder.appendBytesRef(values.getBytesRef(i, valueScratch)); | ||
valuesInPosition++; | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
Releasables.close(values, positions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.