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

Filter objects based on values in primitive lists #6988

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,32 @@ public void equalTo_nonLatinCharacters() {
assertEquals(0, resultList.size());
}

@Test
public void equalTo_primitiveList_string() {
int numberOfObjects = 4;
int numberOfBlocks = 5;

realm.beginTransaction();
for (int i = 0; i < numberOfObjects; i++) {
for (int j = 0; j < numberOfBlocks; j++) {
AllTypes obj = realm.createObject(AllTypes.class);
obj.getColumnStringList().add("realm" + j);
obj.getColumnBinaryList();
obj.getColumnBooleanList();
obj.getColumnLongList();
obj.getColumnDoubleList();
obj.getColumnFloatList();
obj.getColumnDateList();
obj.getColumnDecimal128List();
obj.getColumnObjectIdList();
}
}
realm.commitTransaction();

RealmResults<AllTypes> all = realm.where(AllTypes.class).equalTo("columnStringList", "realm0").findAll();
assertEquals(numberOfObjects, all.size());
}

private void doTestForInString(String targetField) {
populateNoPrimaryKeyNullTypesRows();
RealmResults<NoPrimaryKeyNullTypes> resultList = realm.where(NoPrimaryKeyNullTypes.class).in(targetField, new String[]{"test data 14"}).findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,8 @@ static void TableQuery_StringPredicate(JNIEnv* env, jlong nativeQueryPtr, jlongA
}
switch (predicate) {
case StringEqual:{
// FIXME Alternative to try out querying objects by predicate on primitive lists with updated query syntax
// Q(nativeQueryPtr)->and_query(Q(nativeQueryPtr)->get_table()->column<Lst<String>>(ColKey(col_key_arr[0])) == value2);
Q(nativeQueryPtr)->equal(ColKey(col_key_arr[0]), value2, is_case_sensitive);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion realm/realm-library/src/main/java/io/realm/RealmQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public RealmQuery<E> equalTo(String fieldName, @Nullable ObjectId value) {
}

private RealmQuery<E> equalToWithoutThreadValidation(String fieldName, @Nullable String value, Case casing) {
FieldDescriptor fd = schema.getFieldDescriptors(fieldName, RealmFieldType.STRING);
FieldDescriptor fd = schema.getFieldDescriptors(fieldName, RealmFieldType.STRING, RealmFieldType.STRING_LIST);
this.query.equalTo(fd.getColumnKeys(), fd.getNativeTablePointers(), value, casing);
return this;
}
Expand Down