Fix RSQL G2 visitor OR optimizaton when one table with different attributes (#2135)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-12-10 16:37:46 +02:00
committed by GitHub
parent d3eeb71826
commit 13fef83e53
2 changed files with 11 additions and 6 deletions

View File

@@ -71,7 +71,7 @@ public class JpaQueryRsqlVisitorG2<A extends Enum<A> & RsqlQueryField, T>
private final boolean ensureIgnoreCase;
private final SimpleTypeConverter simpleTypeConverter = new SimpleTypeConverter();
private final Map<Class<?>, Path<?>> javaTypeToPath = new HashMap<>();
private final Map<String, Path<?>> attributeToPath = new HashMap<>();
private boolean inOr;
public JpaQueryRsqlVisitorG2(final Class<A> enumType,
@@ -100,7 +100,7 @@ public class JpaQueryRsqlVisitorG2<A extends Enum<A> & RsqlQueryField, T>
return Collections.singletonList(children.isEmpty() ? cb.conjunction() : cb.or(children.toArray(new Predicate[0])));
} finally {
inOr = false;
javaTypeToPath.clear();
attributeToPath.clear();
}
}
@@ -303,7 +303,7 @@ public class JpaQueryRsqlVisitorG2<A extends Enum<A> & RsqlQueryField, T>
}
} // if a collection - it is a join
if (inOr && root == this.root) { // try to reuse join of the same "or" level and no subquery
return javaTypeToPath.computeIfAbsent(attribute.getJavaType(), k -> root.join(fieldNameSplit, JoinType.LEFT));
return attributeToPath.computeIfAbsent(attribute.getName(), k -> root.join(fieldNameSplit, JoinType.LEFT));
} else {
return root.join(fieldNameSplit, JoinType.LEFT);
}