orientechnologies / orientdb-gremlin

TinkerPop3 Graph Structure Implementation for OrientDB
Apache License 2.0
91 stars 32 forks source link

Queries with two or more parameters don't work. #168

Closed sombra-ostryzhniuk-andrii closed 4 years ago

sombra-ostryzhniuk-andrii commented 4 years ago

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);
    }
  }
wolf4ood commented 4 years ago

Hi @sombra-ostryzhniuk-andrii

Do you have the traversal that fails? Thanks

sombra-ostryzhniuk-andrii commented 4 years ago

@wolf4ood Do you mean a stack trace?

wolf4ood commented 4 years ago

Hi @sombra-ostryzhniuk-andrii

I mean the gremlin traversal/query that produces this error

sombra-ostryzhniuk-andrii commented 4 years ago

@wolf4ood No, I don't have. I use this spring data query: Optional<GenericContainer> findByDefinitionAndDeleted(String definition, Boolean deleted);

wolf4ood commented 4 years ago

Which spring data?

Do you have a reproducer that I can use to debug it ?

Thanks

sombra-ostryzhniuk-andrii commented 4 years ago

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

wolf4ood commented 4 years ago

Hi @sombra-ostryzhniuk-andrii

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