diff --git a/s2core/src/main/scala/org/apache/s2graph/core/GraphElementBuilder.scala b/s2core/src/main/scala/org/apache/s2graph/core/GraphElementBuilder.scala index c8c25b36..a6515fbd 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/GraphElementBuilder.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/GraphElementBuilder.scala @@ -69,7 +69,7 @@ class GraphElementBuilder(graph: S2GraphLike) { val (ts, operation, logType, srcId, tgtId, label) = (parts(0), parts(1), parts(2), parts(3), parts(4), parts(5)) val props = if (parts.length >= 7) fromJsonToProperties(Json.parse(parts(6)).asOpt[JsObject].getOrElse(Json.obj())) else Map.empty[String, Any] val tempDirection = if (parts.length >= 8) parts(7) else "out" - val direction = if (tempDirection != "out" && tempDirection != "in") "out" else tempDirection + val direction = if (tempDirection != "out" && tempDirection != "in" && tempDirection != "undirected") "out" else tempDirection val edge = toEdge(srcId, tgtId, label, direction, props, ts.toLong, operation) Option(edge) } recover { diff --git a/s2core/src/test/scala/org/apache/s2graph/core/GraphElementBuilderTest.scala b/s2core/src/test/scala/org/apache/s2graph/core/GraphElementBuilderTest.scala new file mode 100644 index 00000000..33b9e757 --- /dev/null +++ b/s2core/src/test/scala/org/apache/s2graph/core/GraphElementBuilderTest.scala @@ -0,0 +1,57 @@ +package org.apache.s2graph.core + +import org.apache.s2graph.core.mysqls.Label +import org.scalatest._ + +class GraphElementBuilderTest extends FunSuite with Matchers with TestCommon with TestCommonWithModels { + initTests() + + /* + In Test CommonWithModels, + - labelName: undirectedLabelName is created as undirected label. + - labelName: labelName is created as directed label. + */ + val timestamp = "1" + val operation = "insert" + val logType = "edge" + val srcId = 1L + val tgtId = 101L + val props = "{}" + val outDirection = "out" + val inDirection = "in" + + + test("toEdge with directed label. direction out.") { + val parts = Array( + timestamp, operation, logType, srcId.toString, tgtId.toString, labelName, props, outDirection + ) + + val s2EdgeLike = builder.toEdge(parts).get + s2EdgeLike.srcVertex.id.innerId.value shouldBe(srcId) + s2EdgeLike.tgtVertex.id.innerId.value shouldBe(tgtId) + s2EdgeLike.getDirection() shouldBe("out") + + } + test("toEdge with directed label. direction in.") { + val parts = Array( + timestamp, operation, logType, srcId.toString, tgtId.toString, labelName, props, inDirection + ) + + val s2EdgeLike = builder.toEdge(parts).get + s2EdgeLike.srcVertex.id.innerId.value shouldBe(srcId) + s2EdgeLike.tgtVertex.id.innerId.value shouldBe(tgtId) + s2EdgeLike.getDirection() shouldBe("in") + + } + test("toEdge with undirected label. direction out.") { + // undirectedLabelName has tgtColumnType as string. + val parts = Array( + timestamp, operation, logType, srcId.toString, tgtId.toString, undirectedLabelName, props, outDirection + ) + + val s2EdgeLike = builder.toEdge(parts).get + s2EdgeLike.srcVertex.id.innerId.value shouldBe(srcId) + s2EdgeLike.tgtVertex.id.innerId.value shouldBe(tgtId.toString) + s2EdgeLike.getDirection() shouldBe("out") + } +}