Skip to content

Remove Optional from FilterStatsCalculator and ComparisonStatsCalculator method signatures#11686

Merged
arhimondr merged 4 commits intoprestodb:masterfrom
arhimondr:filter-stats-calculator-remove-optional
Oct 11, 2018
Merged

Remove Optional from FilterStatsCalculator and ComparisonStatsCalculator method signatures#11686
arhimondr merged 4 commits intoprestodb:masterfrom
arhimondr:filter-stats-calculator-remove-optional

Conversation

@arhimondr
Copy link
Member

Having Optional in these interfaces makes code messy. Optional.empty() indicates an absence of the estimate. However it doesn't mean that if the result is not empty, the estimate is not unknown. That makes code harder to reason about.

- Reorder methods
- Reorder arguments
- Give more meaningful name to variables
- Give more readable names to methogs
In fact Optional.empty() meant the same as PlanNodeStatsEstimate.unknown(). Although it wasn't
clear if it is possible for ComparisonStatsCalculator to return Optional.of(PlanNodeStatsEstimate.unknown()),
and whether the code that calls ComparisonStatsCalculator should check for unknown within the Optional.

This commit tries to address this ambiguity.
- Extract SymbolStatsEstimate#isSingleValue method
- Give variables more readable names
- Reorder methods
- Return Optional.empty() explicitly instead of delegating to visitExpression()
- Simplify getType and getExpressionStats methods. Functional style is extra there
@arhimondr
Copy link
Member Author

I ran the tests from the #11665, the plans are the same.

Copy link
Contributor

@kokosing kokosing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with this refactor.

@arhimondr arhimondr merged commit 75e2715 into prestodb:master Oct 11, 2018
@arhimondr arhimondr deleted the filter-stats-calculator-remove-optional branch October 11, 2018 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants