Skip to content

Conversation

@goungoun
Copy link
Contributor

@goungoun goungoun commented Jan 9, 2026

What changes were proposed in this pull request?

This PR removes the limitation from a fixed-length pattern. It should work with chaining with other patterns such as:
(u)-[*2]->(v);(v)-[]->(k), (u)-[]->(v);(v)-[*2]->(k);(a)-[*1]->(b);(b)-[*2]->(c);(c)-[*3]->(d)

Why are the changes needed?

The current version cannot parse a chained pattern when it is with a fixed-length pattern.

image

Error:

scala> g.find("(a)-[*2]->(b);(b)-[]->(c)").where("a.id == 0").show()
org.graphframes.InvalidParseException: Failed to parse bad motif string: '(a)-[*2]->(b);(b)-[]->(c)'.  Returned message: end of input expected
  at org.graphframes.pattern.Pattern$.parse(patterns.scala:83)
  at org.graphframes.GraphFrame.findAugmentedPatterns(GraphFrame.scala:520)
  at org.graphframes.GraphFrame.find(GraphFrame.scala:515)
  ... 42 elided

Expected:

+---------+---------+---------+---------+
|        a|     _ab1|        b|        c|
+---------+---------+---------+---------+
|{0, a, f}|{1, b, m}|{2, c, m}|{0, a, f}|
|{0, a, f}|{1, b, m}|{2, c, m}|{3, d, f}|
|{0, a, f}|{1, b, m}|{0, a, f}|{1, b, m}|
+---------+---------+---------+---------+

How does it work?

The fixed-length vertex generation logic is moved to the query rewrite phase. The naming rule for generating interim vertexes has changed from _v1, _v2, _v3 to _uv1, _uv2, _uv3, where the names are derived by combining the source and target vertex names u and v. This behavior change is inevitable to prevent duplication. For example, in the pattern (b)-[*2]->(c);(c)-[*3]->(d) _v1 should not be generated twice, as it would result in duplicated column name. Instead, _bc and _cd will be generated.

Before: Parser

val midVertices = (1 until hop).map(i => NamedVertex(s"_v$i"))

After: Pattern Rewrite

val midVertices = (1 until hop).map(i => s"_${src}${dst}${i}")

@goungoun goungoun changed the title fix: allow chaining with fixed-length patterns [WIP] fix: allow chaining with fixed-length patterns Jan 9, 2026
@goungoun goungoun marked this pull request as draft January 9, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant