[GitHub] [spark] dongjoon-hyun commented on a change in pull request #24851: [SPARK-27303][GRAPH] Add PropertyGraph construction API

2019-06-12 Thread GitBox
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_r292998259
 
 

 ##
 File path: 
graph/api/src/main/scala/org/apache/spark/graph/api/CypherSession.scala
 ##
 @@ -0,0 +1,139 @@
+/*
+ * 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.
+ *
 
 Review comment:
   ```
   $ dev/scalastyle
   [error] 
/home/jenkins/workspace/SparkPullRequestBuilder/graph/api/src/main/scala/org/apache/spark/graph/api/CypherSession.scala:16:
 Header does not match expected text
   [error] 
/home/jenkins/workspace/SparkPullRequestBuilder/graph/api/src/main/scala/org/apache/spark/graph/api/PropertyGraph.scala:16:
 Header does not match expected text
   [error] 
/home/jenkins/workspace/SparkPullRequestBuilder/graph/api/src/main/scala/org/apache/spark/graph/api/GraphElementFrame.scala:16:
 Header does not match expected text
   [error] 
/home/jenkins/workspace/SparkPullRequestBuilder/graph/api/src/main/scala/org/apache/spark/graph/api/PropertyGraphType.scala:16:
 Header does not match expected text
   ```


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



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #24851: [SPARK-27303][GRAPH] Add PropertyGraph construction API

2019-06-12 Thread GitBox
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_r292997721
 
 

 ##
 File path: 
graph/api/src/test/java/org/apache/spark/graph/api/JavaPropertyGraphSuite.java
 ##
 @@ -0,0 +1,90 @@
+/*
+ * 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 com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.RowFactory;
+import org.apache.spark.sql.test.TestSparkSession;
+import org.apache.spark.sql.types.DataType;
+import org.apache.spark.sql.types.DataTypes;
+import org.apache.spark.sql.types.StructField;
+import org.apache.spark.sql.types.StructType;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public abstract class JavaPropertyGraphSuite implements Serializable {
+private transient TestSparkSession spark;
+private transient CypherSession cypherSession = null;
+
+@Before
+public void setUp() {
+spark = new TestSparkSession();
+}
+
+@After
+public void tearDown() {
+spark.stop();
+spark = null;
+}
+
+@Test
+public void testCreateFromNodeFrame() {
+StructType personSchema = createSchema(
+Lists.newArrayList("id", "name"),
+Lists.newArrayList(DataTypes.LongType, DataTypes.StringType));
+
+List personData = Arrays.asList(
+RowFactory.create(0L, "Alice"),
+RowFactory.create(1L, "Bob"));
+
+StructType knowsSchema = createSchema(
+Lists.newArrayList("id", "source", "target", "since"),
+Lists.newArrayList(DataTypes.LongType, DataTypes.LongType, 
DataTypes.LongType, DataTypes.IntegerType));
+
+List knowsData = Collections.singletonList(RowFactory.create(0L, 
0L, 1L, 1984));
+
+Dataset personDf = spark.createDataFrame(personData, 
personSchema);
+NodeFrame personNodeFrame = NodeFrame.create(personDf, "id", 
Sets.newHashSet("Person"));
+
+Dataset knowsDf = spark.createDataFrame(knowsData, knowsSchema);
+RelationshipFrame knowsRelFrame = RelationshipFrame.create(knowsDf, 
"id", "source", "target", "KNOWS");
+
+PropertyGraph graph = 
cypherSession.createGraph(Lists.newArrayList(personNodeFrame), 
Lists.newArrayList(knowsRelFrame));
+List result = graph.nodes().collectAsList();
+Assert.assertEquals(1, result.size());
+}
+
+private StructType createSchema(List fieldNames, List 
dataTypes) {
+List fields = new ArrayList<>();
+for (int i = 0; i < fieldNames.size(); i++) {
+fields.add(DataTypes.createStructField(fieldNames.get(i), 
dataTypes.get(i), true));
+}
+return DataTypes.createStructType(fields);
+}
+}
 
 Review comment:
   FYI, Apache Spark uses 2-space indentation for Java code, too. Please fix 
this one and consider that in the next PRs.
   


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



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #24851: [SPARK-27303][GRAPH] Add PropertyGraph construction API

2019-06-12 Thread GitBox
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_r292995823
 
 

 ##
 File path: 
graph/api/src/test/java/org/apache/spark/graph/api/JavaPropertyGraphSuite.java
 ##
 @@ -0,0 +1,90 @@
+/*
+ * 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 com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.RowFactory;
+import org.apache.spark.sql.test.TestSparkSession;
+import org.apache.spark.sql.types.DataType;
+import org.apache.spark.sql.types.DataTypes;
+import org.apache.spark.sql.types.StructField;
+import org.apache.spark.sql.types.StructType;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public abstract class JavaPropertyGraphSuite implements Serializable {
 
 Review comment:
   Is this `abstract` test suite used?
   


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



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #24851: [SPARK-27303][GRAPH] Add PropertyGraph construction API

2019-06-12 Thread GitBox
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_r292993795
 
 

 ##
 File path: 
graph/api/src/main/scala/org/apache/spark/graph/api/CypherSession.scala
 ##
 @@ -0,0 +1,139 @@
+/*
+ * 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.
+ *
 
 Review comment:
   Could you remove this new line? The other license header seems to have the 
same issue.


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



[GitHub] [spark] dongjoon-hyun commented on a change in pull request #24851: [SPARK-27303][GRAPH] Add PropertyGraph construction API

2019-06-12 Thread GitBox
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