-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
20 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
13 changes: 13 additions & 0 deletions
13
spark-poc/sparkJob/src/main/scala/dev/config/SparkConfig.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,13 @@ | ||
package dev.config | ||
|
||
import org.ini4j.spi.OptionsParser | ||
|
||
object SparkConfig { | ||
|
||
// def parser(config: String): OptionsParser[T] = { | ||
// new OptionsParser[T](config){ | ||
// //head(config) | ||
// } | ||
// } | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,48 @@ | ||
package spark | ||
|
||
import config.AppConfig | ||
import driver.SparkDriver | ||
import org.apache.spark.SparkConf | ||
import org.apache.spark.sql.SparkSession | ||
import org.slf4j.LoggerFactory | ||
|
||
object myJob1 { | ||
|
||
def main(args: Array[String]): Unit = { | ||
|
||
val logger = LoggerFactory.getLogger(this.getClass) | ||
//logger.info(AppConfig.dump) | ||
|
||
val conf = new SparkConf() | ||
.setAppName("myJob1") | ||
.setMaster("local[*]") | ||
|
||
//val s_driver = SparkDriver.getSparkSession("myJob1"); | ||
val s_context = SparkDriver.getSparkContext("myJob1", conf); | ||
val sc = SparkDriver.getSparkContext("myJob1", conf); | ||
val spark = SparkDriver | ||
|
||
//println("s_driver = " + s_driver) | ||
println("s_context = " + s_context) | ||
println("sc = " + sc) | ||
println("spark = " + spark) | ||
|
||
val rdd1 = s_context.makeRDD(1 to 4, 2) | ||
val rdd1 = sc.makeRDD(1 to 4, 2) | ||
|
||
println(rdd1.aggregate(0)(_ + _, _ + _)) // 10 | ||
|
||
println(rdd1.aggregate(1)(_ + _, _ + _)) // 13 | ||
|
||
println("================") | ||
|
||
val rdd2 = sc.makeRDD(1 to 4, 4) | ||
|
||
println(rdd2.aggregate(1)(_ + _, _ + _)) // 15 | ||
|
||
println("================") | ||
|
||
// compare : fold | ||
|
||
println(rdd1.fold(0)(_ + _)) // 10 | ||
|
||
println(rdd1.fold(1)(_ + _)) // 13 | ||
|
||
println(">>> SparkApp1 end ") | ||
} | ||
|
||
} |