From 14c27d5c86ac31077a0e3ebda9bb574e49f9de0d Mon Sep 17 00:00:00 2001 From: Luigi Dell'Aquila Date: Mon, 4 Feb 2019 16:43:23 +0100 Subject: [PATCH] Fix SELECT FROM INDEX from a subquery Resolves: #8745 --- .../core/sql/executor/FetchFromIndexStep.java | 47 +++++-------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/FetchFromIndexStep.java b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/FetchFromIndexStep.java index a4057e8dbc7..ee23f5f82be 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/sql/executor/FetchFromIndexStep.java +++ b/core/src/main/java/com/orientechnologies/orient/core/sql/executor/FetchFromIndexStep.java @@ -13,40 +13,11 @@ import com.orientechnologies.orient.core.db.viewmanager.ViewManager; import com.orientechnologies.orient.core.exception.OCommandExecutionException; import com.orientechnologies.orient.core.exception.OCommandInterruptedException; -import com.orientechnologies.orient.core.index.OCompositeKey; -import com.orientechnologies.orient.core.index.OIndex; -import com.orientechnologies.orient.core.index.OIndexCursor; -import com.orientechnologies.orient.core.index.OIndexDefinition; -import com.orientechnologies.orient.core.index.OIndexDefinitionMultiValue; +import com.orientechnologies.orient.core.index.*; import com.orientechnologies.orient.core.metadata.schema.OType; -import com.orientechnologies.orient.core.sql.parser.OAndBlock; -import com.orientechnologies.orient.core.sql.parser.OBaseExpression; -import com.orientechnologies.orient.core.sql.parser.OBetweenCondition; -import com.orientechnologies.orient.core.sql.parser.OBinaryCompareOperator; -import com.orientechnologies.orient.core.sql.parser.OBinaryCondition; -import com.orientechnologies.orient.core.sql.parser.OBooleanExpression; -import com.orientechnologies.orient.core.sql.parser.OCollection; -import com.orientechnologies.orient.core.sql.parser.OContainsAnyCondition; -import com.orientechnologies.orient.core.sql.parser.OContainsKeyOperator; -import com.orientechnologies.orient.core.sql.parser.OContainsValueOperator; -import com.orientechnologies.orient.core.sql.parser.OEqualsCompareOperator; -import com.orientechnologies.orient.core.sql.parser.OExpression; -import com.orientechnologies.orient.core.sql.parser.OGeOperator; -import com.orientechnologies.orient.core.sql.parser.OGtOperator; -import com.orientechnologies.orient.core.sql.parser.OInCondition; -import com.orientechnologies.orient.core.sql.parser.OLeOperator; -import com.orientechnologies.orient.core.sql.parser.OLtOperator; -import com.orientechnologies.orient.core.sql.parser.OValueExpression; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import com.orientechnologies.orient.core.sql.parser.*; + +import java.util.*; import java.util.stream.Collectors; /** @@ -297,8 +268,16 @@ private void processInCondition() { if (OMultiValue.isMultiValue(rightValue)) { customIterator = new OMultiCollectionIterator<>(); for (Object item : OMultiValue.getMultiValueIterable(rightValue)) { + if (item instanceof OResult) { + if (((OResult) item).isElement()) { + item = ((OResult) item).getElement().get(); + } else if (((OResult) item).getPropertyNames().size() == 1) { + item = ((OResult) item).getProperty(((OResult) item).getPropertyNames().iterator().next()); + } + } OIndexCursor localCursor = createCursor(equals, definition, item, ctx); + Object item_ = item; customIterator.add(new Iterator() { @Override public boolean hasNext() { @@ -315,7 +294,7 @@ public Map.Entry next() { @Override public Object getKey() { - return item; + return item_; } @Override