private static double computedStdDev(double sumSquared, double sum, long n) { double average = sum / n; double variance = (sumSquared - 2 * sum * average + average * average * n) / n; // variance might be negative because of numeric inaccuracy, therefore we need to use max return sqrt(max(variance, 0d)); }
private static double computedWeightedStdDev(double sumSquared, double sum, double totalWeight) { double average = sum / totalWeight; double variance = (sumSquared - 2 * sum * average) / totalWeight + average * average; // variance might be negative because of numeric inaccuracy, therefore we need to use max return sqrt(max(variance, 0d)); }
public static PlanNodeStatsEstimate computeAntiJoin(PlanNodeStatsEstimate sourceStats, PlanNodeStatsEstimate filteringSourceStats, Symbol sourceJoinSymbol, Symbol filteringSourceJoinSymbol) { return compute(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol, (sourceJoinSymbolStats, filteringSourceJoinSymbolStats) -> max(sourceJoinSymbolStats.getDistinctValuesCount() * MIN_ANTI_JOIN_FILTER_COEFFICIENT, sourceJoinSymbolStats.getDistinctValuesCount() - filteringSourceJoinSymbolStats.getDistinctValuesCount())); }
factor = Double.max(factor, HiveConf.getFloatVar(aspCtx.getConf(), HiveConf.ConfVars.HIVE_STATS_IN_MIN_RATIO));
double outputRowCount = max(supersetRowCount - subsetRowCount, 0); double newNullsCount = max(supersetNullsCount - subsetNullsCount, 0); newSymbolStats.setNullsFraction(min(newNullsCount, outputRowCount) / outputRowCount); double subsetValuesPerDistinctValue = subsetNonNullsCount / subsetDistinctValues; if (supersetValuesPerDistinctValue <= subsetValuesPerDistinctValue) { newDistinctValuesCount = max(supersetDistinctValues - subsetDistinctValues, 0);
/** * Creates a new region bounded by the two opposing locations. * @param from The first bounding corner. * @param to The second bounding corner. */ public RectangularRegion(Location from, Location to) { Preconditions.checkArgument( from.getWorld() == to.getWorld(), "The given locations do not have matching worlds." ); this.lowCorner = new Location( from.getWorld(), Double.min(from.getX(), to.getX()), Double.min(from.getY(), to.getY()), Double.min(from.getZ(), to.getZ()) ); this.highCorner = new Location( from.getWorld(), Double.max(from.getX(), to.getX()), Double.max(from.getY(), to.getY()), Double.max(from.getZ(), to.getZ()) ); this.widthX = highCorner.getBlockX() - lowCorner.getBlockX(); this.widthY = highCorner.getBlockY() - lowCorner.getBlockY(); this.widthZ = highCorner.getBlockZ() - lowCorner.getBlockZ(); }
public static PlanNodeStatsEstimate capStats(PlanNodeStatsEstimate stats, PlanNodeStatsEstimate cap) { if (stats.isOutputRowCountUnknown() || cap.isOutputRowCountUnknown()) { return PlanNodeStatsEstimate.unknown(); } PlanNodeStatsEstimate.Builder result = PlanNodeStatsEstimate.builder(); double cappedRowCount = min(stats.getOutputRowCount(), cap.getOutputRowCount()); result.setOutputRowCount(cappedRowCount); stats.getSymbolsWithKnownStatistics().forEach(symbol -> { SymbolStatsEstimate symbolStats = stats.getSymbolStatistics(symbol); SymbolStatsEstimate capSymbolStats = cap.getSymbolStatistics(symbol); SymbolStatsEstimate.Builder newSymbolStats = SymbolStatsEstimate.builder(); // for simplicity keep the average row size the same as in the input // in most cases the average row size doesn't change after applying filters newSymbolStats.setAverageRowSize(symbolStats.getAverageRowSize()); newSymbolStats.setDistinctValuesCount(min(symbolStats.getDistinctValuesCount(), capSymbolStats.getDistinctValuesCount())); newSymbolStats.setLowValue(max(symbolStats.getLowValue(), capSymbolStats.getLowValue())); newSymbolStats.setHighValue(min(symbolStats.getHighValue(), capSymbolStats.getHighValue())); double numberOfNulls = stats.getOutputRowCount() * symbolStats.getNullsFraction(); double capNumberOfNulls = cap.getOutputRowCount() * capSymbolStats.getNullsFraction(); double cappedNumberOfNulls = min(numberOfNulls, capNumberOfNulls); double cappedNullsFraction = cappedRowCount == 0 ? 1 : cappedNumberOfNulls / cappedRowCount; newSymbolStats.setNullsFraction(cappedNullsFraction); result.addSymbolStatistics(symbol, newSymbolStats.build()); }); return result.build(); }
@Override public double applyAsDouble(double operand) { return Double.max(max,operand); } }
@Override public double applyAsDouble(double operand) { return Double.max(max,operand); } }
@Override public double applyAsDouble(double operand) { return Double.max(max,operand); } }
private static double computedWeightedStdDev(double sumSquared, double sum, double totalWeight) { double average = sum / totalWeight; double variance = (sumSquared - 2 * sum * average) / totalWeight + average * average; // variance might be negative because of numeric inaccuracy, therefore we need to use max return sqrt(max(variance, 0d)); }
private static double computedWeightedStdDev(double sumSquared, double sum, double totalWeight) { double average = sum / totalWeight; double variance = (sumSquared - 2 * sum * average) / totalWeight + average * average; // variance might be negative because of numeric inaccuracy, therefore we need to use max return sqrt(max(variance, 0d)); }
private static double computedStdDev(double sumSquared, double sum, long n) { double average = sum / n; double variance = (sumSquared - 2 * sum * average + average * average * n) / n; // variance might be negative because of numeric inaccuracy, therefore we need to use max return sqrt(max(variance, 0d)); }
private static double computedStdDev(double sumSquared, double sum, long n) { double average = sum / n; double variance = (sumSquared - 2 * sum * average + average * average * n) / n; // variance might be negative because of numeric inaccuracy, therefore we need to use max return sqrt(max(variance, 0d)); }
@Override public double applyAsDouble(double operand) { return Double.min(max,Double.max(min,operand)); } }
@Override public double applyAsDouble(double operand) { return Double.min(max,Double.max(min,operand)); } }
void max(double newValue) { while (true) { long oldBits = this.number.get(); double oldValue = Double.longBitsToDouble(oldBits); long newBits = Double.doubleToLongBits(Double.max(oldValue, newValue)); if (this.number.compareAndSet(oldBits, newBits)) { return; } } }
void max(double newValue) { while (true) { long oldBits = this.number.get(); double oldValue = Double.longBitsToDouble(oldBits); long newBits = Double.doubleToLongBits(Double.max(oldValue, newValue)); if (this.number.compareAndSet(oldBits, newBits)) { return; } } }
public static PlanNodeStatsEstimate computeAntiJoin(PlanNodeStatsEstimate sourceStats, PlanNodeStatsEstimate filteringSourceStats, Symbol sourceJoinSymbol, Symbol filteringSourceJoinSymbol) { return compute(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol, (sourceJoinSymbolStats, filteringSourceJoinSymbolStats) -> max(sourceJoinSymbolStats.getDistinctValuesCount() * MIN_ANTI_JOIN_FILTER_COEFFICIENT, sourceJoinSymbolStats.getDistinctValuesCount() - filteringSourceJoinSymbolStats.getDistinctValuesCount())); }
public static PlanNodeStatsEstimate computeAntiJoin(PlanNodeStatsEstimate sourceStats, PlanNodeStatsEstimate filteringSourceStats, Symbol sourceJoinSymbol, Symbol filteringSourceJoinSymbol) { return compute(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol, (sourceJoinSymbolStats, filteringSourceJoinSymbolStats) -> max(sourceJoinSymbolStats.getDistinctValuesCount() * MIN_ANTI_JOIN_FILTER_COEFFICIENT, sourceJoinSymbolStats.getDistinctValuesCount() - filteringSourceJoinSymbolStats.getDistinctValuesCount())); }