1
你好我的具體要求,我想寫一個UDAF,它只是收集所有的輸入行。如何編寫一個簡單的行集合的Spark UDAF?
輸入是一個兩列的行,Double Type;
中級架構,「我想」,是的ArrayList(糾正我,如果我錯了)
返回的數據類型是ArrayList的
我寫我的UDAF的「想法」,但我希望有人幫我完成它。
class CollectorUDAF() extends UserDefinedAggregateFunction {
// Input Data Type Schema
def inputSchema: StructType = StructType(Array(StructField("value", DoubleType), StructField("y", DoubleType)))
// Intermediate Schema
def bufferSchema = util.ArrayList[Array(StructField("value", DoubleType), StructField("y", DoubleType)]
// Returned Data Type .
def dataType: DataType = util.ArrayList[Array(StructField("value", DoubleType), StructField("y", DoubleType)]
// Self-explaining
def deterministic = true
// This function is called whenever key changes
def initialize(buffer: MutableAggregationBuffer) = {
}
// Iterate over each entry of a group
def update(buffer: MutableAggregationBuffer, input: Row) = {
}
// Called after all the entries are exhausted.
def evaluate(buffer: Row) = {
}
def merge(buffer1: MutableAggregationBuffer, buffer2: Row): Unit = {
}
}