-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Migrate to text based query parser. #7318
Migrate to text based query parser. #7318
Conversation
…ing classes out from the schema
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.
Really nice... are a bunch of tests that needs to be revisited though. And I had some comments to implementation in places.
One question though: If FieldDescriptors are no longer needed, couldn't we also remove a lot of code from the ProxyClassGenerator?
CHANGELOG.md
Outdated
@@ -1,12 +1,18 @@ | |||
## 10.4.0 (YYYY-MM-DD) | |||
### Breaking Changes | |||
* Queries no longer check do nullability checks on non-nullable fields. |
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.
* Queries no longer check do nullability checks on non-nullable fields. | |
* Queries no longer do nullability checks on non-nullable fields, so using `null` as an argument will not throw an `IllegalArgumentException` |
CHANGELOG.md
Outdated
|
||
### Known Bugs | ||
* Java field names not supported on Sort or Distinct operations. (Issue [#4550] (https://github.com/realm/realm-core/issues/4550)) | ||
* Queries on fields named with non-latin characters are not currently supported. (Issue [#4467] (https://github.com/realm/realm-core/issues/4467)) |
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.
It is fine to have this entry when merging this PR, but I would consider this a blocker for releasing.
@@ -725,6 +725,7 @@ public void run() throws Exception { | |||
} | |||
|
|||
@Test | |||
@Ignore("FIXME: See https://github.com/realm/realm-core/issues/4469") |
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 issue has been closed, so this test should probably be updated.
fail(); | ||
} catch (IllegalArgumentException ignored) { | ||
} | ||
RealmResults<Owner> owners7 = testRealm.where(Owner.class).between("cat.age", 1, 20).findAll(); |
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.
It also closes this issue: #2204 🥳 , so should definitely be in the CHANGELOG
realm/realm-library/src/androidTest/java/io/realm/RealmQueryTests.java
Outdated
Show resolved
Hide resolved
* <p> | ||
* Class and property names used in the raw predicate can be either the names defined in the | ||
* Realm Model classes or the internal names defined using the {@link io.realm.annotations.RealmClass} | ||
* or {@link io.realm.annotations.RealmField} annotations. | ||
* <p> |
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.
Any reason to remove this?
We should probably also add something about neededing to escape field names with spaces?
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.
Shouldn't have removed. Added a comment on escaping field and class names.
this.context = sharedRealm.context; | ||
this.sharedRealm = sharedRealm; | ||
this.nativeTableRefPtr = nativeTableRefPointer; | ||
this.osKeyPathMapping = osKeyPathMapping; |
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.
Not sure it is safe to store it like this? The keypath mapping can be updated by a callback from Core, making storing it here dangerous. Unless the usage is very shortlived. But maybe I am missing something?
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.
Great catch, it is not safe as it can be recreated by a callback from core.
private boolean queryValidated = true; | ||
|
||
// TODO: Can we protect this? | ||
public TableQuery(NativeContext context, Table table, long nativeQueryPtr) { | ||
private static String escapeFieldName(String fieldName) { |
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.
Not sure it is a bug as such, just something we need to document for using the string-based queries.
queryValidated = false; | ||
return this; | ||
} | ||
sortSeparator = ", "; |
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.
This seems to lead to trailing ,
. That is okay with the Query Parser?
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.
It is fine! We use the separator between fields.
if (value == null) { throw new IllegalArgumentException(DATE_NULL_ERROR_MESSAGE); } | ||
nativeGreaterTimestamp(nativePtr, columnKey, tablePtrs, value.getTime()); | ||
public TableQuery isEmpty(String fieldName) { | ||
rawPredicateWithPointers(escapeFieldName(fieldName) + ".@count = 0"); |
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.
Does this also work with Strings? If I remember correctly the old isEmpty()
also accepted Strings?
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.
Yes, it does!
@@ -3097,30 +3095,28 @@ private void distinctAllFields(Realm realm, String prefix) { | |||
types.remove(type); | |||
} | |||
|
|||
// Verify that we have tested all field types except LinkingObjects which is not part of | |||
// the schema lookup | |||
// Validate that backlinks are not supported by sort/distinct |
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.
Distinct and sort don't support backlinks: realm/realm-core#4524
Refactors the current type-safe query system in Ream Java to use the new string-based query parser. It introduced some behavioral changes:
equalto
/notequalto
null
on non-nullable fields no longer throws.or()
with not right part does not throw.distinct()
does not fail on invalid types/unknown fields.isEmpty
/isNotEmpty
now works with all Realm list types (before it only worked on Realm Objects Lists).There is no actual query validation until it gets executed.String operations
contains
,like
,beginsWith
,endsWith
enforce non-null value arguments. These operations arguments were marked as non-null but no check was in place.Known issues