Spark2 3 1使用技巧

2021-09-13 03:46:07 字數 735 閱讀 7545

case class studentinfo(id:long,name:string,age:int)

val example = spark.read.json("/data/result.json").as(studentinfo)

example.show()

在需要根據不同資料定義不同schema

val schemainfo = "name age"

val fields = schemainfo.map(item=> item.split(" ")

.map(item=>structfield(item,stringtype,nullable=true))

val schema = structtype(fields)

val rowrdd = peoplerdd.map(_.split(" ").map(attributes=>row(attributes(0),attributes(1))

val peopledf = spark.createdataframe(rowrdd,schema)

peopledf.show()

因為在spark-submit時配置的executor-memory 2g等沒有生效,後來問同事說他也碰到這樣的問題,解決方案就是動態的分配executor,官方文件,中文文件

Spark2 3 1 函式傳遞

spark api非常依賴於在驅動器程式傳遞函式到集群上執行,有兩種方式 1 匿名函式 2 全域性單例物件的靜態方法 1 傳遞單例物件的函式 object myfunctions myrdd.map myfunctions.func1 2 在類的方法中有transformation action操作...

Spark2 3 1中用各種模式來跑官方Demo

local模式也就是本地模式,也就是在本地機器上單機執行程式。使用這個模式的話,並不需要啟動hadoop集群,也不需要啟動spark集群,只要有一台機器上安裝了jdk scala spark即可執行。進入到spark2.1.1的安裝目錄,命令是 cd opt spark spark 2.1.1 bi...

Spark簡單使用

spark的乙個主要特點就是可以在記憶體中使用,因此他的計算速度比較快。在初學之前按照 quick start.html 中的示例來做一遍。先來初步理解一下操作流程。1.首先是搭建spark,網上有很多教程,cmd中最後執行pyspark 我們首先來分析spark資料夾中的 readme.md 檔案...