Skip to content

Index type conflict, ClassCastException if multiple indexed fields are included in the same query #1266

Description

@matre

If indexes with different types (on different fields) are used in the same query, the failure below is produced.

Nitrite org.dizitart:nitrite:4.4.1
MVStore adapter org.dizitart:nitrite-mvstore-adapter:4.4.1

java.lang.ClassCastException: class java.lang.Double cannot be cast to class java.lang.String
    at org.dizitart.no2.common.util.Comparables.compare(Comparables.java:20)
    at org.dizitart.no2.common.DBValue.compareTo(DBValue.java:58)
    at org.dizitart.no2.index.IndexEntryKey.compareTo(IndexEntryKey.java:111)
    at org.dizitart.no2.index.IndexEntryKey.compareTo(IndexEntryKey.java:43)
    at org.dizitart.no2.mvstore.NitriteMVMap.ceilingKey(NitriteMVMap.java:174)
    at org.dizitart.no2.index.IndexMap.compositeGet(IndexMap.java:244)
    at org.dizitart.no2.index.IndexMap.get(IndexMap.java:228)
    at org.dizitart.no2.filters.EqualsFilter.applyOnIndex(EqualsFilter.java:58)
    at org.dizitart.no2.index.IndexScanner.doScan(IndexScanner.java:86)
    at org.dizitart.no2.index.SingleFieldIndex.scanIndex(SingleFieldIndex.java:232)
       Nitrite db = Nitrite.builder()
                .loadModule(MVStoreModule.withConfig().build())
                .openOrCreate();
        try {
            NitriteCollection items = db.getCollection("items");

            // Two separate single-field indexes.
            items.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "item_number");
            items.createIndex(IndexOptions.indexOptions(IndexType.NON_UNIQUE), "name");

            Document doc = Document.createDocument();
            doc.put("name", "item_c");
            doc.put("item_number", 103L);
            items.insert(doc);

            Filter eqName     = FluentFilter.where("name").eq("item_c");
            Filter gteNumber  = FluentFilter.where("item_number").gte(102);
            Filter lteNumber  = FluentFilter.where("item_number").lte(104);

            Filter andFilter = Filter.and(eqName, gteNumber, lteNumber);

            // Throws ClassCastException instead of returning the document.
            items.find(andFilter).iterator().next();
        } finally {
            db.close();
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions