do best to avoid overflow in avg function

since we define the return data type of avg() to DoubleType, I think we can do our best to extend the scope to avoid the overflowing, so I think we can transform the datatype to DoubleType before sum.