Skip to content

Conversation

bevzzz
Copy link
Collaborator

@bevzzz bevzzz commented Sep 9, 2025

This PR adds the SortBy operator to "fetch objects" query.

things.query.fetchObjects(
    results -> results.sort(
        SortBy.property("width"), // ASC by default
        SortBy.property("length").asc(), // Set ASC axplicitly
        SortBy.creationTime() // _creationTimeUnix
        SortBy.lastUpdateTime() // _lastUpdateTimeUnix
    )
);

Other query types do not support sorting, because the results' order is determined by their relevance.

@bevzzz bevzzz self-assigned this Sep 9, 2025
Copy link

@orca-security-eu orca-security-eu bot left a comment

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

@bevzzz
Copy link
Collaborator Author

bevzzz commented Sep 9, 2025

I chose not to provide an alias for SortBy.uuid() the way Python client does, because I don't quite understand what the utility of that ordering is.

If internally UUIDs are mapped to their (monotonically increasing) int64 docIDs, then this should correspond to sorting by creation time.

If the UUIDs are ordered alphabetically, then the order, while deterministic, is essentially random from the user's point of view.

Åm I missing some use case here?

@dirkkul
Copy link
Collaborator

dirkkul commented Sep 11, 2025

Åm I missing some use case here?

Users can use time-series based UUIDs which monotonically increase with time. Then sorting by UUID is the same as sorting by creation time (or some other order they are using). However this is not recommended due to async replication relying on randomness in the UUIDs.

I am fine with not adding it

@bevzzz
Copy link
Collaborator Author

bevzzz commented Sep 12, 2025

Users can use time-series based UUIDs which monotonically increase with time.

Right, good point. Well, if we don't preserve original timestamps during migrations (as this user mentioned) I can see why someone would do that 🤔

Agreed tho, I'd see if anyone requests that feature before adding it.

@bevzzz bevzzz merged commit 5b00b5b into v6 Sep 12, 2025
2 checks passed
@bevzzz bevzzz deleted the v6-sort branch September 12, 2025 15:40
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.

2 participants