public static PlanNodeStatsEstimate computeSemiJoin(PlanNodeStatsEstimate sourceStats, PlanNodeStatsEstimate filteringSourceStats, Symbol sourceJoinSymbol, Symbol filteringSourceJoinSymbol) { return compute(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol, (sourceJoinSymbolStats, filteringSourceJoinSymbolStats) -> min(filteringSourceJoinSymbolStats.getDistinctValuesCount(), sourceJoinSymbolStats.getDistinctValuesCount())); }
factor = Double.min(factor, 1.0d); if (!allColsFilteredByStats) { factor = Double.max(factor, HiveConf.getFloatVar(aspCtx.getConf(), HiveConf.ConfVars.HIVE_STATS_IN_MIN_RATIO));
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(); }
/** * 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(); }
double subsetNullsCount = subsetSymbolStats.getNullsFraction() * subsetRowCount; double newNullsCount = max(supersetNullsCount - subsetNullsCount, 0); newSymbolStats.setNullsFraction(min(newNullsCount, outputRowCount) / outputRowCount);
@Override public double applyAsDouble(double operand) { return Double.min(min,operand); } }
@Override public double applyAsDouble(double operand) { return Double.min(min,operand); } }
@Override public double applyAsDouble(double operand) { return Double.min(min,operand); } }
@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 min(double newValue) { while (true) { long oldBits = this.number.get(); double oldValue = Double.longBitsToDouble(oldBits); long newBits = Double.doubleToLongBits(Double.min(oldValue, newValue)); if (this.number.compareAndSet(oldBits, newBits)) { return; } } } }
void min(double newValue) { while (true) { long oldBits = this.number.get(); double oldValue = Double.longBitsToDouble(oldBits); long newBits = Double.doubleToLongBits(Double.min(oldValue, newValue)); if (this.number.compareAndSet(oldBits, newBits)) { return; } } } }
public static PlanNodeStatsEstimate computeSemiJoin(PlanNodeStatsEstimate sourceStats, PlanNodeStatsEstimate filteringSourceStats, Symbol sourceJoinSymbol, Symbol filteringSourceJoinSymbol) { return compute(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol, (sourceJoinSymbolStats, filteringSourceJoinSymbolStats) -> min(filteringSourceJoinSymbolStats.getDistinctValuesCount(), sourceJoinSymbolStats.getDistinctValuesCount())); }
/** * Creates a BinaryOperator to calculate the minimum Quantity * * @return the min BinaryOperator, not null. */ public static <Q extends Quantity<Q>> BinaryOperator<Quantity<Q>> min() { return (q1, q2) -> { double d1 = q1.getValue().doubleValue(); double d2 = q2.to(q1.getUnit()).getValue().doubleValue(); double min = Double.min(d1, d2); if (min == d1) { return q1; } return q2; }; }
public static PlanNodeStatsEstimate computeSemiJoin(PlanNodeStatsEstimate sourceStats, PlanNodeStatsEstimate filteringSourceStats, Symbol sourceJoinSymbol, Symbol filteringSourceJoinSymbol) { return compute(sourceStats, filteringSourceStats, sourceJoinSymbol, filteringSourceJoinSymbol, (sourceJoinSymbolStats, filteringSourceJoinSymbolStats) -> min(filteringSourceJoinSymbolStats.getDistinctValuesCount(), sourceJoinSymbolStats.getDistinctValuesCount())); }
/** * Creates a BinaryOperator to calculate the minimum Quantity * * @return the min BinaryOperator, not null. */ public static <Q extends Quantity<Q>> BinaryOperator<Quantity<Q>> min() { return (q1, q2) -> { double d1 = q1.getValue().doubleValue(); double d2 = q2.to(q1.getUnit()).getValue().doubleValue(); double min = Double.min(d1, d2); if (min == d1) { return q1; } return q2; }; }
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 PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) { if (damage < minDamage) return PowerResult.noop(); if (!checkCooldown(this, player, cooldown, true, true)) return PowerResult.cd(); if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); if (entity.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE)) { PotionEffect e = entity.getPotionEffect(PotionEffectType.DAMAGE_RESISTANCE); if (e.getAmplifier() >= 4) return PowerResult.noop(); } Context.instance().putExpiringSeconds(player.getUniqueId(), "realdamage.target", entity, 3); double health = entity.getHealth(); double newHealth = health - realDamage; newHealth = max(newHealth, 0.1);//Bug workaround newHealth = min(newHealth, entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); entity.setHealth(newHealth); return PowerResult.ok(damage); }
@Override public PowerResult<Void> tick(Player player, ItemStack stack) { if (!checkCooldownByString(this, player, "potiontick." + effect.getName(), interval, false, true)) return PowerResult.cd(); if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); double health = player.getHealth(); boolean hasEffect = false; for (PotionEffect potionEffect : player.getActivePotionEffects()) { if (potionEffect.getType().equals(effect)) { hasEffect = true; if (clear) { player.removePotionEffect(effect); } else if (potionEffect.getDuration() <= 5 || potionEffect.getAmplifier() < amplifier) player.addPotionEffect(new PotionEffect(effect, duration, amplifier, true), true); break; } } if (!hasEffect && !clear) { player.addPotionEffect(new PotionEffect(effect, duration, amplifier, true), true); } if (effect.equals(PotionEffectType.HEALTH_BOOST) && health > 0) { health = min(health, player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); player.setHealth(health); } return PowerResult.ok(); }