[
https://issues.apache.org/jira/browse/TINKERPOP-2863?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17711529#comment-17711529
]
ASF GitHub Bot commented on TINKERPOP-2863:
-------------------------------------------
vkagamlyk commented on code in PR #2019:
URL: https://github.com/apache/tinkerpop/pull/2019#discussion_r1164551918
##########
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java:
##########
@@ -1608,35 +1608,31 @@ public default GraphTraversal<S, E> hasId(final Object
id, final Object... other
return this.hasId((P) id);
}
else {
- Object[] ids;
+ this.asAdmin().getBytecode().addStep(Symbols.hasId, id, otherIds);
+
+ //using ArrayList given P.within() turns all arguments into lists
+ final List<Object> ids = new ArrayList<>();
if (id instanceof Object[]) {
- ids = (Object[]) id;
- } else {
- ids = new Object[] {id};
- }
- int size = ids.length;
- int capacity = size;
+ Collections.addAll(ids, (Object[]) id);
+ } else if (id instanceof Collection) {
+ // when hasId() is pushed down to g.V() step, it unwraps any
lists in ids into their individual elements,
+ // here we will do that with lists as well to remain
consistent (TINKERPOP-2863)
+ ids.addAll((Collection<?>) id);
+ } else
+ ids.add(id);
+
+ // flattening ids from other lists in varargs works cleaner with
lists, as otherwise any list will need to
+ // be turned into array first
for (final Object i : otherIds) {
if (i.getClass().isArray()) {
Review Comment:
```suggestion
if (i instanceof Object[]) {
```
> HasId Step generates incorrect results when given a list of IDs mid-traversal
> -----------------------------------------------------------------------------
>
> Key: TINKERPOP-2863
> URL: https://issues.apache.org/jira/browse/TINKERPOP-2863
> Project: TinkerPop
> Issue Type: Bug
> Components: process
> Affects Versions: 3.6.2
> Reporter: Taylor Riggan
> Priority: Critical
>
> In most situations, hasId() will accept a list of potential IDs to filter on
> and implicitly use within() filtering semantics to return the correct
> results. Examples:
> {code:java}
> g.V().hasId(['1','2'])
> {code}
> returns:
> {code:java}
> [v[1], v[2]]{code}
> or
> {code:java}
> g.E().hasId(['5140','5261']){code}
> returns:
> {code:java}
> [e[5140][1-route->51], e[5261][1-route->398]]{code}
> However, when using the same form of semantics mid-traversal, both of these
> queries return empty results:
> {code:java}
> g.V().has('code','ATL').outE('route').hasId(['5140','5261'])
> g.V().has('code','ATL').outE('route').inV().hasId(['2','3'])
> {code}
> When using profile() against both queries, the hasId() bytecode gets
> transformed into
> {code:java}
> HasStep([~id.eq([5140, 5261])]) {code}
> This equates to finding a vertex or edge with an ID that matches the entire
> list instead of the elements within the list.
> The preceding was tested against Gremlin Server 3.6.2 with the Airroutes
> dataset.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)