spark开发demo

spark-demo

累加计算金额–开窗累计所有数据

val amountRdd = spark.sql(
"""
|select
| end_time,
| amount index_val,
| amount + ${t1Amount} index_sum,
| ${version} version
| from(
|select 
| end_time,
| sum(amount) over(order by end_time asc) amount
| from ${a}
| order by end_time desc
| ) tmp
""".stripMargin)
.rdd
.map(x=>{
	val end_time=x.getTimestamp(x.fieldIndex("end_time"))
	val index_val=x.getDecimal(x.fieldIndex("index_val")).toString
	val index_sum=x.getDecimal(x.fieldIndex("index_sum")).toString
	val version=x.getInt(x.fieldIndex("version"))
	Row(end_time, index_val, index_sum, version)
})

val structType = StructType(Seq(
	StructField("end_time", TimestampType, true),
	StructField("index_val", StringType, true),
	StructField("index_sum", StringType, true),
	StructField("version", IntegerType, true),
))
spark.createDataFra

你可能感兴趣的:(大数据学习,spark)