Code review comment: repeated code with line 360-390

Code under review:
private ScalarOperator createNewAggFunction(ScalarOperator arg0, ScalarOperator arg1, Type returnType) {
            if (arg0.isConstant()) {
                

                AggregateFunction countFunction = AggregateFunction.createBuiltin(
                        FunctionSet.COUNT, Lists.newArrayList(arg1.getType()), Type.BIGINT, Type.BIGINT,
                        false, true, true);

                
                List<ScalarOperator> countArguments = Lists.newArrayList();
                if (arg1.isNullable()) {
                    ColumnRefOperator newColumnRef;

                    if (arg1.isColumnRef()) {
                        newColumnRef = (ColumnRefOperator) arg1;
                        if (!oldPreAggProjections.containsKey(arg1)) {
                            newPreAggProjections.put((ColumnRefOperator) arg1, arg1);
                        }
                    } else if (commonArguments.containsKey(arg1)) {
                        
                        
                        newColumnRef = commonArguments.get(arg1);
                    } else {
                        newColumnRef = columnRefFactory.create(arg1, arg1.getType(), arg1.isNullable());
                        newPreAggProjections.put(newColumnRef, arg1);
                        commonArguments.put(arg1, newColumnRef);
                    }
                    countArguments.add(newColumnRef);
                }
                CallOperator newAggFunction = new CallOperator(FunctionSet.COUNT,
                        Type.BIGINT, countArguments, countFunction);

                ColumnRefOperator newAggRef = columnRefFactory.create(
                        newAggFunction, newAggFunction.getType(), true);
                newAggregations.put(newAggRef, newAggFunction);

                
                ScalarOperator countOperator = null;
                ScalarOperator constOperator = null;
                PrimitiveType primitiveType = returnType.getPrimitiveType();
                switch (primitiveType) {
                    case DECIMAL128:
                        countOperator = new CastOperator(
                                ScalarType.createDecimalV3Type(PrimitiveType.DECIMAL128, 18, 0),
                                newAggRef, false);
                        int precision = ((ScalarType) arg0.getType()).getScalarPrecision();
                        int scale = ((ScalarType) arg0.getType()).getScalarScale();
                        Type constType = ScalarType.createDecimalV3Type(PrimitiveType.DECIMAL128, precision, scale);
                        constOperator = arg0.isConstantNull() ? ConstantOperator.createNull(constType) :
                                ConstantOperator.createDecimal(new BigDecimal(arg0.toString()), constType);
                        break;
                    case DOUBLE:
                        countOperator = new CastOperator(returnType, newAggRef, false);
                        constOperator = arg0.isConstantNull() ? ConstantOperator.createNull(Type.DOUBLE) :
                                ConstantOperator.createDouble(((ConstantOperator) arg0).getDouble());
                        break;
                    case LARGEINT:
                        countOperator = new CastOperator(returnType, newAggRef, false);
                        constOperator = arg0.isConstantNull() ? ConstantOperator.createNull(Type.LARGEINT) :
                                ConstantOperator.createLargeInt(new BigInteger(arg0.toString()));
                        break;
                    case BIGINT:
                        
                        countOperator = newAggRef;
                        constOperator = arg0.isConstantNull() ? ConstantOperator.createNull(Type.BIGINT) :
                                ConstantOperator.createBigint(Long.parseLong(arg0.toString()));
                        break;
                    default:
                        Preconditions.checkState(false, "unexpected sum function result type");
                }

                Function multiplyFn = GlobalStateMgr.getCurrentState().getFunction(
                        new Function(new FunctionName(FunctionSet.MULTIPLY),
                                Lists.newArrayList(countOperator.getType(), constOperator.getType()),
                                returnType, false),
                        Function.CompareMode.IS_IDENTICAL);
                Preconditions.checkState(multiplyFn != null,
                        "cannot find function multiply");

                CallOperator newMultiply = new CallOperator(FunctionSet.MULTIPLY, returnType,
                        Lists.newArrayList(
                                countOperator, constOperator), multiplyFn);
                return newMultiply;
            } else {
                

                ColumnRefOperator newColumnRef;

                if (arg0.isColumnRef()) {
                    
                    
                    newColumnRef = (ColumnRefOperator) arg0;
                    if (!oldPreAggProjections.containsKey(arg0)) {
                        newPreAggProjections.put((ColumnRefOperator) arg0, arg0);
                    }
                } else if (commonArguments.containsKey(arg0)) {
                    
                    
                    newColumnRef = commonArguments.get(arg0);
                } else {
                    newColumnRef = columnRefFactory.create(arg0, arg0.getType(), arg0.isNullable());
                    newPreAggProjections.put(newColumnRef, arg0);
                    commonArguments.put(arg0, newColumnRef);
                }

                Type sumFunctionType = returnType;
                if (returnType.isDecimalV3()) {
                    
                    int argScale = ((ScalarType) arg0.getType()).getScalarScale();
                    sumFunctionType = ScalarType.createDecimalV3Type(PrimitiveType.DECIMAL128, 38, argScale);
                }

                AggregateFunction sumFunction = AggregateFunction.createBuiltin(
                        FunctionSet.SUM, Lists.newArrayList(arg0.getType()), sumFunctionType, sumFunctionType,
                        false, true, false);

                CallOperator newAggFunction = new CallOperator(FunctionSet.SUM,
                        sumFunctionType, Lists.newArrayList(newColumnRef), sumFunction);

                ColumnRefOperator newAggRef = columnRefFactory.create(
                        newAggFunction, newAggFunction.getType(), true);
                newAggregations.put(newAggRef, newAggFunction);
                return newAggRef;
            }
        }

Line commented on: if (arg1.isColumnRef()) {

Revised code:
private ScalarOperator createNewAggFunction(ScalarOperator arg0, ScalarOperator arg1, Type returnType) {
            if (arg0.isConstant()) {
                

                AggregateFunction countFunction = AggregateFunction.createBuiltin(
                        FunctionSet.COUNT, Lists.newArrayList(arg1.getType()), Type.BIGINT, Type.BIGINT,
                        false, true, true);

                
                List<ScalarOperator> countArguments = Lists.newArrayList();
                if (arg1.isNullable()) {
                    countArguments.add(createColumnRefForAggArgument(arg1));
                }
                CallOperator newAggFunction = new CallOperator(FunctionSet.COUNT,
                        Type.BIGINT, countArguments, countFunction);

                ColumnRefOperator newAggRef = columnRefFactory.create(
                        newAggFunction, newAggFunction.getType(), true);
                newAggregations.put(newAggRef, newAggFunction);

                
                ScalarOperator countOperator = null;
                ScalarOperator constOperator = null;
                PrimitiveType primitiveType = returnType.getPrimitiveType();
                switch (primitiveType) {
                    case DECIMAL128:
                        countOperator = new CastOperator(
                                ScalarType.createDecimalV3Type(PrimitiveType.DECIMAL128, 18, 0),
                                newAggRef, false);
                        int precision = ((ScalarType) arg0.getType()).getScalarPrecision();
                        int scale = ((ScalarType) arg0.getType()).getScalarScale();
                        Type constType = ScalarType.createDecimalV3Type(PrimitiveType.DECIMAL128, precision, scale);
                        constOperator = arg0.isConstantNull() ? ConstantOperator.createNull(constType) :
                                ConstantOperator.createDecimal(new BigDecimal(arg0.toString()), constType);
                        break;
                    case DOUBLE:
                        countOperator = new CastOperator(returnType, newAggRef, false);
                        constOperator = arg0.isConstantNull() ? ConstantOperator.createNull(Type.DOUBLE) :
                                ConstantOperator.createDouble(((ConstantOperator) arg0).getDouble());
                        break;
                    case LARGEINT:
                        countOperator = new CastOperator(returnType, newAggRef, false);
                        constOperator = arg0.isConstantNull() ? ConstantOperator.createNull(Type.LARGEINT) :
                                ConstantOperator.createLargeInt(new BigInteger(arg0.toString()));
                        break;
                    case BIGINT:
                        
                        countOperator = newAggRef;
                        constOperator = arg0.isConstantNull() ? ConstantOperator.createNull(Type.BIGINT) :
                                ConstantOperator.createBigint(Long.parseLong(arg0.toString()));
                        break;
                    default:
                        Preconditions.checkState(false, "unexpected sum function result type");
                }

                Function multiplyFn = GlobalStateMgr.getCurrentState().getFunction(
                        new Function(new FunctionName(FunctionSet.MULTIPLY),
                                Lists.newArrayList(countOperator.getType(), constOperator.getType()),
                                returnType, false),
                        Function.CompareMode.IS_IDENTICAL);
                Preconditions.checkState(multiplyFn != null,
                        "cannot find function multiply");

                CallOperator newMultiply = new CallOperator(FunctionSet.MULTIPLY, returnType,
                        Lists.newArrayList(
                                countOperator, constOperator), multiplyFn);
                return newMultiply;
            } else {
                

                ColumnRefOperator newColumnRef = createColumnRefForAggArgument(arg0);
                Type sumFunctionType = returnType;

                if (returnType.isDecimalV3()) {
                    
                    int argScale = ((ScalarType) arg0.getType()).getScalarScale();
                    sumFunctionType = ScalarType.createDecimalV3Type(PrimitiveType.DECIMAL128, 38, argScale);
                }

                AggregateFunction sumFunction = AggregateFunction.createBuiltin(
                        FunctionSet.SUM, Lists.newArrayList(arg0.getType()), sumFunctionType, sumFunctionType,
                        false, true, false);

                CallOperator newAggFunction = new CallOperator(FunctionSet.SUM,
                        sumFunctionType, Lists.newArrayList(newColumnRef), sumFunction);

                ColumnRefOperator newAggRef = columnRefFactory.create(
                        newAggFunction, newAggFunction.getType(), true);
                newAggregations.put(newAggRef, newAggFunction);
                return newAggRef;
            }
        }