Queries with two or more parameters don't work.
sombra-ostryzhniuk-andrii opened this issue · comments
Queries with two or more parameters don't work. For example:
Optional<GenericContainer> findByDefinitionAndDeleted(String definition, Boolean deleted);
The reason:
The same entity class is added each time for each parameter so then the same query are generated two times, for each item of the classes
list. So an error occurs:
com.orientechnologies.orient.core.sql.OCommandSQLParsingException: Error parsing query:
SELECT expand($union) LET $q0 = (SELECT FROM `GenericContainer` WHERE `definition` = :param0 AND `deleted` = :param1) , LET $q0 = (SELECT FROM `GenericContainer` WHERE `definition` = :param0 AND `deleted` = :param1) , $union = UNIONALL($q0,$q1)
Possible solution:
Allow only unique values in the classes
list in the class org/apache/tinkerpop/gremlin/orientdb/OrientGraphQueryBuilder.java
:
public OrientGraphQueryBuilder addCondition(HasContainer condition) {
if (isLabelKey(condition.getKey())) {
Object value = condition.getValue();
if (value instanceof List) {
((List) value).forEach(label -> addClass((String) label));
} else {
addClass((String) value);
}
} else {
params.put(condition.getKey(), condition.getPredicate());
}
return this;
}
private void addClass(String classLabel) {
if (!classes.contains(classLabel)) {
classes.add(classLabel);
}
}
Do you have the traversal that fails? Thanks
@wolf4ood Do you mean a stack trace?
I mean the gremlin traversal/query that produces this error
@wolf4ood
No, I don't have. I use this spring data query:
Optional<GenericContainer> findByDefinitionAndDeleted(String definition, Boolean deleted);
Which spring data?
Do you have a reproducer that I can use to debug it ?
Thanks
Do you mean something like this?
DefaultGraphTraversal : [OrientGraphStep(vertex,[~label.eq(GenericContainer), definition.eq(test), ~label.eq(GenericContainer), deleted.eq(false)])]
That's the value from OrientGraphCountStrategy : apply(Traversal.Admin<?, ?> traversal)
.
definition
and deleted
are properties. That error occurs for every query by two or more parameters, independently on data.
Thanks
thanks for the debug info, i guess spring data gremlin you are referring to.
I guess that filter put the labels 2 times and make the ODB builder fails.
Your patch is correct , i will applying it and it will be available in the next release or snapshot
Thanks