|
@@ -12,15 +12,17 @@ import org.elasticsearch.common.util.BitArray;
|
|
|
import org.elasticsearch.common.util.$Type$Array;
|
|
|
import org.elasticsearch.compute.ann.Experimental;
|
|
|
import org.elasticsearch.compute.data.Block;
|
|
|
+import org.elasticsearch.compute.data.BooleanBlock;
|
|
|
+$if(long)$
|
|
|
+import org.elasticsearch.compute.data.IntVector;
|
|
|
+$endif$
|
|
|
import org.elasticsearch.compute.data.$Type$Block;
|
|
|
import org.elasticsearch.compute.data.$Type$Vector;
|
|
|
+$if(double)$
|
|
|
+import org.elasticsearch.compute.data.IntVector;
|
|
|
+$endif$
|
|
|
import org.elasticsearch.core.Releasables;
|
|
|
|
|
|
-import java.lang.invoke.MethodHandles;
|
|
|
-import java.lang.invoke.VarHandle;
|
|
|
-import java.nio.ByteOrder;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
/**
|
|
|
* Aggregator state for an array of $type$s.
|
|
|
* This class is generated. Do not edit it.
|
|
@@ -123,9 +125,23 @@ $endif$
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** Extracts an intermediate view of the contents of this state. */
|
|
|
+ void toIntermediate(Block[] blocks, int offset, IntVector selected) {
|
|
|
+ assert blocks.length >= offset + 2;
|
|
|
+ var valuesBuilder = $Type$Block.newBlockBuilder(selected.getPositionCount());
|
|
|
+ var nullsBuilder = BooleanBlock.newBlockBuilder(selected.getPositionCount());
|
|
|
+ for (int i = 0; i < selected.getPositionCount(); i++) {
|
|
|
+ int group = selected.getInt(i);
|
|
|
+ valuesBuilder.append$Type$(values.get(group));
|
|
|
+ nullsBuilder.appendBoolean(hasValue(group));
|
|
|
+ }
|
|
|
+ blocks[offset + 0] = valuesBuilder.build();
|
|
|
+ blocks[offset + 1] = nullsBuilder.build();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public long getEstimatedSize() {
|
|
|
- return Long.BYTES + (largestIndex + 1L) * $BYTES$ + LongArrayState.estimateSerializeSize(nonNulls);
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -135,80 +151,6 @@ $endif$
|
|
|
|
|
|
@Override
|
|
|
public AggregatorStateSerializer<$Type$ArrayState> serializer() {
|
|
|
- return new $Type$ArrayStateSerializer();
|
|
|
- }
|
|
|
-
|
|
|
-$if(long)$
|
|
|
- private static final VarHandle longHandle = MethodHandles.byteArrayViewVarHandle(long[].class, ByteOrder.BIG_ENDIAN);
|
|
|
-
|
|
|
- static int serializeBitArray(BitArray bits, byte[] ba, int offset) {
|
|
|
- if (bits == null) {
|
|
|
- longHandle.set(ba, offset, 0);
|
|
|
- return Long.BYTES;
|
|
|
- }
|
|
|
- final LongArray array = bits.getBits();
|
|
|
- longHandle.set(ba, offset, array.size());
|
|
|
- offset += Long.BYTES;
|
|
|
- for (long i = 0; i < array.size(); i++) {
|
|
|
- longHandle.set(ba, offset, array.get(i));
|
|
|
- }
|
|
|
- return Long.BYTES + Math.toIntExact(array.size() * Long.BYTES);
|
|
|
- }
|
|
|
-
|
|
|
- static BitArray deseralizeBitArray(BigArrays bigArrays, byte[] ba, int offset) {
|
|
|
- long size = (long) longHandle.get(ba, offset);
|
|
|
- if (size == 0) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- offset += Long.BYTES;
|
|
|
- final LongArray array = bigArrays.newLongArray(size);
|
|
|
- for (long i = 0; i < size; i++) {
|
|
|
- array.set(i, (long) longHandle.get(ba, offset));
|
|
|
- }
|
|
|
- return new BitArray(bigArrays, array);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- static int estimateSerializeSize(BitArray bits) {
|
|
|
- if (bits == null) {
|
|
|
- return Long.BYTES;
|
|
|
- }
|
|
|
- return Long.BYTES + Math.toIntExact(bits.getBits().size() * Long.BYTES);
|
|
|
- }
|
|
|
-$endif$
|
|
|
-
|
|
|
- private static class $Type$ArrayStateSerializer implements AggregatorStateSerializer<$Type$ArrayState> {
|
|
|
- private static final VarHandle lengthHandle = MethodHandles.byteArrayViewVarHandle(long[].class, ByteOrder.BIG_ENDIAN);
|
|
|
- private static final VarHandle valueHandle = MethodHandles.byteArrayViewVarHandle($type$[].class, ByteOrder.BIG_ENDIAN);
|
|
|
-
|
|
|
- @Override
|
|
|
- public int size() {
|
|
|
- return $BYTES$;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int serialize($Type$ArrayState state, byte[] ba, int offset, org.elasticsearch.compute.data.IntVector selected) {
|
|
|
- lengthHandle.set(ba, offset, selected.getPositionCount());
|
|
|
- offset += Long.BYTES;
|
|
|
- for (int i = 0; i < selected.getPositionCount(); i++) {
|
|
|
- valueHandle.set(ba, offset, state.values.get(selected.getInt(i)));
|
|
|
- offset += $BYTES$;
|
|
|
- }
|
|
|
- final int valuesBytes = Long.BYTES + ($BYTES$ * selected.getPositionCount());
|
|
|
- return valuesBytes + LongArrayState.serializeBitArray(state.nonNulls, ba, offset);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void deserialize($Type$ArrayState state, byte[] ba, int offset) {
|
|
|
- Objects.requireNonNull(state);
|
|
|
- int positions = (int) (long) lengthHandle.get(ba, offset);
|
|
|
- offset += Long.BYTES;
|
|
|
- for (int i = 0; i < positions; i++) {
|
|
|
- state.set(($type$) valueHandle.get(ba, offset), i);
|
|
|
- offset += $BYTES$;
|
|
|
- }
|
|
|
- state.largestIndex = positions - 1;
|
|
|
- state.nonNulls = LongArrayState.deseralizeBitArray(state.bigArrays, ba, offset);
|
|
|
- }
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
}
|
|
|
}
|