Skip to content

Conversation

@MAST1999
Copy link
Contributor

I tried not to change too many things.
If something doesn't look right, or we need some tests that are missing, I'm happy to try and make those changes.

BTW, I tried adding date support to eq as well but, I couldn't figure out a way to make it work. I made a change in packages/db/src/query/compiler/evaluators.ts and, after checking it, I can see that it's converting date to number and comparing it correctly.

After I added a test to confirm it, the test kept failing :(
So if it's something that needs more work I can take it out and follow up later.

Feel free to make any necessary changes :)

@changeset-bot
Copy link

changeset-bot bot commented Aug 20, 2025

🦋 Changeset detected

Latest commit: dc6a2a8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@tanstack/db-ivm Patch
@tanstack/db Patch
@tanstack/angular-db Patch
@tanstack/electric-db-collection Patch
@tanstack/query-db-collection Patch
@tanstack/react-db Patch
@tanstack/rxdb-db-collection Patch
@tanstack/solid-db Patch
@tanstack/svelte-db Patch
@tanstack/trailbase-db-collection Patch
@tanstack/vue-db Patch
todos Patch
@tanstack/db-example-react-todo Patch

Not sure what this means? Click here to learn what changesets are.

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

@MAST1999
Copy link
Contributor Author

I also checked with lt, gt and the whole family and I think it's working. Though I recommend someone double check.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 20, 2025

More templates

@tanstack/angular-db

npm i https://pkg.pr.new/@tanstack/angular-db@428

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@428

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@428

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@428

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@428

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@428

@tanstack/rxdb-db-collection

npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@428

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@428

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@428

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@428

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@428

commit: dc6a2a8

@MAST1999
Copy link
Contributor Author

OK, managed to make it work.

The PR is ready for review.

@samwillis
Copy link
Collaborator

Hey @MAST1999 just letting you know this hasn't dropped off my radar. I've asked @kevin-dp to review it as he worked on the groupBy operator recently.

@samwillis samwillis requested a review from kevin-dp August 26, 2025 11:09
Copy link
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

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

I left some comments with regard to the code changes. I believe the changes here are indeed enough for Dates to work with aggregation functions.

On the longer term, i'm not sure if this is the approach we want to take. Turning the value into a number with Number seems brittle and works for Dates but may not work for other data types.

We may want a bigger refactor such that min and max work on any data type that has a total ordering. This means we need a custom comparator function as well as a bottom value and a top value for that specific data type. For example, for numbers the comparator is <, the bottom value is -Inf and the top value is +Inf.

@samwillis
Copy link
Collaborator

I think in future a larger refactor may be good to support a wider range of types in min/max, but in the sort term this looks like a good route to getting them working for Date. Numbers and dates are by far the most common use for these functions, so lets concentrate on getting that in soon.

@samwillis
Copy link
Collaborator

samwillis commented Sep 24, 2025

Hi @MAST1999, I'm finally catching up on this! I hope you don't mind that I have made some tweaks and pushed to your branch. You had identified much of what needed to happen, and while looking through this it's become apparent we actually have a small bug with range lookups on Date properties.

@kevin-dp could you take a look at this PR, I think its all good now but I want you to cast your eyes over the normalisation of keys for the btree index. Even though we had a comparison function that supported dates they would still be inserted using the Date object ref, and so range queries would not work. This PR changes it to normalise dates to a number as the key in the index so that the same date is inserted under the same key. As you did this initial work I want to check that we are making the correct changes. May be worth discussing on Monday.

@MAST1999 I removed the normalisation of other objects to JSON - this is an edge case that I don't think we need to support, and stringifying to json is very slow. It would be better to just go on object ref for them (essentually random order).

Copy link
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

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

Overall the changes look good to me. Left some comments for small improvements.

@samwillis samwillis requested a review from kevin-dp September 29, 2025 14:23
Copy link
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my feedback. I left 1 comment that is important to double check whether it is correct or not before we merge.

@samwillis samwillis self-requested a review September 29, 2025 19:20
@samwillis samwillis dismissed kevin-dp’s stale review September 29, 2025 19:22

Gave me the go-ahead via DM

@samwillis samwillis merged commit 51c6bc5 into TanStack:main Sep 29, 2025
6 checks passed
@github-actions github-actions bot mentioned this pull request Sep 29, 2025
@MAST1999 MAST1999 deleted the feat_add_date_support_to_aggregate_fns branch September 30, 2025 00:13
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