Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.4' into 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sherfert committed Jul 18, 2018
2 parents 2a734fd + 1f0dfd1 commit a4841ab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ trait NumericHelper {

protected def asDouble(a: AnyValue): DoubleValue = Values.doubleValue(asNumber(a).doubleValue())

protected def asInt(a: AnyValue): IntValue = Values.intValue(asNumber(a).longValue().toInt)
protected def asInt(a: AnyValue): IntValue = Values.intValue(asPrimitiveInt(a))

protected def asLong(a: AnyValue): LongValue = Values.longValue(asNumber(a).longValue())
protected def asPrimitiveInt(a: AnyValue): Int = asNumber(a).longValue().toInt

protected def asLong(a: AnyValue): LongValue = Values.longValue(asPrimitiveLong(a))

protected def asPrimitiveLong(a: AnyValue): Long = asNumber(a).longValue()

private def asNumber(a: AnyValue): NumberValue = a match {
case null => throw new CypherTypeException("Expected a numeric value for " + toString + ", but got null")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.neo4j.cypher.internal.runtime.interpreted.ExecutionContext
import org.neo4j.cypher.internal.runtime.interpreted.commands.expressions.{Expression, NumericHelper}
import org.opencypher.v9_0.util.attribution.Id

import scala.collection.AbstractIterator
import scala.collection.Iterator.empty

case class LimitPipe(source: Pipe, exp: Expression)
Expand All @@ -33,25 +34,21 @@ case class LimitPipe(source: Pipe, exp: Expression)

protected def internalCreateResults(input: Iterator[ExecutionContext], state: QueryState): Iterator[ExecutionContext] = {

if (input.isEmpty)
return Iterator.empty
if (input.isEmpty) return empty

val limit = asLong(exp(state.createOrGetInitialContext(executionContextFactory), state))
val limit = asPrimitiveLong(exp(state.createOrGetInitialContext(executionContextFactory), state))

new LimitIterator(limit.value(), input)
}

class LimitIterator(limit: Long, iterator: Iterator[ExecutionContext]) extends Iterator[ExecutionContext] {
private var remaining = limit
new AbstractIterator[ExecutionContext] {
private var remaining = limit

def hasNext = remaining > 0 && iterator.hasNext
def hasNext: Boolean = remaining > 0 && input.hasNext

def next(): ExecutionContext =
if (remaining > 0) {
remaining -= 1
iterator.next()
}
else empty.next()
def next(): ExecutionContext =
if (remaining > 0L) {
remaining -= 1L
input.next()
}
else empty.next()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ case class SkipPipe(source: Pipe, exp: Expression)
if(input.isEmpty)
return Iterator.empty

val skip = asInt(exp(state.createOrGetInitialContext(executionContextFactory), state))
val skip = asPrimitiveInt(exp(state.createOrGetInitialContext(executionContextFactory), state))

input.drop(skip.value())
input.drop(skip)
}
}

0 comments on commit a4841ab

Please sign in to comment.