-
-
Notifications
You must be signed in to change notification settings - Fork 27
Add Expr.statistics method based on Statistics
#84
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
13b828f
start experimenting with parquet statistics
rjzamora f5f4e19
Merge remote-tracking branch 'upstream/main' into pq-statistics-len
rjzamora 990ba4c
adopt parts of #40
rjzamora 1c62f4c
experimenting with dedicated Metadata class structure
rjzamora afd59d7
add missing file
rjzamora 8302305
go back to and remove sub-class for now
rjzamora a3c5f2c
add parquet test
rjzamora cbced80
use assume vs inherit
rjzamora 5fe5862
use assume vs inherit
rjzamora b0946f8
split test
rjzamora bfd8710
fix doc-string
rjzamora 2d343c7
fix typos
rjzamora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Iterable | ||
| from dataclasses import dataclass | ||
| from functools import singledispatchmethod | ||
| from typing import Any | ||
|
|
||
| from dask_expr.expr import Elemwise, Expr, Partitions | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class Statistics: | ||
| """Abstract class for expression statistics | ||
|
|
||
| See Also | ||
| -------- | ||
| PartitionStatistics | ||
| """ | ||
|
|
||
| data: Any | ||
|
|
||
| @singledispatchmethod | ||
| def assume(self, parent: Expr) -> Statistics | None: | ||
| """Statistics that a "parent" Expr may assume | ||
|
|
||
| A return value of `None` (the default) means that | ||
| `parent` is not eligable to assume this kind of | ||
| statistics. | ||
| """ | ||
| return None | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class PartitionStatistics(Statistics): | ||
| """Statistics containing a distinct value for every partition | ||
|
|
||
| See Also | ||
| -------- | ||
| RowCountStatistics | ||
| """ | ||
|
|
||
| data: Iterable | ||
|
|
||
|
|
||
| @PartitionStatistics.assume.register | ||
| def _partitionstatistics_partitions(self, parent: Partitions): | ||
| # A `Partitions` expression may assume statistics | ||
| # from the selected partitions | ||
| return type(self)( | ||
| type(self.data)( | ||
| part for i, part in enumerate(self.data) if i in parent.partitions | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| # | ||
| # PartitionStatistics sub-classes | ||
| # | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class RowCountStatistics(PartitionStatistics): | ||
| """Tracks the row count of each partition""" | ||
|
|
||
| def sum(self): | ||
| """Return the total row-count of all partitions""" | ||
| return sum(self.data) | ||
|
|
||
|
|
||
| @RowCountStatistics.assume.register | ||
| def _rowcount_elemwise(self, parent: Elemwise): | ||
| # All Element-wise operations may assume | ||
| # row-count statistics | ||
| return self | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I could use some help understanding this module.
I think that in general we have yet to define what kinds of statistics we're going to capture, and how we plan to encode those. There are lots of options here.
I think what I'm seeing here is that your response is "we'll just make different classes for all the different kinds of things that people might want to encode". Is that correct? If so, I'm not totally bought into this just yet.
I think that the question of "how do we encode dataframe-level or partition-level statistics" is a big open one. I'm ok with us not having a clear answer on this before we move forward, but I want the level of sophistication of our solution to be correlated with our confidence. This feels like a somewhat sophisticated/specific solution (a few classes with some specific method APIs) but I don't have confidence that it's correct (or at least I don't know enough to be confident). Can you help me understand here?
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.
Hmmm. We may need to have a real-time chat about this one. My primary goal here was to keep things very simple, and so it worries me a bit that you see something sophisticated.
The general approach here is: “Adopt the same
statisticsapproach suggested in #40, but use a simple data class as a container for the statistics so that we know if/how it should be passed from child to parent.” I only added the simple class structure to the mix after I started experimenting with row-count and min/max column statistics, and felt that there was unnecessary_statisticslogic polluting several non-IOExprclasses. Since I know the statistics representation/framework is likely to evolve (or be replaced completely) in the future, I was hoping to keep the logic isolated. In the end, I decided to focus on the simple row-count case, and propose a class structure that I expect to be relevant to all statistics: We need hold some kind of statistics “data”, and we need to expose a mechanism to allow the passing of a specific kind of statistics between child and parent.I suppose you are probably saying that that you would prefer not to introduce classes until we know that those classes will capture some of the other kinds of statistics we will want to track (e.g. min/max/null column statistics, and “shuffled-by” information)? This request is perfectly fair. I’ll admit that part of the reason I didn’t include min/max column statistics in this PR is that I hadn’t decided on the best way to represent partition-wise column statistics.
Aside: My favorite column-statistics approach I’ve played with so far is to track a
ColumnStatistics(Statistics)object for each column, and for thedataof that object to be aColumnMaxima(PartitionStatistics)object wheredatais a tuple of{‘min’: …, ‘max’: …}dicts.Another consideration is whether this design will allow us to push down “requests” for missing statistics into a
ReadParquetexpression at optimization time. I think the answer is “yes,” but this question is another reason I’d like to keep the statistics logic isolated in the meantime.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.
One thing I don't like about the design in this PR is that it still uses the
dictapproach (as is) from #40 for tracking all known statistics. Whatever design we ultimately go with, we will probably need to enforce explicit rules for key names and collisions. I didn't bother to deal with this yet, but it was certainly on my mind.