public static LogicalType findAvgAggType(LogicalType argType) {
        final LogicalType resultType;
        if (argType.is(DECIMAL)) {
            // a hack to make legacy types possible until we drop them
            if (argType instanceof LegacyTypeInformationType) {
                return argType;
            }
            // adopted from
            // https://docs.microsoft.com/en-us/sql/t-sql/functions/avg-transact-sql
            // however, we count by BIGINT, therefore divide by DECIMAL(20,0),
            // but the end result is actually the same, which is DECIMAL(38, MAX(6, s)).
            resultType = LogicalTypeMerging.findDivisionDecimalType(38, getScale(argType), 20, 0);
        } else {
            resultType = argType;
        }
        return resultType.copy(argType.isNullable());
    }
@Test
    void testFindAvgAggType() {
        assertThat(LogicalTypeMerging.findAvgAggType(decimal(38, 20)))
                .isDecimalType()
                .hasPrecisionAndScale(38, 20);
        assertThat(LogicalTypeMerging.findAvgAggType(decimal(38, 2)))
                .isDecimalType()
                .hasPrecisionAndScale(38, 6);
        assertThat(LogicalTypeMerging.findAvgAggType(decimal(38, 8)))
                .isDecimalType()
                .hasPrecisionAndScale(38, 8);
        assertThat(LogicalTypeMerging.findAvgAggType(decimal(30, 20)))
                .isDecimalType()
                .hasPrecisionAndScale(38, 20);
        assertThat(LogicalTypeMerging.findAvgAggType(decimal(10, 10)))
                .isDecimalType()
                .hasPrecisionAndScale(38, 10);
    }