forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESQL: Fixed length vector builder (elastic#99970)
This adds things like `IntVector.FixedBuilder` which is slightly simpler to use than constructing the arrays by hand. It also measures bytes used up front in the circuit breaker. And it'll be easier to integrate it into framework happening over in elastic#99931 to handle errors in topn. This also uses it in `mv_` functions.
- Loading branch information
Showing
59 changed files
with
879 additions
and
228 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
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
61 changes: 61 additions & 0 deletions
61
...pute/src/main/generated-src/org/elasticsearch/compute/data/BooleanVectorFixedBuilder.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,61 @@ | ||
/* | ||
* 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.RamUsageEstimator; | ||
|
||
/** | ||
* Builder for {@link BooleanVector}s that never grows. Prefer this to | ||
* {@link BooleanVectorBuilder} if you know the precise size up front because | ||
* it's faster. | ||
* This class is generated. Do not edit it. | ||
*/ | ||
final class BooleanVectorFixedBuilder implements BooleanVector.FixedBuilder { | ||
private final BlockFactory blockFactory; | ||
private final boolean[] values; | ||
/** | ||
* The next value to write into. {@code -1} means the vector has already | ||
* been built. | ||
*/ | ||
private int nextIndex; | ||
|
||
BooleanVectorFixedBuilder(int size, BlockFactory blockFactory) { | ||
blockFactory.adjustBreaker(ramBytesUsed(size), false); | ||
this.blockFactory = blockFactory; | ||
this.values = new boolean[size]; | ||
} | ||
|
||
@Override | ||
public BooleanVectorFixedBuilder appendBoolean(boolean value) { | ||
values[nextIndex++] = value; | ||
return this; | ||
} | ||
|
||
private static long ramBytesUsed(int size) { | ||
return size == 1 | ||
? ConstantBooleanVector.RAM_BYTES_USED | ||
: BooleanArrayVector.BASE_RAM_BYTES_USED + RamUsageEstimator.alignObjectSize( | ||
(long) RamUsageEstimator.NUM_BYTES_ARRAY_HEADER + size * Byte.BYTES | ||
); | ||
} | ||
|
||
@Override | ||
public BooleanVector build() { | ||
if (nextIndex < 0) { | ||
throw new IllegalStateException("already closed"); | ||
} | ||
if (nextIndex != values.length) { | ||
throw new IllegalStateException("expected to write [" + values.length + "] entries but wrote [" + nextIndex + "]"); | ||
} | ||
nextIndex = -1; | ||
if (values.length == 1) { | ||
return new ConstantBooleanVector(values[0], 1, blockFactory); | ||
} | ||
return new BooleanArrayVector(values, values.length, blockFactory); | ||
} | ||
} |
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
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
Oops, something went wrong.