This repository has been archived by the owner on Oct 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from Nicole00/sjs_poc
add GraphTriangleCount algorithm
- Loading branch information
Showing
4 changed files
with
54 additions
and
5 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
38 changes: 38 additions & 0 deletions
38
nebula-algorithm/src/main/scala/com/vesoft/nebula/algorithm/lib/GraphTriangleCountAlgo.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,38 @@ | ||
/* Copyright (c) 2020 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
package com.vesoft.nebula.algorithm.lib | ||
|
||
import com.vesoft.nebula.algorithm.config.AlgoConstants | ||
import org.apache.spark.sql.{DataFrame, Dataset, Row, SparkSession} | ||
import org.apache.spark.sql.types.{IntegerType, LongType, StructField, StructType} | ||
|
||
/** | ||
* compute all graph's triangle count | ||
*/ | ||
object GraphTriangleCountAlgo { | ||
|
||
def apply(spark: SparkSession, dataset: Dataset[Row]): DataFrame = { | ||
|
||
val triangleCount = TriangleCountAlgo(spark, dataset) | ||
val count = triangleCount | ||
.select(AlgoConstants.TRIANGLECOUNT_RESULT_COL) | ||
.rdd | ||
.map(value => value.get(0).asInstanceOf[Int]) | ||
.reduce(_ + _) / 3 | ||
val list = List(count) | ||
val rdd = spark.sparkContext.parallelize(list).map(row => Row(row)) | ||
|
||
val schema = StructType( | ||
List( | ||
StructField("count", IntegerType, nullable = false) | ||
)) | ||
val algoResult = spark.sqlContext | ||
.createDataFrame(rdd, schema) | ||
|
||
algoResult | ||
} | ||
} |
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