From e2ef9ed75eb653bdb7115fe68623e38ccdf20496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus=20R=C3=B8rbech?= Date: Fri, 3 Jul 2020 10:44:26 +0200 Subject: [PATCH] Experiments with support for predicate queries on primitive lists of strings --- .../java/io/realm/RealmQueryTests.java | 26 +++++++++++++++++++ .../main/cpp/io_realm_internal_TableQuery.cpp | 2 ++ .../src/main/java/io/realm/RealmQuery.java | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/realm/realm-library/src/androidTest/java/io/realm/RealmQueryTests.java b/realm/realm-library/src/androidTest/java/io/realm/RealmQueryTests.java index f5ea0ca3d1..890df76ebe 100644 --- a/realm/realm-library/src/androidTest/java/io/realm/RealmQueryTests.java +++ b/realm/realm-library/src/androidTest/java/io/realm/RealmQueryTests.java @@ -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 all = realm.where(AllTypes.class).equalTo("columnStringList", "realm0").findAll(); + assertEquals(numberOfObjects, all.size()); + } + private void doTestForInString(String targetField) { populateNoPrimaryKeyNullTypesRows(); RealmResults resultList = realm.where(NoPrimaryKeyNullTypes.class).in(targetField, new String[]{"test data 14"}).findAll(); diff --git a/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp b/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp index f315099bb2..7cb71412f4 100644 --- a/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp +++ b/realm/realm-library/src/main/cpp/io_realm_internal_TableQuery.cpp @@ -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>(ColKey(col_key_arr[0])) == value2); Q(nativeQueryPtr)->equal(ColKey(col_key_arr[0]), value2, is_case_sensitive); break; } diff --git a/realm/realm-library/src/main/java/io/realm/RealmQuery.java b/realm/realm-library/src/main/java/io/realm/RealmQuery.java index 0f29dc4ac3..955a376833 100644 --- a/realm/realm-library/src/main/java/io/realm/RealmQuery.java +++ b/realm/realm-library/src/main/java/io/realm/RealmQuery.java @@ -329,7 +329,7 @@ public RealmQuery equalTo(String fieldName, @Nullable ObjectId value) { } private RealmQuery 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; }