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 24, 2023
1 parent 8acfcb1 commit c64573f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This release also includes changes from <<release-3-5-8, 3.5.8>>.
* Fixed a bug in `StarGraph` where `EdgeFilter` did not remove associated Edge Properties.
* Added translator to the Go GLV.
* Fixed bug with filtering for `group()` when the side-effect label was defined for it.
* 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"));
}
}
}

0 comments on commit c64573f

Please sign in to comment.