测试spark
This commit is contained in:
parent
4a112f3038
commit
6749b4ef03
|
@ -2,8 +2,11 @@ package org.jeecg.sy;
|
|||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.spark.sql.Dataset;
|
||||
import org.apache.spark.sql.Row;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -33,6 +36,8 @@ public class Controller {
|
|||
list.set(i, list.get(list.size() - i - 1));
|
||||
list.set(list.size() - i - 1, temp);
|
||||
}
|
||||
|
||||
String df = Test$.MODULE$.getString();
|
||||
return Result.ok(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package org.jeecg.sy
|
||||
|
||||
import org.apache.spark.sql.{DataFrame, SparkSession}
|
||||
|
||||
object Test {
|
||||
def getString(): String = {
|
||||
// 本地模式
|
||||
val spark = SparkSession.builder()
|
||||
.appName("SparkDemo")
|
||||
.master("local")
|
||||
.getOrCreate()
|
||||
// 输出spark的版本信息
|
||||
// 去除所有日志
|
||||
spark.sparkContext.setLogLevel("WARN")
|
||||
println("-----------------------\n\n\n\n\n\n")
|
||||
// 产生是十个随机的数
|
||||
val data = 1 to 10
|
||||
// 生成RDD
|
||||
val distData = spark.sparkContext.parallelize(data)
|
||||
// 求出数字出现的次数
|
||||
val counts = distData.map(n => (n, 1)).reduceByKey(_ + _)
|
||||
// 打印结果
|
||||
counts.collect().foreach(println)
|
||||
println("\n\n\n\n\n\n-----------------------")
|
||||
// 返回一个文字66
|
||||
return "66"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue