Skip to content
Merged
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 @@ -66,6 +66,7 @@
import static org.dizitart.no2.common.util.Iterables.listOf;
import static org.dizitart.no2.filters.Filter.ALL;
import static org.dizitart.no2.filters.Filter.and;
import static org.dizitart.no2.filters.Filter.or;
import static org.dizitart.no2.filters.FluentFilter.where;
import static org.dizitart.no2.integration.TestUtil.deleteDb;
import static org.dizitart.no2.integration.TestUtil.getRandomTempDbFile;
Expand Down Expand Up @@ -236,6 +237,43 @@ public void testReopen() throws ParseException {
assertEquals(prevRepoSize + 1, repoSizeNow);
}

@Test
public void testLogicalIdSearchForLegacyStringIds() {
String stringBackedId = "1840817122658033664";
long longBackedId = 2041406700293308416L;

NitriteCollection testCollection = db.getCollection("legacy-id-test");
testCollection.insert(
createDocument("_id", stringBackedId).put("tag", "string-id"),
createDocument("_id", longBackedId).put("tag", "long-id"));
db.commit();
db.close();

db = TestUtil.createDb(fileName, "test-user", "test-password");
testCollection = db.getCollection("legacy-id-test");

Document directResult = testCollection.find(where("_id").eq(Long.parseLong(stringBackedId))).firstOrNull();
assertNotNull(directResult);
assertEquals(Long.parseLong(stringBackedId), directResult.getId().getIdValue());

Set<Long> orIds = new HashSet<>();
for (Document document : testCollection.find(or(
where("_id").eq(longBackedId),
where("_id").eq(Long.parseLong(stringBackedId)))).toList()) {
orIds.add(document.getId().getIdValue());
}

assertTrue(orIds.contains(longBackedId));
assertTrue(orIds.contains(Long.parseLong(stringBackedId)));

Document andResult = testCollection.find(and(
where("_id").eq(Long.parseLong(stringBackedId)),
where("tag").eq("string-id"))).firstOrNull();

assertNotNull(andResult);
assertEquals(Long.parseLong(stringBackedId), andResult.getId().getIdValue());
}

@Test
public void testClose() {
NitriteCollection testCollection = db.getCollection("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private FindPlan createOrPlan(Collection<IndexDescriptor> indexDescriptors, List

// check if all sub plan have index support
for (FindPlan plan : findPlan.getSubPlans()) {
if (plan.getIndexDescriptor() == null) {
if (plan.getIndexDescriptor() == null && plan.getByIdFilter() == null) {
// if one of the sub plan doesn't have any index support
// then it can not be optimized, instead the
// original filter should be set as coll-scan filter
Expand Down
Loading