|
@@ -8,9 +8,13 @@
|
|
|
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.util.$Array$;
|
|
|
import org.elasticsearch.core.Releasable;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
/**
|
|
|
* Vector implementation that defers to an enclosed {@link $if(boolean)$Bit$else$$Type$$endif$Array}.
|
|
|
* Does not take ownership of the array and does not adjust circuit breakers to account for it.
|
|
@@ -27,6 +31,32 @@ public final class $Type$BigArrayVector extends AbstractVector implements $Type$
|
|
|
this.values = values;
|
|
|
}
|
|
|
|
|
|
+ static $Type$BigArrayVector readArrayVector(int positions, StreamInput in, BlockFactory blockFactory) throws IOException {
|
|
|
+$if(boolean)$
|
|
|
+ $Array$ values = new BitArray(blockFactory.bigArrays(), true, in);
|
|
|
+$else$
|
|
|
+ $Array$ values = blockFactory.bigArrays().new$Type$Array(positions, false);
|
|
|
+$endif$
|
|
|
+ boolean success = false;
|
|
|
+ try {
|
|
|
+$if(boolean)$$else$
|
|
|
+ values.fillWith(in);
|
|
|
+$endif$
|
|
|
+ $Type$BigArrayVector vector = new $Type$BigArrayVector(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 $Type$Block asBlock() {
|
|
|
return new $Type$VectorBlock(this);
|