Skip to content
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 @@ -683,7 +683,7 @@ private static void testAssigner(
hostRequirement = Optional.of(hostAddress);
break;
}
else if (currentAssignment.getSplits().size() < splitCount) {
if (currentAssignment.getSplits().size() < splitCount) {
splitCount = currentAssignment.getSplits().size();
hostRequirement = Optional.of(hostAddress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.google.common.collect.ImmutableList;
import io.trino.metadata.Split;
import io.trino.spi.HostAddress;
import io.trino.spi.SplitWeight;
import io.trino.spi.connector.ConnectorSplit;

import java.util.List;
Expand All @@ -38,19 +37,12 @@ class TestingConnectorSplit
private final int id;
private final OptionalInt bucket;
private final Optional<List<HostAddress>> addresses;
private final SplitWeight weight;

public TestingConnectorSplit(int id, OptionalInt bucket, Optional<List<HostAddress>> addresses)
{
this(id, bucket, addresses, SplitWeight.standard().getRawValue());
}

public TestingConnectorSplit(int id, OptionalInt bucket, Optional<List<HostAddress>> addresses, long weight)
{
this.id = id;
this.bucket = requireNonNull(bucket, "bucket is null");
this.addresses = addresses.map(ImmutableList::copyOf);
this.weight = SplitWeight.fromRawValue(weight);
}

public int getId()
Expand All @@ -75,12 +67,6 @@ public List<HostAddress> getAddresses()
return addresses.orElse(ImmutableList.of());
}

@Override
public SplitWeight getSplitWeight()
{
return weight;
}

@Override
public Object getInfo()
{
Expand All @@ -105,13 +91,13 @@ public boolean equals(Object o)
return false;
}
TestingConnectorSplit that = (TestingConnectorSplit) o;
return id == that.id && weight == that.weight && Objects.equals(bucket, that.bucket) && Objects.equals(addresses, that.addresses);
return id == that.id && Objects.equals(bucket, that.bucket) && Objects.equals(addresses, that.addresses);
}

@Override
public int hashCode()
{
return Objects.hash(id, bucket, addresses, weight);
return Objects.hash(id, bucket, addresses);
}

@Override
Expand All @@ -121,7 +107,6 @@ public String toString()
.add("id", id)
.add("bucket", bucket)
.add("addresses", addresses)
.add("weight", weight)
.toString();
}

Expand Down
12 changes: 9 additions & 3 deletions core/trino-spi/src/main/java/io/trino/spi/SplitWeight.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.google.errorprone.annotations.DoNotCall;

import java.math.BigDecimal;
import java.util.Collection;
Expand Down Expand Up @@ -82,10 +83,10 @@ public String toString()
* to avoid breakages that could arise if {@link SplitWeight#UNIT_VALUE} changes in the future.
*/
@JsonCreator
// TODO Mark with @DoNotCall
@DoNotCall // For JSON serialization only
public static SplitWeight fromRawValue(long value)
{
return value == UNIT_VALUE ? STANDARD_WEIGHT : new SplitWeight(value);
return fromRawValueInternal(value);
}

/**
Expand All @@ -105,7 +106,12 @@ public static SplitWeight fromProportion(double weight)
throw new IllegalArgumentException("Invalid weight: " + weight);
}
// Must round up to avoid small weights rounding to 0
return fromRawValue((long) Math.ceil(weight * UNIT_VALUE));
return fromRawValueInternal((long) Math.ceil(weight * UNIT_VALUE));
}

private static SplitWeight fromRawValueInternal(long value)
{
return value == UNIT_VALUE ? STANDARD_WEIGHT : new SplitWeight(value);
}

public static SplitWeight standard()
Expand Down