-
Notifications
You must be signed in to change notification settings - Fork 63
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
groupBy {}.aggregate { keys }
#662
base: master
Are you sure you want to change the base?
Conversation
…e extension properties api in notebooks
…o provide access to the keys: AnyRow used to group the df by.
internal class GroupByReceiverImpl<T>( | ||
override val df: DataFrame<T>, | ||
override val hasGroupingKeys: Boolean, | ||
private val retrieveKey: () -> AnyRow = { |
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.
Hm, it has to be lambda here? Can be a DataRow, not sure. And what about default parameter: can it somehow actually throw an exception?
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.
The lambda could be replaced by by a nullable AnyRow perhaps.
And yes, it will throw an exception when you use dataFrame.aggregate { keys }
, since for some reason, the same AggregateGroupedDsl
is used there. There's also an option to get here via pivot
, so for those cases I make it throw a helpful exception.
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.
Hmm, i'd say we need to make type of lambda in Groupby.aggregate more specific then? So only for that case we provide keys as a DSL property. Also, if it makes sense, we can make aggregate an extension function and hide existing member one (but this could be a different story)
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.
Oh yes, i remember now. aggregate probably should be an extension function on GroupBy
public interface GroupBy<out T, out G> : Grouped<G> {
public val groups: FrameColumn<G>
public val keys: DataFrame<T>
then keys can become DataRow<T>
Because now aggregate on GroupBy is resolved to this member and it simply doesn't know anything about keys
public interface Grouped<out T> : Aggregatable<T> {
public fun <R> aggregate(body: AggregateGroupedBody<T, R>): DataFrame<T>
}
Provides access to the keys of the
groupBy {}
operation in theaggregate {}
step. Very useful when you're grouping by anexpr {}
column and want to use the value of a key column to influence how the aggregation happens.For instance:
keys
will be provided as anAnyRow
, since most it will just contain the key columns fromdf
, a tiny subset. Giving it the same type asdf
would result in many breaking accessors onkeys
.