org.elasticsearch.compute.data.LongBigArrayVector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of x-pack-esql-compute Show documentation
Show all versions of x-pack-esql-compute Show documentation
Elasticsearch subproject :x-pack:plugin:esql:compute
/*
* 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;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.util.LongArray;
import org.elasticsearch.core.Releasable;
import org.elasticsearch.core.ReleasableIterator;
import java.io.IOException;
/**
* Vector implementation that defers to an enclosed {@link LongArray}.
* Does not take ownership of the array and does not adjust circuit breakers to account for it.
* This class is generated. Do not edit it.
*/
public final class LongBigArrayVector extends AbstractVector implements LongVector, Releasable {
private static final long BASE_RAM_BYTES_USED = 0; // FIXME
private final LongArray values;
public LongBigArrayVector(LongArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
}
static LongBigArrayVector readArrayVector(int positions, StreamInput in, BlockFactory blockFactory) throws IOException {
LongArray values = blockFactory.bigArrays().newLongArray(positions, false);
boolean success = false;
try {
values.fillWith(in);
LongBigArrayVector vector = new LongBigArrayVector(values, positions, blockFactory);
blockFactory.adjustBreaker(vector.ramBytesUsed() - RamUsageEstimator.sizeOf(values));
success = true;
return vector;
} finally {
if (success == false) {
values.close();
}
}
}
void writeArrayVector(int positions, StreamOutput out) throws IOException {
values.writeTo(out);
}
@Override
public LongBlock asBlock() {
return new LongVectorBlock(this);
}
@Override
public long getLong(int position) {
return values.get(position);
}
@Override
public ElementType elementType() {
return ElementType.LONG;
}
@Override
public boolean isConstant() {
return false;
}
@Override
public long ramBytesUsed() {
return BASE_RAM_BYTES_USED + RamUsageEstimator.sizeOf(values);
}
@Override
public LongVector filter(int... positions) {
var blockFactory = blockFactory();
final LongArray filtered = blockFactory.bigArrays().newLongArray(positions.length);
for (int i = 0; i < positions.length; i++) {
filtered.set(i, values.get(positions[i]));
}
return new LongBigArrayVector(filtered, positions.length, blockFactory);
}
@Override
public ReleasableIterator lookup(IntBlock positions, ByteSizeValue targetBlockSize) {
return new LongLookup(asBlock(), positions, targetBlockSize);
}
@Override
public void closeInternal() {
// The circuit breaker that tracks the values {@link LongArray} is adjusted outside
// of this class.
values.close();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof LongVector that) {
return LongVector.equals(this, that);
}
return false;
}
@Override
public int hashCode() {
return LongVector.hash(this);
}
@Override
public String toString() {
return getClass().getSimpleName() + "[positions=" + getPositionCount() + ", values=" + values + ']';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy