Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanups in aggregation functions #16751

Merged
merged 5 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ private DecimalAverageAggregation() {}
@LiteralParameters({"p", "s"})
public static void inputShortDecimal(
@AggregationState LongDecimalWithOverflowAndLongState state,
@BlockPosition @SqlType(value = "decimal(p, s)", nativeContainerType = long.class) Block block,
@BlockIndex int position)
@SqlType("decimal(p,s)") long rightLow)
{
state.addLong(1); // row counter

long[] decimal = state.getDecimalArray();
int offset = state.getDecimalArrayOffset();

long rightLow = block.getLong(position, 0);
long rightHigh = rightLow >> 63;

long overflow = addWithOverflow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import javax.annotation.Nullable;

import static io.airlift.slice.SizeOf.SIZE_OF_LONG;
import static io.airlift.slice.SizeOf.instanceSize;
import static io.airlift.slice.SizeOf.sizeOf;
import static java.lang.System.arraycopy;
Expand All @@ -38,7 +39,7 @@ public LongDecimalWithOverflowAndLongState createGroupedState()
return new GroupedLongDecimalWithOverflowAndLongState();
}

public static class GroupedLongDecimalWithOverflowAndLongState
private static final class GroupedLongDecimalWithOverflowAndLongState
extends AbstractGroupedAccumulatorState
implements LongDecimalWithOverflowAndLongState
{
Expand Down Expand Up @@ -135,11 +136,11 @@ public long getEstimatedSize()
}
}

public static class SingleLongDecimalWithOverflowAndLongState
private static final class SingleLongDecimalWithOverflowAndLongState
implements LongDecimalWithOverflowAndLongState
{
private static final int INSTANCE_SIZE = instanceSize(SingleLongDecimalWithOverflowAndLongState.class);
private static final int SIZE = (int) sizeOf(new long[2]);
private static final int SIZE = (int) sizeOf(new long[2]) + SIZE_OF_LONG + SIZE_OF_LONG;

private final long[] unscaledDecimal = new long[2];
private long longValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import javax.annotation.Nullable;

import static io.airlift.slice.SizeOf.SIZE_OF_BYTE;
import static io.airlift.slice.SizeOf.SIZE_OF_LONG;
import static io.airlift.slice.SizeOf.instanceSize;
import static io.airlift.slice.SizeOf.sizeOf;
import static java.lang.System.arraycopy;
Expand Down Expand Up @@ -134,7 +136,7 @@ public static class SingleLongDecimalWithOverflowState
implements LongDecimalWithOverflowState
{
private static final int INSTANCE_SIZE = instanceSize(SingleLongDecimalWithOverflowState.class);
private static final int SIZE = (int) sizeOf(new long[2]);
private static final int SIZE = (int) sizeOf(new long[2]) + SIZE_OF_BYTE + SIZE_OF_LONG;

private final long[] unscaledDecimal = new long[2];
private boolean isNotNull;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ private static void addToState(LongDecimalWithOverflowAndLongState state, BigInt

private static void addToState(DecimalType type, LongDecimalWithOverflowAndLongState state, BigInteger value)
{
BlockBuilder blockBuilder = type.createFixedSizeBlockBuilder(1);
type.writeObject(blockBuilder, Int128.valueOf(value));
if (type.isShort()) {
DecimalAverageAggregation.inputShortDecimal(state, blockBuilder.build(), 0);
DecimalAverageAggregation.inputShortDecimal(state, Int128.valueOf(value).toLongExact());
}
else {
BlockBuilder blockBuilder = type.createFixedSizeBlockBuilder(1);
type.writeObject(blockBuilder, Int128.valueOf(value));
DecimalAverageAggregation.inputLongDecimal(state, blockBuilder.build(), 0);
}
}
Expand Down