Permalink
Browse files

First step in coming back to lazy evaluation

  • Loading branch information...
systay committed Mar 16, 2012
1 parent 111341b commit e0abd0cb5c954a26e7561b9d88575a2e03c56f33
@@ -27,11 +27,13 @@ import java.lang.String
import internal.symbols.SymbolTable
import collection.Map
import collection.immutable.{Map => ImmutableMap}
-class PipeExecutionResult(r: Traversable[Map[String, Any]], val symbols: SymbolTable, val columns: List[String], val timeTaken: Long)
+
+class PipeExecutionResult(r: => Traversable[Map[String, Any]], val symbols: SymbolTable, val columns: List[String])
extends ExecutionResult
with StringExtras {
- lazy val immutableResult = r.map( m => m.toMap )
+ lazy val immutableResult = r.map(m => m.toMap)
+
def javaColumns: java.util.List[String] = columns.asJava
def javaColumnAs[T](column: String): java.util.Iterator[T] = columnAs[T](column).map(x => makeValueJavaCompatible(x).asInstanceOf[T]).asJava
@@ -67,15 +69,17 @@ class PipeExecutionResult(r: Traversable[Map[String, Any]], val symbols: SymbolT
}
def dumpToString(writer: PrintWriter) {
+ val start = System.nanoTime()
val eagerResult = r.toList
+ val timeTaken = .001 * (System.nanoTime() - start)
val columnSizes = calculateColumnSizes(eagerResult)
val headers = columns.map((c) => Map[String, Any](c -> Some(c))).reduceLeft(_ ++ _)
val headerLine: String = createString(columns, columnSizes, headers)
val lineWidth: Int = headerLine.length - 2
val --- = "+" + repeat("-", lineWidth) + "+"
- val footer = "%d rows, %d ms".format(eagerResult.size, timeTaken)
+ val footer = "%d rows, %f ms".format(eagerResult.size, timeTaken)
writer.println(---)
writer.println(headerLine)
@@ -57,17 +57,9 @@ class ExecutionPlanImpl(inputQuery: Query, graph: GraphDatabaseService) extends
checkForMissingPredicates(query, pipe)
}
- println(pipe.executionPlan())
-
val func = (params: Map[String, Any]) => {
- val start = System.currentTimeMillis()
val newMap = MutableMap() ++ params
- val results = pipe.createResults(newMap)
- val timeTaken = System.currentTimeMillis() - start
-
- println(pipe.executionPlan())
-
- new PipeExecutionResult(results, pipe.symbols, inputQuery.returns.columns, timeTaken)
+ new PipeExecutionResult(pipe.createResults(newMap), pipe.symbols, inputQuery.returns.columns)
}
val executionPlan = pipe.executionPlan()

0 comments on commit e0abd0c

Please sign in to comment.