dongjoon-hyun commented on a change in pull request #24851: 
[SPARK-27303][GRAPH] Add PropertyGraph construction API
URL: https://github.com/apache/spark/pull/24851#discussion_r292992944
 
 

 ##########
 File path: 
graph/api/src/test/scala/org/apache/spark/graph/api/PropertyGraphSuite.scala
 ##########
 @@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.spark.graph.api
+
+import org.apache.spark.graph.api.CypherSession.{
+  ID_COLUMN,
+  LABEL_COLUMN_PREFIX,
+  SOURCE_ID_COLUMN,
+  TARGET_ID_COLUMN
+}
+import org.apache.spark.sql.{DataFrame, QueryTest}
+import org.apache.spark.sql.test.SharedSparkSession
+import org.scalatest.Matchers
+
+abstract class PropertyGraphSuite extends QueryTest with SharedSparkSession 
with Matchers {
+
+  // Override in spark-cypher
+  type IdType = Long
+  def convertId(inputId: Long): IdType
+
+  def cypherSession: CypherSession
+
+  test("create graph from NodeFrame") {
+    val nodeData = spark.createDataFrame(Seq(0L -> "Alice", 1L -> 
"Bob")).toDF("id", "name")
+    val nodeFrame = NodeFrame.create(nodeData, "id", Set("Person"))
+    val graph = cypherSession.createGraph(Seq(nodeFrame), Seq.empty)
+
+    val expectedDf = spark
+      .createDataFrame(Seq((convertId(0L), true, "Alice"), (convertId(1L), 
true, "Bob")))
+      .toDF(ID_COLUMN, label("Person"), "name")
+
+    checkAnswer(graph.nodes, expectedDf)
+  }
+
+  test("create graph from NodeFrame and RelationshipFrame") {
+    val nodeData = spark.createDataFrame(Seq(0L -> "Alice", 1L -> 
"Bob")).toDF("id", "name")
+    val nodeFrame = NodeFrame.create(nodeData, "id", Set("Person"))
+
+    val relationshipData = spark
+      .createDataFrame(Seq((0L, 0L, 1L, 1984)))
+      .toDF("id", "source", "target", "since")
+    val relationshipFrame =
+      RelationshipFrame.create(relationshipData, "id", "source", "target", 
"KNOWS")
+
+    val graph = cypherSession.createGraph(Seq(nodeFrame), 
Seq(relationshipFrame))
+
+    val expectedNodeDf = spark
+      .createDataFrame(Seq((convertId(0L), true, "Alice"), (convertId(1L), 
true, "Bob")))
+      .toDF(ID_COLUMN, label("Person"), "name")
+
+    val expectedRelDf = spark
+      .createDataFrame(Seq((convertId(0L), convertId(0L), convertId(1L), true, 
1984)))
+      .toDF(ID_COLUMN, SOURCE_ID_COLUMN, TARGET_ID_COLUMN, label("KNOWS"), 
"since")
+
+    checkAnswer(graph.nodes, expectedNodeDf)
+    checkAnswer(graph.relationships, expectedRelDf)
+  }
+
+  test("create graph with multiple node and relationship types") {
+    val studentDF = spark
+      .createDataFrame(Seq((0L, "Alice", 42), (1L, "Bob", 23)))
+      .toDF("id", "name", "age")
+    val teacherDF = spark
+      .createDataFrame(Seq((2L, "Eve", "CS")))
+      .toDF("id", "name", "subject")
+
+    val studentNF =
+      NodeFrame.create(studentDF, "id", Set("Person", "Student"))
+    val teacherNF =
+      NodeFrame.create(teacherDF, "id", Set("Person", "Teacher"))
 
 Review comment:
   nit. If possible, shorter is better.
   ```scala
   val studentNF = NodeFrame.create(studentDF, "id", Set("Person", "Student"))
   val teacherNF = NodeFrame.create(teacherDF, "id", Set("Person", "Teacher"))
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to