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 (#2217)

Co-authored-by: Yang Xia <[email protected]>
  • Loading branch information
rdtr and xiazcy authored Sep 29, 2023
1 parent 69a3253 commit 4173f42
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 now throws exception when a duplicate key is provided in a query.
* Fixed bug in `DotNetTranslator` where `PartitionStrategy` usage was not translating properly when specifying the `readPartitions`.
* Fixed bug in `PythonTranslator` where `Set` syntax was not being generated properly.
* Fixed bug in configuration object given to `PartitionStrategy` for Go that prevented `readPartitions` from behing set properly.
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 4173f42

Please sign in to comment.