I am using flink table api to compute avg and stddevPop for some fields as the following:
Table windowedTable = inputTable
.window(Tumble.over(lit(5).seconds()).on($("ts")).as("w"))
.groupBy($("w"), $("src_ip"))
.select($("w").start().as("window_start"),
$("src_ip"),
$("pkts_from_src").avg().as("pkts_from_src_mean"),
$("pkts_from_src").stddevPop().as("pkts_from_src_stddev")
);
windowedTable.execute().print();
I was expecting the avg() and stddevPop() would always return Double in Java. But it seems the return data type is the same as the data type defined in the source table. If in the source table the field pkts_from_src is defined as BIGINT, the data type of avg() and stddevPop() are Long in Java. If the field pkts_from_src is defined as DOUBLE in the source table, the data type of avg() and stddevPop() are Double in Java.
Is there a way to define the field pkts_from_src as of BIGINT but have Double in Java as the return data type of avg() and stddevPop()?
I think you could CAST the field before applying avg(). Or implement your own user defined function.