forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-2716] [gelly] [apis] New checksum method on DataSet and Graph
This closes apache#1462
- Loading branch information
1 parent
98fad04
commit a8be52a
Showing
9 changed files
with
352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...braries/flink-gelly-scala/src/main/scala/org/apache/flink/graph/scala/utils/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.flink.graph.scala | ||
|
||
import org.apache.flink.api.common.typeinfo.TypeInformation | ||
import org.apache.flink.api.java.Utils.ChecksumHashCode | ||
import org.apache.flink.api.scala._ | ||
import org.apache.flink.api.scala.utils._ | ||
|
||
import scala.reflect.ClassTag | ||
|
||
package object utils { | ||
/** | ||
* This class provides utility methods for computing checksums over a Graph. | ||
* | ||
* @param self Graph | ||
*/ | ||
implicit class GraphUtils[K: TypeInformation : ClassTag, VV: TypeInformation : ClassTag, EV: | ||
TypeInformation : ClassTag](val self: Graph[K, VV, EV]) { | ||
|
||
/** | ||
* Computes the ChecksumHashCode over the Graph. | ||
* | ||
* @return the ChecksumHashCode over the vertices and edges. | ||
*/ | ||
@throws(classOf[Exception]) | ||
def checksumHashCode(): ChecksumHashCode = { | ||
val checksum: ChecksumHashCode = self.getVertices.checksumHashCode() | ||
checksum.add(self.getEdges checksumHashCode()) | ||
checksum | ||
} | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...-gelly-scala/src/test/scala/org/apache/flink/graph/scala/test/util/GraphUtilsITCase.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.flink.graph.scala.test.util | ||
|
||
import org.apache.flink.api.scala._ | ||
import org.apache.flink.graph.scala._ | ||
import org.apache.flink.graph.scala.utils._ | ||
import org.apache.flink.graph.scala.test.TestGraphUtils | ||
import org.apache.flink.test.util.MultipleProgramsTestBase | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
|
||
@RunWith(classOf[Parameterized]) | ||
class GraphUtilsITCase(mode: MultipleProgramsTestBase.TestExecutionMode) extends | ||
MultipleProgramsTestBase(mode) { | ||
|
||
@Test | ||
@throws(classOf[Exception]) | ||
def testChecksumHashCodeVerticesAndEdges() { | ||
val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment | ||
val graph: Graph[Long, Long, Long] = Graph.fromDataSet(TestGraphUtils | ||
.getLongLongVertexData(env), TestGraphUtils.getLongLongEdgeData(env), env) | ||
val checksum = graph.checksumHashCode() | ||
assertEquals(checksum.getCount, 12L) | ||
assertEquals(checksum.getChecksum, 19665L) | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
flink-libraries/flink-gelly/src/main/java/org/apache/flink/graph/utils/GraphUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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.flink.graph.utils; | ||
|
||
import org.apache.flink.api.java.Utils; | ||
import org.apache.flink.api.java.Utils.ChecksumHashCode; | ||
import org.apache.flink.api.java.utils.DataSetUtils; | ||
import org.apache.flink.graph.Graph; | ||
|
||
public class GraphUtils { | ||
|
||
/** | ||
* Computes the checksum over the Graph | ||
* | ||
* @return the checksum over the vertices and edges. | ||
*/ | ||
public static Utils.ChecksumHashCode checksumHashCode(Graph graph) throws Exception { | ||
ChecksumHashCode checksum = DataSetUtils.checksumHashCode(graph.getVertices()); | ||
checksum.add(DataSetUtils.checksumHashCode(graph.getEdges())); | ||
return checksum; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ibraries/flink-gelly/src/test/java/org/apache/flink/graph/test/util/GraphUtilsITCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.flink.graph.test.util; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.apache.flink.api.java.ExecutionEnvironment; | ||
import org.apache.flink.api.java.Utils.ChecksumHashCode; | ||
import org.apache.flink.graph.Graph; | ||
import org.apache.flink.graph.test.TestGraphUtils; | ||
import org.apache.flink.graph.utils.GraphUtils; | ||
import org.apache.flink.test.util.MultipleProgramsTestBase; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
public class GraphUtilsITCase extends MultipleProgramsTestBase { | ||
|
||
public GraphUtilsITCase(TestExecutionMode mode){ | ||
super(mode); | ||
} | ||
|
||
@Test | ||
public void testChecksumHashCodeVerticesAndEdges() throws Exception { | ||
/* | ||
* Test checksum hashcode | ||
*/ | ||
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); | ||
|
||
Graph<Long, Long, Long> graph = Graph.fromDataSet( | ||
TestGraphUtils.getLongLongVertexData(env), | ||
TestGraphUtils.getLongLongEdgeData(env), | ||
env); | ||
|
||
ChecksumHashCode checksum = GraphUtils.checksumHashCode(graph); | ||
|
||
assertEquals(checksum.getCount(), 12L); | ||
assertEquals(checksum.getChecksum(), 19665L); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.