TINKERPOP-1920 Fixed P.within/without() handling for collections#817
TINKERPOP-1920 Fixed P.within/without() handling for collections#817
Conversation
jorgebay
left a comment
There was a problem hiding this comment.
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))) |
There was a problem hiding this comment.
Can be simplified to args.Length == 1 && args[0] is ICollection<object>
|
|
||
| private static T[] ToGenericArray<T>(ICollection<T> collection) | ||
| { | ||
| if (collection == null) |
There was a problem hiding this comment.
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];
}|
@jorgebay i implemented your suggestions - thanks |
|
VOTE +1 |
FlorianHockmann
left a comment
There was a problem hiding this comment.
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])); |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
Please also remove the enum value here: https://github.com/apache/tinkerpop/blob/tp32/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs#L60
|
VOTE +1 (pending Florian's 2 comments) |
|
@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? |
gremlin-dotnet/glv/P.template
Outdated
| 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)); |
There was a problem hiding this comment.
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 😅
There was a problem hiding this comment.
Nice catch! I've looked at it and missed it completely :)
There was a problem hiding this comment.
hahaha....oops - copy/paste. thanks-that was dumb on my part
cfc04a8 to
8c87fcf
Compare
https://issues.apache.org/jira/browse/TINKERPOP-1920
Made the logic the same as what we have in Java currently for
P.within()andP.without()for handling single collection values. I pretty much just made this work so open to input from C# experts for a nicer handling ofP, but for now in terms of fixing the problem:Builds with
mvn clean install -pl :gremlin-dotnet,:gremlin-dotnet-source,:gremlin-dotnet-tests -DskipIntegrationTests=falseVOTE+1