Skip to content

Commit 4928ddd

Browse files
committed
fix: correct class cast exception on index query lookup: issue #10530
1 parent e5e906d commit 4928ddd

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

core/src/main/java/com/orientechnologies/orient/core/sql/executor/FetchFromIndexStep.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,32 @@ private void processInCondition() {
319319
if (OMultiValue.isMultiValue(rightValue)) {
320320
customIterator = new OMultiCollectionIterator<>();
321321
Set<Object> itemsSet;
322+
Comparator<Object> com =
323+
new Comparator<Object>() {
324+
325+
@Override
326+
public int compare(Object o1, Object o2) {
327+
if (o1 instanceof Collection && o2 instanceof Collection) {
328+
Collection c1 = (Collection) o1;
329+
Collection c2 = (Collection) o2;
330+
if (c1.size() != c2.size()) {
331+
return c1.size() - c2.size();
332+
}
333+
Iterator i1 = c1.iterator();
334+
Iterator i2 = c2.iterator();
335+
while (i1.hasNext() && i2.hasNext()) {
336+
int comp = ((Comparable) i1.next()).compareTo(i2.next());
337+
if (comp != 0) return comp;
338+
}
339+
return 1;
340+
}
341+
return ((Comparable) o1).compareTo(o2);
342+
}
343+
};
322344
if (orderAsc) {
323-
itemsSet = new TreeSet<>();
345+
itemsSet = new TreeSet<>(com);
324346
} else {
325-
itemsSet = new TreeSet<>((Comparator<Object>) Collections.reverseOrder());
347+
itemsSet = new TreeSet<>((Comparator<Object>) Collections.reverseOrder(com));
326348
}
327349
for (Object item : OMultiValue.getMultiValueIterable(rightValue)) {
328350
if (item instanceof OResult) {
@@ -333,6 +355,8 @@ private void processInCondition() {
333355
((OResult) item).getProperty(((OResult) item).getPropertyNames().iterator().next());
334356
}
335357
}
358+
if (item instanceof List) {}
359+
336360
itemsSet.add(item);
337361
}
338362
for (Object item : itemsSet) {

core/src/test/java/com/orientechnologies/orient/core/sql/executor/OSelectStatementExecutionTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,29 @@ public void testFetchFromClustersNumberOrderByRidAsc() {
928928
result.close();
929929
}
930930

931+
@Test
932+
public void testFetchFromClassWithIndexComposite() {
933+
db.command("create class CompositeIndexWithoutNullValues").close();
934+
db.command("create property CompositeIndexWithoutNullValues.one String").close();
935+
db.command("create property CompositeIndexWithoutNullValues.two String").close();
936+
db.command(
937+
"create index CompositeIndexWithoutNullValues.one_two on"
938+
+ " CompositeIndexWithoutNullValues (one, two) NOTUNIQUE METADATA"
939+
+ " {ignoreNullValues: true}")
940+
.close();
941+
942+
db.command("insert into CompositeIndexWithoutNullValues set one = 'foo', two = 'beer' ")
943+
.close();
944+
db.command("insert into CompositeIndexWithoutNullValues set one = 'foo', two = 'bar'").close();
945+
List<OResult> results =
946+
db
947+
.query(
948+
"select from index:CompositeIndexWithoutNullValues.one_two where key in [['beer','foo']]")
949+
.stream()
950+
.collect(Collectors.toList());
951+
assertEquals(results.size(), 0);
952+
}
953+
931954
@Test
932955
public void testQueryAsTarget() {
933956
String className = "testQueryAsTarget";

0 commit comments

Comments
 (0)