Skip to content

Conversation

Uziniii
Copy link

@Uziniii Uziniii commented Aug 21, 2025

#422

not all tests are correct and theres change to be done with AggregateFunction type cause it doesnt return initial type value

the pull request is only for review i dont know how to implement the type in the AggregateFunction type and for knowing if a features like this can and would be added to tanstack db because i really need it and i thinks its necessary

Copy link

changeset-bot bot commented Aug 21, 2025

⚠️ No Changeset found

Latest commit: 5659a2d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@MAST1999
Copy link
Contributor

Hey, I'm in dire need of this operator 😄

Do you need any help or testing? I have sometime this weekend.

@@ -344,7 +344,7 @@ function getAggregateFunction(aggExpr: Aggregate) {
const valueExtractor = ([, namespacedRow]: [string, NamespacedRow]) => {
const value = compiledExpr(namespacedRow)
// Ensure we return a number for numeric aggregate functions
return typeof value === `number` ? value : value != null ? Number(value) : 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this is a good change, since the other function rely on the value being a number.

Might be a good idea to add another value extractor specific to your need. At least that's what I've done in my PR for min and max to support dates.

Copy link
Author

Choose a reason for hiding this comment

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

Yes that a workaround for now I didn't have the time to do it and I needed it to work fast for my project

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree this should be a separate extractor

Copy link
Collaborator

@samwillis samwillis left a comment

Choose a reason for hiding this comment

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

Hey @Uziniii
Thanks for picking this up - I'm supportive of adding this, although it needs a little more work first.
This will work well for small groups, but will not be ideal for large hierarchical aggregations, for that we have a plan to make them fully incidental all each level.
The key thing is tidying up the value extractor code.
We should also maybe add some type tests ( in group-by.test-d.ts) to ensure that the value extracted in the list results in the current type on the resulting collection, let me know when you are further along and I will take another look.

@@ -344,7 +344,7 @@ function getAggregateFunction(aggExpr: Aggregate) {
const valueExtractor = ([, namespacedRow]: [string, NamespacedRow]) => {
const value = compiledExpr(namespacedRow)
// Ensure we return a number for numeric aggregate functions
return typeof value === `number` ? value : value != null ? Number(value) : 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree this should be a separate extractor

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.

3 participants