com.facebook.presto.jdbc.internal.spi.statistics.PlanStatistics Maven / Gradle / Ivy
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.jdbc.internal.spi.statistics;
import com.facebook.presto.jdbc.internal.drift.annotations.ThriftConstructor;
import com.facebook.presto.jdbc.internal.drift.annotations.ThriftField;
import com.facebook.presto.jdbc.internal.drift.annotations.ThriftStruct;
import com.facebook.presto.jdbc.internal.jackson.annotation.JsonCreator;
import com.facebook.presto.jdbc.internal.jackson.annotation.JsonProperty;
import java.util.Objects;
import static java.util.Objects.requireNonNull;
@ThriftStruct
public class PlanStatistics
{
private static final PlanStatistics EMPTY = new PlanStatistics(Estimate.unknown(), Estimate.unknown(), 0);
private final Estimate rowCount;
private final Estimate outputSize;
// A number ranging between 0 and 1, reflecting our confidence in the statistics
private final double confidence;
public static PlanStatistics empty()
{
return EMPTY;
}
@JsonCreator
@ThriftConstructor
public PlanStatistics(@JsonProperty("rowCount") Estimate rowCount, @JsonProperty("outputSize") Estimate outputSize, @JsonProperty("confidence") double confidence)
{
this.rowCount = requireNonNull(rowCount, "rowCount is null");
this.outputSize = requireNonNull(outputSize, "outputSize is null");
checkArgument(confidence >= 0 && confidence <= 1, "confidence should be between 0 and 1");
this.confidence = confidence;
}
@JsonProperty
@ThriftField(1)
public Estimate getRowCount()
{
return rowCount;
}
@JsonProperty
@ThriftField(2)
public Estimate getOutputSize()
{
return outputSize;
}
@JsonProperty
@ThriftField(3)
public double getConfidence()
{
return confidence;
}
private static void checkArgument(boolean condition, String message)
{
if (!condition) {
throw new IllegalArgumentException(message);
}
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PlanStatistics that = (PlanStatistics) o;
return Double.compare(that.confidence, confidence) == 0 && Objects.equals(rowCount, that.rowCount) && Objects.equals(outputSize, that.outputSize);
}
@Override
public int hashCode()
{
return Objects.hash(rowCount, outputSize, confidence);
}
@Override
public String toString()
{
return "PlanStatistics{" +
"rowCount=" + rowCount +
", outputSize=" + outputSize +
", confidence=" + confidence +
'}';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy