|
@@ -0,0 +1,206 @@
|
|
|
+// 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.aggregation;
|
|
|
+
|
|
|
+import java.lang.Integer;
|
|
|
+import java.lang.Override;
|
|
|
+import java.lang.String;
|
|
|
+import java.lang.StringBuilder;
|
|
|
+import java.util.List;
|
|
|
+import org.elasticsearch.compute.data.Block;
|
|
|
+import org.elasticsearch.compute.data.BooleanBlock;
|
|
|
+import org.elasticsearch.compute.data.BooleanVector;
|
|
|
+import org.elasticsearch.compute.data.ElementType;
|
|
|
+import org.elasticsearch.compute.data.IntBlock;
|
|
|
+import org.elasticsearch.compute.data.IntVector;
|
|
|
+import org.elasticsearch.compute.data.Page;
|
|
|
+import org.elasticsearch.compute.operator.DriverContext;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@link GroupingAggregatorFunction} implementation for {@link MinBooleanAggregator}.
|
|
|
+ * This class is generated. Do not edit it.
|
|
|
+ */
|
|
|
+public final class MinBooleanGroupingAggregatorFunction implements GroupingAggregatorFunction {
|
|
|
+ private static final List<IntermediateStateDesc> INTERMEDIATE_STATE_DESC = List.of(
|
|
|
+ new IntermediateStateDesc("min", ElementType.BOOLEAN),
|
|
|
+ new IntermediateStateDesc("seen", ElementType.BOOLEAN) );
|
|
|
+
|
|
|
+ private final BooleanArrayState state;
|
|
|
+
|
|
|
+ private final List<Integer> channels;
|
|
|
+
|
|
|
+ private final DriverContext driverContext;
|
|
|
+
|
|
|
+ public MinBooleanGroupingAggregatorFunction(List<Integer> channels, BooleanArrayState state,
|
|
|
+ DriverContext driverContext) {
|
|
|
+ this.channels = channels;
|
|
|
+ this.state = state;
|
|
|
+ this.driverContext = driverContext;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static MinBooleanGroupingAggregatorFunction create(List<Integer> channels,
|
|
|
+ DriverContext driverContext) {
|
|
|
+ return new MinBooleanGroupingAggregatorFunction(channels, new BooleanArrayState(driverContext.bigArrays(), MinBooleanAggregator.init()), driverContext);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<IntermediateStateDesc> intermediateStateDesc() {
|
|
|
+ return INTERMEDIATE_STATE_DESC;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int intermediateBlockCount() {
|
|
|
+ return INTERMEDIATE_STATE_DESC.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GroupingAggregatorFunction.AddInput prepareProcessPage(SeenGroupIds seenGroupIds,
|
|
|
+ Page page) {
|
|
|
+ BooleanBlock valuesBlock = page.getBlock(channels.get(0));
|
|
|
+ BooleanVector valuesVector = valuesBlock.asVector();
|
|
|
+ if (valuesVector == null) {
|
|
|
+ if (valuesBlock.mayHaveNulls()) {
|
|
|
+ state.enableGroupIdTracking(seenGroupIds);
|
|
|
+ }
|
|
|
+ return new GroupingAggregatorFunction.AddInput() {
|
|
|
+ @Override
|
|
|
+ public void add(int positionOffset, IntBlock groupIds) {
|
|
|
+ addRawInput(positionOffset, groupIds, valuesBlock);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(int positionOffset, IntVector groupIds) {
|
|
|
+ addRawInput(positionOffset, groupIds, valuesBlock);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return new GroupingAggregatorFunction.AddInput() {
|
|
|
+ @Override
|
|
|
+ public void add(int positionOffset, IntBlock groupIds) {
|
|
|
+ addRawInput(positionOffset, groupIds, valuesVector);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(int positionOffset, IntVector groupIds) {
|
|
|
+ addRawInput(positionOffset, groupIds, valuesVector);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addRawInput(int positionOffset, IntVector groups, BooleanBlock values) {
|
|
|
+ for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) {
|
|
|
+ int groupId = Math.toIntExact(groups.getInt(groupPosition));
|
|
|
+ if (values.isNull(groupPosition + positionOffset)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int valuesStart = values.getFirstValueIndex(groupPosition + positionOffset);
|
|
|
+ int valuesEnd = valuesStart + values.getValueCount(groupPosition + positionOffset);
|
|
|
+ for (int v = valuesStart; v < valuesEnd; v++) {
|
|
|
+ state.set(groupId, MinBooleanAggregator.combine(state.getOrDefault(groupId), values.getBoolean(v)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addRawInput(int positionOffset, IntVector groups, BooleanVector values) {
|
|
|
+ for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) {
|
|
|
+ int groupId = Math.toIntExact(groups.getInt(groupPosition));
|
|
|
+ state.set(groupId, MinBooleanAggregator.combine(state.getOrDefault(groupId), values.getBoolean(groupPosition + positionOffset)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addRawInput(int positionOffset, IntBlock groups, BooleanBlock values) {
|
|
|
+ for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) {
|
|
|
+ if (groups.isNull(groupPosition)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int groupStart = groups.getFirstValueIndex(groupPosition);
|
|
|
+ int groupEnd = groupStart + groups.getValueCount(groupPosition);
|
|
|
+ for (int g = groupStart; g < groupEnd; g++) {
|
|
|
+ int groupId = Math.toIntExact(groups.getInt(g));
|
|
|
+ if (values.isNull(groupPosition + positionOffset)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int valuesStart = values.getFirstValueIndex(groupPosition + positionOffset);
|
|
|
+ int valuesEnd = valuesStart + values.getValueCount(groupPosition + positionOffset);
|
|
|
+ for (int v = valuesStart; v < valuesEnd; v++) {
|
|
|
+ state.set(groupId, MinBooleanAggregator.combine(state.getOrDefault(groupId), values.getBoolean(v)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addRawInput(int positionOffset, IntBlock groups, BooleanVector values) {
|
|
|
+ for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) {
|
|
|
+ if (groups.isNull(groupPosition)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int groupStart = groups.getFirstValueIndex(groupPosition);
|
|
|
+ int groupEnd = groupStart + groups.getValueCount(groupPosition);
|
|
|
+ for (int g = groupStart; g < groupEnd; g++) {
|
|
|
+ int groupId = Math.toIntExact(groups.getInt(g));
|
|
|
+ state.set(groupId, MinBooleanAggregator.combine(state.getOrDefault(groupId), values.getBoolean(groupPosition + positionOffset)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addIntermediateInput(int positionOffset, IntVector groups, Page page) {
|
|
|
+ state.enableGroupIdTracking(new SeenGroupIds.Empty());
|
|
|
+ assert channels.size() == intermediateBlockCount();
|
|
|
+ Block minUncast = page.getBlock(channels.get(0));
|
|
|
+ if (minUncast.areAllValuesNull()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BooleanVector min = ((BooleanBlock) minUncast).asVector();
|
|
|
+ Block seenUncast = page.getBlock(channels.get(1));
|
|
|
+ if (seenUncast.areAllValuesNull()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BooleanVector seen = ((BooleanBlock) seenUncast).asVector();
|
|
|
+ assert min.getPositionCount() == seen.getPositionCount();
|
|
|
+ for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) {
|
|
|
+ int groupId = Math.toIntExact(groups.getInt(groupPosition));
|
|
|
+ if (seen.getBoolean(groupPosition + positionOffset)) {
|
|
|
+ state.set(groupId, MinBooleanAggregator.combine(state.getOrDefault(groupId), min.getBoolean(groupPosition + positionOffset)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addIntermediateRowInput(int groupId, GroupingAggregatorFunction input, int position) {
|
|
|
+ if (input.getClass() != getClass()) {
|
|
|
+ throw new IllegalArgumentException("expected " + getClass() + "; got " + input.getClass());
|
|
|
+ }
|
|
|
+ BooleanArrayState inState = ((MinBooleanGroupingAggregatorFunction) input).state;
|
|
|
+ state.enableGroupIdTracking(new SeenGroupIds.Empty());
|
|
|
+ if (inState.hasValue(position)) {
|
|
|
+ state.set(groupId, MinBooleanAggregator.combine(state.getOrDefault(groupId), inState.get(position)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void evaluateIntermediate(Block[] blocks, int offset, IntVector selected) {
|
|
|
+ state.toIntermediate(blocks, offset, selected, driverContext);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void evaluateFinal(Block[] blocks, int offset, IntVector selected,
|
|
|
+ DriverContext driverContext) {
|
|
|
+ blocks[offset] = state.toValuesBlock(selected, driverContext);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append(getClass().getSimpleName()).append("[");
|
|
|
+ sb.append("channels=").append(channels);
|
|
|
+ sb.append("]");
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void close() {
|
|
|
+ state.close();
|
|
|
+ }
|
|
|
+}
|