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

Enable NarrowingCompoundAssignment error-prone check #18466

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 @@ -164,7 +164,7 @@ private String hexAV()
break;
}
else if (chars[pos] >= 'A' && chars[pos] <= 'F') {
chars[pos] += 32; //to low case
chars[pos] += (char) 32; // to low case
}

pos++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public class BasicStageStats
private final long internalNetworkInputPositions;
private final DataSize rawInputDataSize;
private final long rawInputPositions;
private final long cumulativeUserMemory;
private final long failedCumulativeUserMemory;
private final double cumulativeUserMemory;
private final double failedCumulativeUserMemory;
private final DataSize userMemoryReservation;
private final DataSize totalMemoryReservation;
private final Duration totalCpuTime;
Expand Down Expand Up @@ -111,8 +111,8 @@ public BasicStageStats(
DataSize rawInputDataSize,
long rawInputPositions,

long cumulativeUserMemory,
long failedCumulativeUserMemory,
double cumulativeUserMemory,
double failedCumulativeUserMemory,
DataSize userMemoryReservation,
DataSize totalMemoryReservation,

Expand Down Expand Up @@ -219,12 +219,12 @@ public Duration getPhysicalInputReadTime()
return physicalInputReadTime;
}

public long getCumulativeUserMemory()
public double getCumulativeUserMemory()
{
return cumulativeUserMemory;
}

public long getFailedCumulativeUserMemory()
public double getFailedCumulativeUserMemory()
{
return failedCumulativeUserMemory;
}
Expand Down Expand Up @@ -288,8 +288,8 @@ public static BasicStageStats aggregateBasicStageStats(Iterable<BasicStageStats>
int runningDrivers = 0;
int completedDrivers = 0;

long cumulativeUserMemory = 0;
long failedCumulativeUserMemory = 0;
double cumulativeUserMemory = 0;
double failedCumulativeUserMemory = 0;
long userMemoryReservation = 0;
long totalMemoryReservation = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ private QueryStats getQueryStats(Optional<StageInfo> rootStage, List<StageInfo>
int blockedDrivers = 0;
int completedDrivers = 0;

long cumulativeUserMemory = 0;
long failedCumulativeUserMemory = 0;
double cumulativeUserMemory = 0;
double failedCumulativeUserMemory = 0;
long userMemoryReservation = 0;
long revocableMemoryReservation = 0;
long totalMemoryReservation = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ public BasicStageStats getBasicStageStats(Supplier<Iterable<TaskInfo>> taskInfos
int runningDrivers = 0;
int completedDrivers = 0;

long cumulativeUserMemory = 0;
long failedCumulativeUserMemory = 0;
double cumulativeUserMemory = 0;
double failedCumulativeUserMemory = 0;
long userMemoryReservation = 0;
long totalMemoryReservation = 0;

Expand Down Expand Up @@ -416,8 +416,8 @@ public StageInfo getStageInfo(Supplier<Iterable<TaskInfo>> taskInfosSupplier)
int blockedDrivers = 0;
int completedDrivers = 0;

long cumulativeUserMemory = 0;
long failedCumulativeUserMemory = 0;
double cumulativeUserMemory = 0;
double failedCumulativeUserMemory = 0;
long userMemoryReservation = currentUserMemory.get();
long revocableMemoryReservation = currentRevocableMemory.get();
long totalMemoryReservation = currentTotalMemory.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.math.DoubleMath.roundToLong;
import static java.math.RoundingMode.HALF_UP;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;

Expand Down Expand Up @@ -169,7 +171,7 @@ private PrioritizedSplitRunner pollSplit()
}
}

targetScheduledTime /= levelTimeMultiplier;
targetScheduledTime = roundToLong(targetScheduledTime / levelTimeMultiplier, HALF_UP);
}

if (selectedLevel == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private static void verifyMethodHandleSignature(BoundSignature boundSignature, S
checkArgument(convention.getArgumentConventions().size() == boundSignature.getArgumentTypes().size(),
"Expected %s arguments, but got %s", boundSignature.getArgumentTypes().size(), convention.getArgumentConventions().size());

int expectedParameterCount = convention.getArgumentConventions().stream()
long expectedParameterCount = convention.getArgumentConventions().stream()
.mapToInt(InvocationArgumentConvention::getParameterCount)
.sum();
expectedParameterCount += methodType.parameterList().stream().filter(ConnectorSession.class::equals).count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.primitives.Shorts;
import io.trino.spi.Page;
import io.trino.spi.PageBuilder;
import io.trino.spi.TrinoException;
Expand Down Expand Up @@ -1007,10 +1008,10 @@ private int calculatePositionToCombinationIdMapping(Page page, short[] positionT
}
else {
for (int position = 0; position < positionToCombinationIds.length; position++) {
short combinationId = positionToCombinationIds[position];
int combinationId = positionToCombinationIds[position];
combinationId *= dictionarySize;
combinationId += dictionaryBlock.getId(position);
positionToCombinationIds[position] = combinationId;
positionToCombinationIds[position] = Shorts.checkedCast(combinationId);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import java.util.List;

import static com.google.common.base.Verify.verify;
import static com.google.common.math.DoubleMath.roundToLong;
import static io.airlift.slice.SizeOf.instanceSize;
import static java.math.RoundingMode.HALF_UP;

/**
* Instances of this state use a single PageBuilder for all groups.
Expand Down Expand Up @@ -125,7 +127,7 @@ protected final void prepareAdd()
int insertedPosition = currentPageBuilder.getPositionCount();

if (totalPositions == capacity) {
capacity *= 1.5;
capacity = roundToLong(capacity * 1.5, HALF_UP);
nextBlockIndex.ensureCapacity(capacity);
nextPosition.ensureCapacity(capacity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class LookupJoinPageBuilder
private final IntArrayList probeIndexBuilder = new IntArrayList();
private final PageBuilder buildPageBuilder;
private final int buildOutputChannelCount;
private int estimatedProbeBlockBytes;
private int estimatedProbeRowSize = -1;
private long estimatedProbeBlockBytes;
private long estimatedProbeRowSize = -1;
private int previousPosition = -1;
private boolean isSequentialProbeIndices = true;

Expand Down Expand Up @@ -196,13 +196,13 @@ private void appendProbeIndex(JoinProbe probe)
}
}

private int getEstimatedProbeRowSize(JoinProbe probe)
private long getEstimatedProbeRowSize(JoinProbe probe)
{
if (estimatedProbeRowSize != -1) {
return estimatedProbeRowSize;
}

int estimatedProbeRowSize = 0;
long estimatedProbeRowSize = 0;
for (int index : probe.getOutputChannels()) {
Block block = probe.getPage().getBlock(index);
// Estimate the size of the probe row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class LookupJoinPageBuilder
private final IntArrayList probeIndexBuilder = new IntArrayList();
private final PageBuilder buildPageBuilder;
private final int buildOutputChannelCount;
private int estimatedProbeBlockBytes;
private int estimatedProbeRowSize = -1;
private long estimatedProbeBlockBytes;
private long estimatedProbeRowSize = -1;
private int previousPosition = -1;
private boolean isSequentialProbeIndices = true;
private boolean repeatBuildRow;
Expand Down Expand Up @@ -242,13 +242,13 @@ private void appendProbeIndex(JoinProbe probe)
}
}

private int getEstimatedProbeRowSize(JoinProbe probe)
private long getEstimatedProbeRowSize(JoinProbe probe)
{
if (estimatedProbeRowSize != -1) {
return estimatedProbeRowSize;
}

int estimatedProbeRowSize = 0;
long estimatedProbeRowSize = 0;
for (int index : probe.getOutputChannels()) {
Block block = probe.getPage().getBlock(index);
// Estimate the size of the probe row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private ProcessBatchResult processBatch(int batchSize)
{
Block[] blocks = new Block[projections.size()];

int pageSize = 0;
long pageSize = 0;
SelectedPositions positionsBatch = selectedPositions.subRange(0, batchSize);
for (int i = 0; i < projections.size(); i++) {
if (yieldSignal.isSet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static Block sequenceDateYearToMonth(

BlockBuilder blockBuilder = DATE.createBlockBuilder(null, length);

int value = 0;
long value = 0;
for (int i = 0; i < length; ++i) {
DATE.writeLong(blockBuilder, DateTimeOperators.datePlusIntervalYearToMonth(start, value));
value += step;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static Block sequence(

BlockBuilder blockBuilder = SHORT_TYPE.createBlockBuilder(null, length);

int offset = 0;
long offset = 0;
for (int i = 0; i < length; ++i) {
long value = TimestampPlusIntervalYearToMonth.add(start, offset);
SHORT_TYPE.writeLong(blockBuilder, value);
Expand All @@ -79,7 +79,7 @@ public static Block sequence(

BlockBuilder blockBuilder = LONG_TYPE.createBlockBuilder(null, length);

int offset = 0;
long offset = 0;
for (int i = 0; i < length; ++i) {
LongTimestamp value = TimestampPlusIntervalYearToMonth.add(start, offset);
LONG_TYPE.writeObject(blockBuilder, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import static com.google.common.math.DoubleMath.roundToLong;
import static io.trino.server.security.ResourceSecurity.AccessType.WEB_UI;
import static java.math.RoundingMode.HALF_UP;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.SECONDS;

Expand Down Expand Up @@ -91,7 +93,7 @@ else if (query.getState() == QueryState.RUNNING) {
if (!query.getState().isDone()) {
totalInputBytes += query.getQueryStats().getRawInputDataSize().toBytes();
totalInputRows += query.getQueryStats().getRawInputPositions();
totalCpuTimeSecs += query.getQueryStats().getTotalCpuTime().getValue(SECONDS);
totalCpuTimeSecs += roundToLong(query.getQueryStats().getTotalCpuTime().getValue(SECONDS), HALF_UP);

memoryReservation += query.getQueryStats().getUserMemoryReservation().toBytes();
runningDrivers += query.getQueryStats().getRunningDrivers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static io.trino.spi.type.Timestamps.PICOSECONDS_PER_MILLISECOND;
import static io.trino.spi.type.Timestamps.rescale;
import static io.trino.spi.type.TypeOperatorDeclaration.extractOperatorDeclaration;
import static java.lang.Math.toIntExact;
import static java.lang.String.format;
import static java.lang.invoke.MethodHandles.lookup;

Expand Down Expand Up @@ -151,7 +152,7 @@ public Optional<Object> getPreviousValue(Object value)
LongTimestampWithTimeZone timestampWithTimeZone = (LongTimestampWithTimeZone) value;
long epochMillis = timestampWithTimeZone.getEpochMillis();
int picosOfMilli = timestampWithTimeZone.getPicosOfMilli();
picosOfMilli -= rescale(1, 0, 12 - getPrecision());
picosOfMilli -= toIntExact(rescale(1, 0, 12 - getPrecision()));
if (picosOfMilli < 0) {
if (epochMillis == Long.MIN_VALUE) {
return Optional.empty();
Expand All @@ -169,7 +170,7 @@ public Optional<Object> getNextValue(Object value)
LongTimestampWithTimeZone timestampWithTimeZone = (LongTimestampWithTimeZone) value;
long epochMillis = timestampWithTimeZone.getEpochMillis();
int picosOfMilli = timestampWithTimeZone.getPicosOfMilli();
picosOfMilli += rescale(1, 0, 12 - getPrecision());
picosOfMilli += toIntExact(rescale(1, 0, 12 - getPrecision()));
if (picosOfMilli >= PICOSECONDS_PER_MILLISECOND) {
if (epochMillis == Long.MAX_VALUE) {
return Optional.empty();
Expand Down
5 changes: 5 additions & 0 deletions lib/trino-array/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
</properties>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>slice</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.array;

import com.google.common.primitives.Shorts;
import io.airlift.slice.SizeOf;

import java.util.Arrays;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void increment(long index)
*/
public void add(long index, long value)
{
array[segment(index)][offset(index)] += value;
array[segment(index)][offset(index)] += Shorts.checkedCast(value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void testInputFile()

// skip 1MB at a time
inputStream.seek(0);
int expectedPosition = 0;
long expectedPosition = 0;
for (int i = 0; i < 15; i++) {
long skipSize = inputStream.skip(MEGABYTE);
assertThat(skipSize).isEqualTo(MEGABYTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public long skip(long length)
int availableBytes = availableBytes();
// is skip within the current buffer?
if (availableBytes >= length) {
bufferPosition += length;
bufferPosition = checkedCast(bufferPosition + length);
return length;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.hive.formats.encodings.binary;

import com.google.common.math.IntMath;
import io.airlift.slice.Slice;
import io.airlift.slice.SliceOutput;
import io.trino.hive.formats.ReadWriteUtils;
Expand Down Expand Up @@ -168,7 +169,7 @@ private static int decodeNanos(int nanos)
nanos = temp;

if (nanosDigits < 9) {
nanos *= Math.pow(10, 9 - nanosDigits);
nanos *= IntMath.pow(10, 9 - nanosDigits);
}
return nanos;
}
Expand Down
Loading