-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Replace constants with static factory methods #11660
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
Changes from all commits
fa95ae8
9daf7d8
2ccb855
d77b5f6
e4360e6
3ab6145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,9 +26,28 @@ | |
|
|
||
| public final class PlanNodeCostEstimate | ||
| { | ||
| public static final PlanNodeCostEstimate INFINITE_COST = new PlanNodeCostEstimate(POSITIVE_INFINITY, POSITIVE_INFINITY, POSITIVE_INFINITY); | ||
| public static final PlanNodeCostEstimate UNKNOWN_COST = new PlanNodeCostEstimate(NaN, NaN, NaN); | ||
| public static final PlanNodeCostEstimate ZERO_COST = new PlanNodeCostEstimate(0, 0, 0); | ||
| private static final PlanNodeCostEstimate INFINITE = new PlanNodeCostEstimate(POSITIVE_INFINITY, POSITIVE_INFINITY, POSITIVE_INFINITY); | ||
| private static final PlanNodeCostEstimate UNKNOWN = new PlanNodeCostEstimate(NaN, NaN, NaN); | ||
| private static final PlanNodeCostEstimate ZERO = new PlanNodeCostEstimate(0, 0, 0); | ||
|
|
||
| private final double cpuCost; | ||
| private final double memoryCost; | ||
| private final double networkCost; | ||
|
||
|
|
||
| public static PlanNodeCostEstimate infinite() | ||
| { | ||
| return INFINITE; | ||
| } | ||
|
|
||
| public static PlanNodeCostEstimate unknown() | ||
| { | ||
| return UNKNOWN; | ||
| } | ||
|
|
||
| public static PlanNodeCostEstimate zero() | ||
| { | ||
| return ZERO; | ||
| } | ||
|
|
||
| public static PlanNodeCostEstimate cpuCost(double cpuCost) | ||
| { | ||
|
|
@@ -45,10 +64,6 @@ public static PlanNodeCostEstimate networkCost(double networkCost) | |
| return new PlanNodeCostEstimate(0, 0, networkCost); | ||
| } | ||
|
|
||
| private final double cpuCost; | ||
| private final double memoryCost; | ||
| private final double networkCost; | ||
|
|
||
| @JsonCreator | ||
| public PlanNodeCostEstimate( | ||
| @JsonProperty("cpuCost") double cpuCost, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,8 +30,6 @@ | |
| import java.util.Optional; | ||
| import java.util.function.Predicate; | ||
|
|
||
| import static com.facebook.presto.cost.SymbolStatsEstimate.UNKNOWN_STATS; | ||
| import static com.facebook.presto.cost.SymbolStatsEstimate.ZERO_STATS; | ||
| import static java.lang.Double.NaN; | ||
| import static java.lang.Double.isNaN; | ||
| import static java.lang.Math.floor; | ||
|
|
@@ -70,7 +68,7 @@ private PlanNodeStatsEstimate normalize(PlanNodeStatsEstimate stats, Optional<Co | |
|
|
||
| SymbolStatsEstimate symbolStats = stats.getSymbolStatistics(symbol); | ||
| SymbolStatsEstimate normalizedSymbolStats = normalizeSymbolStats(symbol, symbolStats, stats, types); | ||
| if (UNKNOWN_STATS.equals(normalizedSymbolStats)) { | ||
| if (normalizedSymbolStats.isUnknown()) { | ||
| normalized.removeSymbolStatistics(symbol); | ||
| continue; | ||
| } | ||
|
|
@@ -87,8 +85,8 @@ private PlanNodeStatsEstimate normalize(PlanNodeStatsEstimate stats, Optional<Co | |
| */ | ||
| private SymbolStatsEstimate normalizeSymbolStats(Symbol symbol, SymbolStatsEstimate symbolStats, PlanNodeStatsEstimate stats, TypeProvider types) | ||
| { | ||
| if (UNKNOWN_STATS.equals(symbolStats)) { | ||
| return UNKNOWN_STATS; | ||
| if (symbolStats.isUnknown()) { | ||
| return SymbolStatsEstimate.unknown(); | ||
|
||
| } | ||
|
|
||
| double outputRowCount = stats.getOutputRowCount(); | ||
|
|
@@ -116,7 +114,7 @@ private SymbolStatsEstimate normalizeSymbolStats(Symbol symbol, SymbolStatsEstim | |
| } | ||
|
|
||
| if (distinctValuesCount == 0.0) { | ||
| return ZERO_STATS; | ||
| return SymbolStatsEstimate.zero(); | ||
| } | ||
|
|
||
| return SymbolStatsEstimate.buildFrom(symbolStats) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like inlining
zerois error prone, see number of places where you missed NaN