1.输入
高级模式:
spark.read.json(path)
jdbc
csv
parquet //默认格式,列存储格式,hive。
orc
table
text
textFile
低级模式:
spark.read.format(“json”).load(path)
如果不指定format,默认是parquet格式。
2.输出
高级模式:
dataFrame/dataSet. json(path)
jdbc
csv
parquet //默认格式,列存储格式,hive。
orc
table
text
textFile
低级模式:
dataFrame/dataSet.write.format(“jdbc”).参数.mode(saveMode).save
saveMode的类型:
Specifies the behavior when data or table already exists. Options include:
SaveMode.Overwrite
: overwrite the existing data.SaveMode.Append
: append the data.SaveMode.Ignore
: ignore the operation (i.e. no-op).SaveMode.ErrorIfExists
: default option, throw an exception at runtime.
关系型数据库的读写:
1.保存mysql
dataFrame.write.format(“jdbc”)
.option(“url”,”jdbc:mysql://master:3306/rdd”)
.option(“dbtable”,”rddtable10”)
.option(“user”,”root”)
.option(“password”,”123456”)
.mode(“overwrite”)
.save()
2.读入到spark
val data = spark.read.format(“jdbc”)
.option(“url”,”jdbc:mysql://master:3306/rdd”)
.option(“dbtable”,”rddtable10”)
.option(“user”,”root”)
.option(“password”,”123456”)
.load()