You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@s2graph.apache.org by st...@apache.org on 2018/06/15 07:34:17 UTC
[1/7] incubator-s2graph git commit: add operations not supported on
sql
Repository: incubator-s2graph
Updated Branches:
refs/heads/master 5706bbf1d -> 70a7c71a3
add operations not supported on sql
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/f42885bc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/f42885bc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/f42885bc
Branch: refs/heads/master
Commit: f42885bc5fe315217bf40bbbef21557c06f52586
Parents: 33e3d26
Author: Chul Kang <el...@apache.org>
Authored: Fri Jun 8 00:01:18 2018 +0900
Committer: Chul Kang <el...@apache.org>
Committed: Fri Jun 8 00:01:18 2018 +0900
----------------------------------------------------------------------
.../apache/s2graph/s2jobs/task/Process.scala | 64 +++++++++++++++++++-
1 file changed, 63 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f42885bc/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Process.scala
----------------------------------------------------------------------
diff --git a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Process.scala b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Process.scala
index 6bc100f..c077f5b 100644
--- a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Process.scala
+++ b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Process.scala
@@ -20,6 +20,7 @@
package org.apache.s2graph.s2jobs.task
import org.apache.spark.sql.{DataFrame, SparkSession}
+import play.api.libs.json.Json
/**
* Process
@@ -47,7 +48,68 @@ class SqlProcess(conf:TaskConf) extends Process(conf) {
val sql = conf.options("sql")
logger.debug(s"${LOG_PREFIX} sql : $sql")
- ss.sql(sql)
+ postProcess(ss.sql(sql))
}
+
+ /**
+ * extraOperations
+ * @param df
+ * @return
+ */
+ private def postProcess(df: DataFrame): DataFrame = {
+ import org.apache.spark.sql.functions._
+
+ var resultDF = df
+
+ // watermark
+ val timeColumn = conf.options.get(s"time.column")
+ logger.debug(s">> timeColumn: ${timeColumn}")
+
+ val waterMarkDelayTime = conf.options.get(s"watermark.delay.time")
+ if (waterMarkDelayTime.isDefined){
+ logger.debug(s">> waterMarkDelayTime : ${waterMarkDelayTime}")
+ if (timeColumn.isDefined) {
+ resultDF = resultDF.withWatermark(timeColumn.get, waterMarkDelayTime.get)
+ } else logger.warn("time.column does not exists.. cannot apply watermark")
+ }
+
+ // drop duplication
+ val dropDuplicateColumns = conf.options.get("drop.duplicate.columns")
+ if (dropDuplicateColumns.isDefined) {
+ logger.debug(s">> dropDuplicates : ${dropDuplicateColumns}")
+ resultDF = resultDF.dropDuplicates(dropDuplicateColumns.get.split(","))
+ }
+
+ // groupBy
+ val groupedKeysOpt = conf.options.get(s"grouped.keys")
+ if (groupedKeysOpt.isDefined) {
+ var groupedKeys = groupedKeysOpt.get.split(",").map{ key =>
+ col(key.trim)
+ }.toSeq
+
+ val windowDurationOpt = conf.options.get(s"grouped.window.duration")
+ val slideDurationOpt = conf.options.get(s"grouped.slide.duration")
+ if (windowDurationOpt.isDefined && slideDurationOpt.isDefined){
+ logger.debug(s">> using window operation : Duration ${windowDurationOpt}, slideDuration : ${slideDurationOpt}")
+ groupedKeys = groupedKeys ++ Seq(window(col(timeColumn.get), windowDurationOpt.get, slideDurationOpt.get))
+ }
+ logger.debug(s">> groupedKeys: ${groupedKeys}")
+
+ // aggregate options
+ val aggExprs = Json.parse(conf.options.getOrElse(s"grouped.dataset.agg", "[\"count(1)\"]")).as[Seq[String]].map(expr(_))
+ logger.debug(s">> aggr : ${aggExprs}")
+
+ val groupedDF = resultDF.groupBy(groupedKeys: _*)
+
+ resultDF = if (aggExprs.size > 1) {
+ groupedDF.agg(aggExprs.head, aggExprs.tail: _*)
+ } else {
+ groupedDF.agg(aggExprs.head)
+ }
+ }
+
+ resultDF
+ }
+
}
[7/7] incubator-s2graph git commit: [S2GRAPH-218] add operations not
supported on sql
Posted by st...@apache.org.
[S2GRAPH-218] add operations not supported on sql
JIRA:
[S2GRAPH-218] https://issues.apache.org/jira/browse/S2GRAPH-218
Pull Request:
Closes #169
Author
Chul Kang <el...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/70a7c71a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/70a7c71a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/70a7c71a
Branch: refs/heads/master
Commit: 70a7c71a33f89a8d7ca9eac4541987ad9cea1504
Parents: 3da42fc
Author: DO YUNG YOON <st...@apache.org>
Authored: Fri Jun 15 16:33:38 2018 +0900
Committer: DO YUNG YOON <st...@apache.org>
Committed: Fri Jun 15 16:33:38 2018 +0900
----------------------------------------------------------------------
CHANGES | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/70a7c71a/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 1f82a5e..58caf4e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -37,6 +37,7 @@ Release Notes - S2Graph - Version 0.2.0
* [S2GRAPH-197] - Provide S2graphSink for non-streaming dataset
* [S2GRAPH-205] - too many initialize S2Graph when writeBatchMutate on S2GraphSink
* [S2GRAPH-201] - Provide S2GraphSource
+ * [S2GRAPH-218] - add operations not supported on sql
** Bug
* [S2GRAPH-159] - Wrong syntax at a bash script under Linux
[5/7] incubator-s2graph git commit: add continuous trigger option
Posted by st...@apache.org.
add continuous trigger option
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/29a4ed9f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/29a4ed9f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/29a4ed9f
Branch: refs/heads/master
Commit: 29a4ed9fe4e0768a86511086fc3c949fcab47e1c
Parents: 488a56d
Author: Chul Kang <el...@apache.org>
Authored: Fri Jun 8 00:14:59 2018 +0900
Committer: Chul Kang <el...@apache.org>
Committed: Fri Jun 8 00:14:59 2018 +0900
----------------------------------------------------------------------
s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/29a4ed9f/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala
----------------------------------------------------------------------
diff --git a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala
index f7c72cc..720c2d7 100644
--- a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala
+++ b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala
@@ -69,6 +69,8 @@ abstract class Sink(queryName: String, override val conf: TaskConf) extends Task
}
val interval = conf.options.getOrElse("interval", DEFAULT_TRIGGER_INTERVAL)
val checkpointLocation = conf.options.getOrElse("checkpointLocation", DEFAULT_CHECKPOINT_LOCATION)
+ val isContinuous = conf.options.getOrElse("isContinuous", "false").toBoolean
+ val trigger = if (isContinuous) Trigger.Continuous(interval) else Trigger.ProcessingTime(interval)
val cfg = conf.options ++ Map("checkpointLocation" -> checkpointLocation)
@@ -78,7 +80,7 @@ abstract class Sink(queryName: String, override val conf: TaskConf) extends Task
.queryName(s"${queryName}_${conf.name}")
.format(FORMAT)
.options(cfg)
- .trigger(Trigger.ProcessingTime(interval))
+ .trigger(trigger)
.outputMode(mode)
.start()
}
[6/7] incubator-s2graph git commit: Merge branch 'S2GRAPH-218' of
https://github.com/elric-k/incubator-s2graph into elric-k-S2GRAPH-218
Posted by st...@apache.org.
Merge branch 'S2GRAPH-218' of https://github.com/elric-k/incubator-s2graph into elric-k-S2GRAPH-218
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/3da42fc3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/3da42fc3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/3da42fc3
Branch: refs/heads/master
Commit: 3da42fc367df451ffcdd18f71d3d31d24005f13f
Parents: 5706bbf 29a4ed9
Author: DO YUNG YOON <st...@apache.org>
Authored: Fri Jun 15 16:32:22 2018 +0900
Committer: DO YUNG YOON <st...@apache.org>
Committed: Fri Jun 15 16:32:22 2018 +0900
----------------------------------------------------------------------
.../scala/org/apache/s2graph/s2jobs/Job.scala | 11 +++-
.../apache/s2graph/s2jobs/task/Process.scala | 64 +++++++++++++++++++-
.../org/apache/s2graph/s2jobs/task/Sink.scala | 6 +-
.../org/apache/s2graph/s2jobs/task/Source.scala | 17 +++++-
.../org/apache/s2graph/s2jobs/task/Task.scala | 3 +-
5 files changed, 91 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
[2/7] incubator-s2graph git commit: support multiple partitions
Posted by st...@apache.org.
support multiple partitions
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/63727f32
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/63727f32
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/63727f32
Branch: refs/heads/master
Commit: 63727f32c35b54ec07ed1f74df9671f3e9d26ba7
Parents: f42885b
Author: Chul Kang <el...@apache.org>
Authored: Fri Jun 8 00:04:25 2018 +0900
Committer: Chul Kang <el...@apache.org>
Committed: Fri Jun 8 00:04:25 2018 +0900
----------------------------------------------------------------------
s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/63727f32/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala
----------------------------------------------------------------------
diff --git a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala
index ae88b6d..f7c72cc 100644
--- a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala
+++ b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Sink.scala
@@ -93,7 +93,7 @@ abstract class Sink(queryName: String, override val conf: TaskConf) extends Task
case _ => SaveMode.Overwrite
}
- val partitionedWriter = if (partitionsOpt.isDefined) writer.partitionBy(partitionsOpt.get) else writer
+ val partitionedWriter = if (partitionsOpt.isDefined) writer.partitionBy(partitionsOpt.get.split(","): _*) else writer
writeBatchInner(partitionedWriter.format(FORMAT).mode(mode))
}
[3/7] incubator-s2graph git commit: add dataframe cache option
Posted by st...@apache.org.
add dataframe cache option
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/d93e5de4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/d93e5de4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/d93e5de4
Branch: refs/heads/master
Commit: d93e5de4a89d5fbf195acb09d467b103f564a439
Parents: 63727f3
Author: Chul Kang <el...@apache.org>
Authored: Fri Jun 8 00:07:50 2018 +0900
Committer: Chul Kang <el...@apache.org>
Committed: Fri Jun 8 00:07:50 2018 +0900
----------------------------------------------------------------------
.../src/main/scala/org/apache/s2graph/s2jobs/Job.scala | 11 +++++++++--
.../main/scala/org/apache/s2graph/s2jobs/task/Task.scala | 3 +--
2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/d93e5de4/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/Job.scala
----------------------------------------------------------------------
diff --git a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/Job.scala b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/Job.scala
index 717d087..8f21bc2 100644
--- a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/Job.scala
+++ b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/Job.scala
@@ -29,7 +29,12 @@ class Job(ss:SparkSession, jobDesc:JobDescription) extends Serializable with Log
def run() = {
// source
- jobDesc.sources.foreach{ source => dfMap.put(source.conf.name, source.toDF(ss))}
+ jobDesc.sources.foreach{ source =>
+ val df = source.toDF(ss)
+ if (source.conf.cache.getOrElse(false) && !df.isStreaming) df.cache()
+
+ dfMap.put(source.conf.name, df)
+ }
logger.debug(s"valid source DF set : ${dfMap.keySet}")
// process
@@ -64,7 +69,9 @@ class Job(ss:SparkSession, jobDesc:JobDescription) extends Serializable with Log
}
.map { p =>
val inputMap = p.conf.inputs.map{ input => (input, dfMap(input)) }.toMap
- p.conf.name -> p.execute(ss, inputMap)
+ val df = p.execute(ss, inputMap)
+ if (p.conf.cache.getOrElse(false) && !df.isStreaming) df.cache()
+ p.conf.name -> df
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/d93e5de4/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Task.scala
----------------------------------------------------------------------
diff --git a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Task.scala b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Task.scala
index ea42828..1210132 100644
--- a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Task.scala
+++ b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Task.scala
@@ -42,8 +42,7 @@ object TaskConf {
taskConf.options.filterKeys(_.startsWith("cache.")).mapValues(_.toInt)
}
}
-
-case class TaskConf(name: String, `type`: String, inputs: Seq[String] = Nil, options: Map[String, String] = Map.empty)
+case class TaskConf(name:String, `type`:String, inputs:Seq[String] = Nil, options:Map[String, String] = Map.empty, cache:Option[Boolean]=None)
trait Task extends Serializable with Logger {
val conf: TaskConf
[4/7] incubator-s2graph git commit: add partition options for source
df
Posted by st...@apache.org.
add partition options for source df
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/488a56d7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/488a56d7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/488a56d7
Branch: refs/heads/master
Commit: 488a56d7685ce916e0e37fb65b77c43d5e4583fc
Parents: d93e5de
Author: Chul Kang <el...@apache.org>
Authored: Fri Jun 8 00:13:37 2018 +0900
Committer: Chul Kang <el...@apache.org>
Committed: Fri Jun 8 00:13:37 2018 +0900
----------------------------------------------------------------------
.../org/apache/s2graph/s2jobs/task/Source.scala | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/488a56d7/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Source.scala
----------------------------------------------------------------------
diff --git a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Source.scala b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Source.scala
index 9c80e58..259cfc0 100644
--- a/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Source.scala
+++ b/s2jobs/src/main/scala/org/apache/s2graph/s2jobs/task/Source.scala
@@ -40,19 +40,30 @@ class KafkaSource(conf:TaskConf) extends Source(conf) {
val DEFAULT_FORMAT = "raw"
override def mandatoryOptions: Set[String] = Set("kafka.bootstrap.servers", "subscribe")
+ def repartition(df: DataFrame, defaultParallelism: Int) = {
+ conf.options.get("numPartitions").map(n => Integer.parseInt(n)) match {
+ case Some(numOfPartitions: Int) =>
+ logger.info(s"[repartitition] $numOfPartitions ($defaultParallelism)")
+ if (numOfPartitions >= defaultParallelism) df.repartition(numOfPartitions)
+ else df.coalesce(numOfPartitions)
+ case None => df
+ }
+ }
+
override def toDF(ss:SparkSession):DataFrame = {
logger.info(s"${LOG_PREFIX} options: ${conf.options}")
val format = conf.options.getOrElse("format", "raw")
val df = ss.readStream.format("kafka").options(conf.options).load()
+ val partitionedDF = repartition(df, df.sparkSession.sparkContext.defaultParallelism)
format match {
- case "raw" => df
- case "json" => parseJsonSchema(ss, df)
+ case "raw" => partitionedDF
+ case "json" => parseJsonSchema(ss, partitionedDF)
// case "custom" => parseCustomSchema(df)
case _ =>
logger.warn(s"${LOG_PREFIX} unsupported format '$format'.. use default schema ")
- df
+ partitionedDF
}
}