Skip to content

Commit

Permalink
[TINKERPOP-2972] ProjectStep does not allow keys specified in a query…
Browse files Browse the repository at this point in the history
… to be duplicate
  • Loading branch information
rdtr committed Sep 5, 2023
1 parent 91e033f commit 97487f8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This release also includes changes from <<release-3-5-8, 3.5.8>>.
* Deprecated the `HandshakeInterceptor` in favor of a more generic `RequestInterceptor`.
* Fix a bug in `StarGraph` where `EdgeFilter` did not remove associated Edge Properties
* Added translator to the Go GLV
* ProjectStep throws exception when a duplicate key is provided in a query.
[[release-3-6-5]]
=== TinkerPop 3.6.5 (Release Date: July 31, 2023)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
Expand All @@ -48,6 +50,11 @@ public ProjectStep(final Traversal.Admin traversal, final String... projectKeys)

public ProjectStep(final Traversal.Admin traversal, final TraversalRing<S, E> traversalRing, final String... projectKeys) {
super(traversal);

if (Arrays.stream(projectKeys).collect(Collectors.toSet()).size() != projectKeys.length) {
throw new IllegalArgumentException("keys must be unique in ProjectStep");
}

this.projectKeys = Arrays.asList(projectKeys);
this.traversalRing = traversalRing;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;

/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
Expand All @@ -44,4 +50,15 @@ protected List<Traversal> getTraversals() {
__.project("y").by("name")
);
}

@Test
public void shouldThrowWhenDuplicateKeySupplied() {
try {
__.project("x", "x");
fail("Should throw an exception.");
} catch (final Exception re) {
assertThat(re, instanceOf(IllegalArgumentException.class));
assertThat(re.getMessage(), is("keys must be unique in ProjectStep"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,13 @@ Feature: Step - project()
| m[{"a":"d[0].l", "b":"d[29].i"}] |
| m[{"a":"d[1].l", "b":"d[27].i"}] |
| m[{"a":"d[1].l", "b":"d[32].i"}] |
| m[{"a":"d[0].l", "b":"d[35].i"}] |
| m[{"a":"d[0].l", "b":"d[35].i"}] |


Scenario: g_V_projectXa_aX
Given the modern graph
And the traversal of
"""
g.V().project("a", "a")
"""
Then the traversal will raise an error with message containing text of "keys must be unique in ProjectStep"

0 comments on commit 97487f8

Please sign in to comment.