vlsi commented on a change in pull request #1740: [CALCITE-3713] Remove column
names from Project#digest
URL: https://github.com/apache/calcite/pull/1740#discussion_r365115741
##########
File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
##########
@@ -127,11 +137,83 @@ protected final StringBuilder
appendOperands(StringBuilder sb) {
includeType = RexDigestIncludeType.NO_TYPE;
}
}
- sb.append(((RexLiteral) operand).computeDigest(includeType));
+ operandDigests.add(((RexLiteral) operand).computeDigest(includeType));
+ }
+ int totalLength = (operandDigests.size() - 1) * 2; // commas
+ for (String s : operandDigests) {
+ totalLength += s.length();
+ }
+ sb.ensureCapacity(sb.length() + totalLength);
+ sortOperandsIfNeeded(sb, operands, operandDigests);
+ for (int i = 0; i < operandDigests.size(); i++) {
+ String op = operandDigests.get(i);
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(op);
}
return sb;
}
+ private void sortOperandsIfNeeded(StringBuilder sb,
+ List<RexNode> operands, List<String> operandDigests) {
+ if (operands.isEmpty() || !needNormalize()) {
+ return;
+ }
+ final SqlKind kind = op.getKind();
+ if (SqlKind.SYMMETRICAL_SAME_ARG_TYPE.contains(kind)) {
+ final RelDataType firstType = operands.get(0).getType();
+ for (int i = 1; i < operands.size(); i++) {
+ if (!equalSansNullability(firstType, operands.get(i).getType())) {
+ // Arguments have different type, thus they must not be sorted
Review comment:
Do we want to support strict floating-point non-associativity here?
Technically speaking, `PLUS` for FLOATs is not associative :(
https://stackoverflow.com/a/10371890/1261287
>i means to support more reordering for PLUS and TIMES even their operands
types are differen
I wanted the first iteration to be as simple as it could be.
Proper cost estimates are more interesting for me than spending time on
`DECIMAL(3,0) + DECIMAL(5,0)` normalization.
Reordering of `DECIMAL(3,0) + DECIMAL(5,0)` might be tricky, especially if
it is nested: `DECIMAL(3,0) + DECIMAL(3,0) + DECIMAL(5,0)` might probably
return different result than `DECIMAL(5,0) + DECIMAL(3,0) + DECIMAL(3,0)`, so I
don't want to spend time on exploring those scenarios as they are quite rare
for me.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services