Skip to content
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

Add support for list query arguments #1389

Merged
merged 10 commits into from
Jun 15, 2023
Merged

Add support for list query arguments #1389

merged 10 commits into from
Jun 15, 2023

Conversation

rorbech
Copy link
Contributor

@rorbech rorbech commented May 10, 2023

This adds support for passing any Iterable as list arguments to the RQL IN operator.

realm.query<QuerySample>("intField IN $0", listOf(1, 3))
realm.query<QuerySample>("intField IN $0", settOf(1, 3))
realm.query<QuerySample>("intField IN $0", 1 .. 3 step 2)

Input for review
I took some shortcuts for handling allocation and assignments of lists for query arguments. It is not as efficient as it could be, but given that we might want to tweak our scheme for transferring values to the C-API if we can generate the code, I chose to fix support for list arguments and will leave the optimizations for later. The current C-API wrappers does not offer identical was to work with lists of contiguous value types. It didn't find a uniform way to allocate a list of element and then update the elements in place with the current wrapper frameworks. Swig's array_functions copies values when accessed by index whereas Kotlin Native's cinterop only allows you to work with the element by reference. As our overall converter infrastructure is currently creating instances and passing it around, it was easier to just memcpy the elements into place in Kotlin Native than reworking the whole infrastructure to assign native references on JVM (and that would also not allow us to use the generated Swig array-functions for valueArray).

Closes: #929

Copy link
Contributor

@cmelchior cmelchior left a comment

Choose a reason for hiding this comment

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

Awesome... I can see why this is a bit suboptimal, but given that this code doesn't run in any hot path, it is probably okay 👍

@@ -2213,6 +2213,34 @@ class QueryTests {
}
}

@Test
fun query_inListArgument() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to be exhaustive here, but it would be nice with a test for this that takes objects as arguments, just as a smoke test since it involves are few more moving parts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually we also need to test strings with ' and "

@rorbech
Copy link
Contributor Author

rorbech commented May 12, 2023

I have added and extended some test cases (list with single element, strings and objects) in f82058e#diff-db6b549cfdb4b7e0512e5d470bdd52902d32f0647ff5d9b8e1a9f72b7b952546 but some fail, so will have to await resolution of core issues.

@rorbech
Copy link
Contributor Author

rorbech commented Jun 2, 2023

Still fails for object links. Created realm/realm-core#6688 to track that.

@cmelchior
Copy link
Contributor

This is now waiting for realm/realm-core#6705 to be merged.

@rorbech
Copy link
Contributor Author

rorbech commented Jun 14, 2023

realm/realm-core#6705 has been merged, so should try to update core. There seem to be a number of API changes, so not just a submodule update though.

@cmelchior cmelchior merged commit 13274d8 into main Jun 15, 2023
@cmelchior cmelchior deleted the cr/query-in-with-list branch June 15, 2023 11:15
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query with multiple values: in operator
3 participants