During vectorization, decimal fields that are obtained via generic udfs are cast to Decimal64 in some circumstances. For decimal to decimal64 cast, hive compares the source column's `scale + precision` to 18(maximum number of digits that can be represented by a long). A decimal can fit in a long as long as its `precision` is smaller than or equal to 18. Scale is irrelevant.
Since vectorized generic udf expression takes scale into account, it computes wrong output column vector: Decimal instead of Decimal64. This in turn causes ClassCastException down the operator chain.
Below query fails with class cast exception: