1104 final SqlParserPos pos = SqlParserPos.ZERO;
1105 final SqlLiteral nullLiteral = SqlLiteral.createNull(SqlParserPos.ZERO);
1107 final RexNode arg0Rex = cx.convertExpression(arg0Input);
1108 final RexNode arg1Rex = cx.convertExpression(arg1Input);
1112 final SqlNode argSquared = SqlStdOperatorTable.MULTIPLY.createCall(pos, arg0, arg1);
1113 final SqlNode sumArgSquared;
1116 final SqlNode count;
1117 if (dependent == null) {
1118 sumArgSquared = SqlStdOperatorTable.SUM.createCall(pos, argSquared);
1119 sum0 = SqlStdOperatorTable.SUM.createCall(pos, arg0, arg1);
1120 sum1 = SqlStdOperatorTable.SUM.createCall(pos, arg1, arg0);
1121 count = SqlStdOperatorTable.REGR_COUNT.createCall(pos, arg0, arg1);
1123 sumArgSquared = SqlStdOperatorTable.SUM.createCall(pos, argSquared, dependent);
1124 sum0 = SqlStdOperatorTable.SUM.createCall(
1125 pos, arg0, Objects.equals(dependent, arg0Input) ? arg1 : dependent);
1126 sum1 = SqlStdOperatorTable.SUM.createCall(
1127 pos, arg1, Objects.equals(dependent, arg1Input) ? arg0 : dependent);
1128 count = SqlStdOperatorTable.REGR_COUNT.createCall(
1129 pos, arg0, Objects.equals(dependent, arg0Input) ? arg1 : dependent);
1132 final SqlNode sumSquared = SqlStdOperatorTable.MULTIPLY.createCall(pos, sum0, sum1);
1133 final SqlNode countCasted =
1136 final SqlNode avgSumSquared =
1137 SqlStdOperatorTable.DIVIDE.createCall(pos, sumSquared, countCasted);
1138 final SqlNode diff =
1139 SqlStdOperatorTable.MINUS.createCall(pos, sumArgSquared, avgSumSquared);
1140 SqlNode denominator;
1142 denominator = countCasted;
1144 final SqlNumericLiteral one = SqlLiteral.createExactNumeric(
"1", pos);
1145 denominator =
new SqlCase(SqlParserPos.ZERO,
1148 SqlStdOperatorTable.EQUALS.createCall(pos, countCasted, one)),
1150 SqlStdOperatorTable.MINUS.createCall(pos, countCasted, one));
1153 return SqlStdOperatorTable.DIVIDE.createCall(pos, diff, denominator);
SqlNode getCastedSqlNode(SqlNode argInput, RelDataType varType, SqlParserPos pos, RexNode argRex)