Skip to content

Commit

Permalink
Unify pruning var implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Jan 15, 2018
1 parent 2c13b57 commit 66996b6
Show file tree
Hide file tree
Showing 15 changed files with 760 additions and 1,126 deletions.
Expand Up @@ -120,29 +120,6 @@ case class PruningVarExpand(source: LogicalPlan,
override val availableSymbols: Set[String] = source.availableSymbols + to
}

/**
* Another variant of VarExpand, where paths are not explored if they could not produce an unseen
* end node. A more powerful version of PruningVarExpand, which keeps more state. Guaranteed to
* produce unique end nodes.
*
* Only the end node is added to produced rows.
*/
case class FullPruningVarExpand(source: LogicalPlan,
from: String,
dir: SemanticDirection,
types: Seq[RelTypeName],
to: String,
minLength: Int,
maxLength: Int,
predicates: Seq[(LogicalVariable, Expression)] = Seq.empty)
(val solved: PlannerQuery with CardinalityEstimation)(implicit idGen: IdGen) extends LogicalPlan(idGen) with LazyLogicalPlan {

override val lhs = Some(source)
override def rhs = None

override val availableSymbols: Set[String] = source.availableSymbols + to
}

sealed trait ExpansionMode

/**
Expand Down
Expand Up @@ -100,11 +100,7 @@ case object pruningVarExpander extends Rewriter {

val innerRewriter = topDown(Rewriter.lift {
case expand@VarExpand(lhs, fromId, dir, _, relTypes, toId, _, length, ExpandAll, _, _, _, _, predicates) if distinctSet(expand.selfThis) =>
if (length.min >= 4 && length.max.get >= 5)
// These constants were selected by benchmarking on randomized graphs, with different
// degrees of interconnection.
FullPruningVarExpand(lhs, fromId, dir, relTypes, toId, length.min, length.max.get, predicates)(expand.solved)(SameId(expand.id))
else if (length.max.get > 1)
if (length.max.get > 1)
PruningVarExpand(lhs, fromId, dir, relTypes, toId, length.min, length.max.get, predicates)(expand.solved)(SameId(expand.id))
else expand.selfThis
})
Expand Down
Expand Up @@ -204,7 +204,7 @@ class PruningVarExpanderTest extends CypherFunSuite with LogicalPlanningTestSupp
assertNotRewritten(input)
}

test("on longer var-lengths, we use FullPruningVarExpand") {
test("on longer var-lengths, we also use PruningVarExpand") {
// Simplest query:
// match (a)-[*4..5]->(b) return distinct b

Expand All @@ -217,7 +217,7 @@ class PruningVarExpanderTest extends CypherFunSuite with LogicalPlanningTestSupp
val originalExpand = VarExpand(allNodes, fromId, dir, dir, Seq.empty, toId, relId, length, ExpandAll, "tempNode", "tempEdge", TRUE, TRUE, Seq.empty)(solved)
val input = Distinct(originalExpand, Map("to" -> Variable("to")(pos)))(solved)

val rewrittenExpand = FullPruningVarExpand(allNodes, fromId, dir, Seq.empty, toId, 4, 5)(solved)
val rewrittenExpand = PruningVarExpand(allNodes, fromId, dir, Seq.empty, toId, 4, 5)(solved)
val expectedOutput = Distinct(rewrittenExpand, Map("to" -> Variable("to")(pos)))(solved)

rewrite(input) should equal(expectedOutput)
Expand Down
Expand Up @@ -167,10 +167,6 @@ case class CommunityPipeBuilder(monitors: Monitors, recurse: LogicalPlan => Pipe
val predicate = varLengthPredicate(predicates)
PruningVarLengthExpandPipe(source, from, toName, LazyTypes(types.toArray), dir, minLength, maxLength, predicate)()

case FullPruningVarExpand(_, from, dir, types, toName, minLength, maxLength, predicates) =>
val predicate = varLengthPredicate(predicates)
FullPruningVarLengthExpandPipe(source, from, toName, LazyTypes(types.toArray), dir, minLength, maxLength, predicate)()

case Sort(_, sortItems) =>
SortPipe(source, sortItems.map(translateColumnOrder))(id = id)

Expand Down

0 comments on commit 66996b6

Please sign in to comment.