|
@@ -0,0 +1,202 @@
|
|
|
+// 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 TopBooleanAggregator}.
|
|
|
+ * This class is generated. Do not edit it.
|
|
|
+ */
|
|
|
+public final class TopBooleanGroupingAggregatorFunction implements GroupingAggregatorFunction {
|
|
|
+ private static final List<IntermediateStateDesc> INTERMEDIATE_STATE_DESC = List.of(
|
|
|
+ new IntermediateStateDesc("top", ElementType.BOOLEAN) );
|
|
|
+
|
|
|
+ private final TopBooleanAggregator.GroupingState state;
|
|
|
+
|
|
|
+ private final List<Integer> channels;
|
|
|
+
|
|
|
+ private final DriverContext driverContext;
|
|
|
+
|
|
|
+ private final int limit;
|
|
|
+
|
|
|
+ private final boolean ascending;
|
|
|
+
|
|
|
+ public TopBooleanGroupingAggregatorFunction(List<Integer> channels,
|
|
|
+ TopBooleanAggregator.GroupingState state, DriverContext driverContext, int limit,
|
|
|
+ boolean ascending) {
|
|
|
+ this.channels = channels;
|
|
|
+ this.state = state;
|
|
|
+ this.driverContext = driverContext;
|
|
|
+ this.limit = limit;
|
|
|
+ this.ascending = ascending;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static TopBooleanGroupingAggregatorFunction create(List<Integer> channels,
|
|
|
+ DriverContext driverContext, int limit, boolean ascending) {
|
|
|
+ return new TopBooleanGroupingAggregatorFunction(channels, TopBooleanAggregator.initGrouping(driverContext.bigArrays(), limit, ascending), driverContext, limit, ascending);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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++) {
|
|
|
+ TopBooleanAggregator.combine(state, 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));
|
|
|
+ TopBooleanAggregator.combine(state, 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++) {
|
|
|
+ TopBooleanAggregator.combine(state, 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));
|
|
|
+ TopBooleanAggregator.combine(state, 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 topUncast = page.getBlock(channels.get(0));
|
|
|
+ if (topUncast.areAllValuesNull()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BooleanBlock top = (BooleanBlock) topUncast;
|
|
|
+ for (int groupPosition = 0; groupPosition < groups.getPositionCount(); groupPosition++) {
|
|
|
+ int groupId = Math.toIntExact(groups.getInt(groupPosition));
|
|
|
+ TopBooleanAggregator.combineIntermediate(state, groupId, top, groupPosition + positionOffset);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addIntermediateRowInput(int groupId, GroupingAggregatorFunction input, int position) {
|
|
|
+ if (input.getClass() != getClass()) {
|
|
|
+ throw new IllegalArgumentException("expected " + getClass() + "; got " + input.getClass());
|
|
|
+ }
|
|
|
+ TopBooleanAggregator.GroupingState inState = ((TopBooleanGroupingAggregatorFunction) input).state;
|
|
|
+ state.enableGroupIdTracking(new SeenGroupIds.Empty());
|
|
|
+ TopBooleanAggregator.combineStates(state, groupId, inState, 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] = TopBooleanAggregator.evaluateFinal(state, 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();
|
|
|
+ }
|
|
|
+}
|