Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/src/main/scala/org/graphframes/GraphFrame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ class GraphFrame private (
* @group motif
*/
def find(pattern: String): DataFrame = {
val VarLengthPattern = """\((\w+)\)-\[(\w*)\*(\d*)\.\.(\d*)\]-(>?)\((\w+)\)""".r
val FixedLengthUndirectedPattern = """\((\w+)\)-\[(\w*)\*(\d*)\]-\((\w+)\)""".r
val VarLengthPattern = """\((\w*)\)-\[(\w*)\*(\d*)\.\.(\d*)\]-(>?)\((\w*)\)""".r
val FixedLengthUndirectedPattern = """\((\w*)\)-\[(\w*)\*(\d*)\]-\((\w*)\)""".r

pattern match {
case VarLengthPattern(src, name, min, max, direction, dst) =>
Expand Down Expand Up @@ -537,7 +537,9 @@ class GraphFrame private (
val augmentedPatterns = extraPositivePatterns ++ patterns
val df = findSimple(augmentedPatterns)

val names = Pattern.findNamedElementsInOrder(patterns, includeEdges = true)
val names = Pattern
.findNamedElementsInOrder(patterns, includeEdges = true)
.filter(x => !x.startsWith("__tmpv"))
if (names.isEmpty) df else df.select(quote(names.head), names.tail.map(quote): _*)
}

Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/org/graphframes/pattern/patterns.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ private[graphframes] object Pattern {
case fixedLengthPattern(negation, src, name, num, dst) =>
val hop: Int = num.toInt
if (hop > 0) {
val midVertices = (1 until hop).map(i => s"_${src}${dst}${i}")
val midVertices =
if (src.isEmpty && dst.isEmpty) (1 until hop).map(i => s"__tmpv${i}")
else (1 until hop).map(i => s"_${src}${dst}${i}")
val vertices = src +: midVertices :+ dst
vertices
.sliding(2)
Expand Down
15 changes: 15 additions & 0 deletions core/src/test/scala/org/graphframes/PatternMatchSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,21 @@ class PatternMatchSuite extends SparkFunSuite with GraphFrameTestSparkContext {
assert(res.except(expected).isEmpty && expected.except(res).isEmpty)
}

test("undirected edge without vertex name") {
val res = g.find("()-[e*3]-()").drop("_pattern").collect().toSet
val expected =
g.find("(u)-[e*3]-(v)").select("_e1", "_e2", "_e3", "_hop", "_direction").collect().toSet

compareResultToExpected(res, expected)
}

test("directed edge name without vertex name") {
val res = g.find("()-[e*3]->()").collect().toSet
val expected = g.find("(u)-[e*3]->(v)").select("_e1", "_e2", "_e3").collect().toSet

compareResultToExpected(res, expected)
}

test("stateful predicates via UDFs") {
val chain4 = g
.find("(a)-[ab]->(b); (b)-[bc]->(c); (c)-[cd]->(d)")
Expand Down