Skip to content

Commit

Permalink
Solve nested unwind bug in compiled runtime and add some feature tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lojjs committed Jan 17, 2018
1 parent 4a31753 commit 14de805
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 21 deletions.
Expand Up @@ -400,14 +400,26 @@ else if ( iterable instanceof PrimitiveEntityStream )
{
return ((PrimitiveEntityStream) iterable).iterator();
}
else if ( iterable instanceof Long)
{
return (LongStream.of((Long) iterable)).iterator();
}
else if ( iterable instanceof LongStream )
{
return ((LongStream) iterable).iterator();
}
else if ( iterable instanceof Double)
{
return (DoubleStream.of((Double) iterable)).iterator();
}
else if ( iterable instanceof DoubleStream )
{
return ((DoubleStream) iterable).iterator();
}
else if ( iterable instanceof Integer)
{
return (IntStream.of((Integer) iterable)).iterator();
}
else if ( iterable instanceof IntStream )
{
return ((IntStream) iterable).iterator();
Expand All @@ -416,30 +428,15 @@ else if ( iterable == null )
{
return Collections.emptyIterator();
}
else if ( iterable instanceof String )
{
String[] singleStringArray = {(String) iterable};
return getIterator( singleStringArray, 1 );
}
else if ( iterable.getClass().isArray() )
{
int len = Array.getLength( iterable );

return new Iterator()
{
private int position = 0;

@Override
public boolean hasNext()
{
return position < len;
}

@Override
public Object next()
{
if ( position >= len )
{
throw new NoSuchElementException();
}
return Array.get( iterable, position++ );
}
};
return getIterator( iterable, len );
}
else
{
Expand All @@ -448,6 +445,30 @@ public Object next()
}
}

private static Iterator getIterator( Object iterable, int len )
{
return new Iterator()
{
private int position = 0;

@Override
public boolean hasNext()
{
return position < len;
}

@Override
public Object next()
{
if ( position >= len )
{
throw new NoSuchElementException();
}
return Array.get( iterable, position++ );
}
};
}

@SuppressWarnings( "unchecked" )
public static LongStream toLongStream( Object list )
{
Expand Down
Expand Up @@ -65,3 +65,8 @@ Negative parameter for LIMIT should not generate errors

//IndexAcceptance.feature
STARTS WITH should handle null prefix

//UnwindAcceptance.feature
Nested unwind with longs
Nested unwind with doubles
Nested unwind with strings
Expand Up @@ -228,3 +228,57 @@ Feature: UnwindAcceptance
| 'c' |
And no side effects

Scenario: Nested unwind with longs
Given an empty graph
When executing query:
"""
WITH [[1, 2], [3, 4], 5] AS nested
UNWIND nested AS x
UNWIND x AS y
RETURN y
"""
Then the result should be:
| y |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
And no side effects

Scenario: Nested unwind with doubles
Given an empty graph
When executing query:
"""
WITH [[1.5, 2.5], [3.5, 4.5], 5.5] AS nested
UNWIND nested AS x
UNWIND x AS y
RETURN y
"""
Then the result should be:
| y |
| 1.5 |
| 2.5 |
| 3.5 |
| 4.5 |
| 5.5 |
And no side effects

Scenario: Nested unwind with strings
Given an empty graph
When executing query:
"""
WITH [['a', 'b'], ['c', 'd'], 'e'] AS nested
UNWIND nested AS x
UNWIND x AS y
RETURN y
"""
Then the result should be:
| y |
| 'a' |
| 'b' |
| 'c' |
| 'd' |
| 'e' |
And no side effects

0 comments on commit 14de805

Please sign in to comment.