Skip to content

TINKERPOP-1920 Fixed P.within/without() handling for collections#817

Merged
asfgit merged 1 commit intotp32from
TINKERPOP-1920
Mar 19, 2018
Merged

TINKERPOP-1920 Fixed P.within/without() handling for collections#817
asfgit merged 1 commit intotp32from
TINKERPOP-1920

Conversation

@spmallette
Copy link
Copy Markdown
Contributor

https://issues.apache.org/jira/browse/TINKERPOP-1920

Made the logic the same as what we have in Java currently for P.within() and P.without() for handling single collection values. I pretty much just made this work so open to input from C# experts for a nicer handling of P, but for now in terms of fixing the problem:

Builds with mvn clean install -pl :gremlin-dotnet,:gremlin-dotnet-source,:gremlin-dotnet-tests -DskipIntegrationTests=false

VOTE+1

Copy link
Copy Markdown
Contributor

@jorgebay jorgebay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I've added 2 small nits below.

public static P Within(params object[] args)
{
return new P("within", args);
if (args.Length == 1 && args[0].GetType().GetInterfaces().Contains(typeof(ICollection)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to args.Length == 1 && args[0] is ICollection<object>


private static T[] ToGenericArray<T>(ICollection<T> collection)
{
if (collection == null)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can express the logic in this method using null-conditional and null-coalescing operators:

private static T[] ToGenericArray<T>(ICollection<T> collection)
{
    return collection?.ToArray() ?? new T[0];
}

@spmallette
Copy link
Copy Markdown
Contributor Author

@jorgebay i implemented your suggestions - thanks

@jorgebay
Copy link
Copy Markdown
Contributor

VOTE +1

Copy link
Copy Markdown
Member

@FlorianHockmann FlorianHockmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this removes the last ignored tests on tp32

I also just have two nits

{
return new P("within", args);
if (args.Length == 1 && args[0] is ICollection<object>)
return new P("within", ToGenericArray((ICollection<object>) args[0]));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (ICollection<object>) cast can even be removed like this:

if (args.Length == 1 && args[0] is ICollection<object> collection)
    return new P("without", ToGenericArray(collection));

new Dictionary<string, IgnoreReason>
{
{"g_V_hasIdXwithinXemptyXX_count", IgnoreReason.PWithinWrapsArgumentsInArray},
{"g_VX1X_out_aggregateXxX_out_whereXnotXwithinXaXXX", IgnoreReason.PWithinWrapsArgumentsInArray}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkuppitz
Copy link
Copy Markdown
Contributor

VOTE +1 (pending Florian's 2 comments)

@spmallette
Copy link
Copy Markdown
Contributor Author

@FlorianHockmann I rebased and now the tests are failing (with and without your suggested changes) - i assume this has something to do with the lambda work that just merged - any ideas?

Failures:
1) g_V_hasIdXwithinXemptyXX_count: Failed
Xunit.Sdk.ContainsException: Assert.Contains() Failure
Not found: 6
In value:  Object[] [0]
   at Xunit.Assert.Contains[T](T expected, IEnumerable`1 collection, IEqualityComparer`1 comparer)
   at Gremlin.Net.IntegrationTest.Gherkin.CommonSteps.AssertResult(String characterizedAs, DataTable table) in /home/smallette/git/apache/incubator-tinkerpop/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs:line 188
2) g_V_notXhasIdXwithinXemptyXXX_count: Failed
Xunit.Sdk.ContainsException: Assert.Contains() Failure
Not found: 0
In value:  Object[] [6]
   at Xunit.Assert.Contains[T](T expected, IEnumerable`1 collection, IEqualityComparer`1 comparer)
   at Gremlin.Net.IntegrationTest.Gherkin.CommonSteps.AssertResult(String characterizedAs, DataTable table) in /home/smallette/git/apache/incubator-tinkerpop/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs:line 188

if (args.Length == 1 && args[0] is ICollection<object>)
return new P("<%= method %>", ToGenericArray((ICollection<object>) args[0]));
if (args.Length == 1 && args[0] is ICollection<object> collection)
return new P("without", ToGenericArray(collection));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the method should be hard-coded as without here 😄

I just debugged one of the failing tests and was really confused when I saw P.without() in the Bytecode although the scenario only uses P.within(), but good that we now have such a good test coverage with the Gherkin features that we immediately find slips like this one 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! I've looked at it and missed it completely :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahaha....oops - copy/paste. thanks-that was dumb on my part

@asfgit asfgit force-pushed the TINKERPOP-1920 branch 2 times, most recently from cfc04a8 to 8c87fcf Compare March 19, 2018 14:17
@asfgit asfgit merged commit 8c87fcf into tp32 Mar 19, 2018
@asfgit asfgit deleted the TINKERPOP-1920 branch April 14, 2018 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants