xuzifu666 commented on code in PR #5015:
URL: https://github.com/apache/calcite/pull/5015#discussion_r3400238752
##########
core/src/main/java/org/apache/calcite/rel/core/Window.java:
##########
@@ -345,6 +343,72 @@ private String computeString(@UnderInitialization Group
this) {
return buf.toString();
}
+ /** Returns a display string with constant offsets in window bounds
expanded
+ * to their literal values. Unlike {@link #toString()}, this is for display
+ * only and does not affect {@link #equals} or {@link #hashCode}. */
+ public String computeDisplayString(List<RexLiteral> constants, int
inputFieldCount) {
+ final StringBuilder buf = new StringBuilder("window(");
+ final int i = buf.length();
+ if (!keys.isEmpty()) {
+ buf.append("partition ");
+ buf.append(keys);
+ }
+ if (!orderKeys.getFieldCollations().isEmpty()) {
+ if (buf.length() > i) {
+ buf.append(' ');
+ }
+ buf.append("order by ");
+ buf.append(orderKeys);
+ }
+ if (orderKeys.getFieldCollations().isEmpty()
+ && lowerBound.isUnboundedPreceding()
+ && upperBound.isUnboundedFollowing()) {
+ // skip
+ } else if (!orderKeys.getFieldCollations().isEmpty()
+ && lowerBound.isUnboundedPreceding()
+ && upperBound.isCurrentRow()
+ && !isRows) {
+ // skip
+ } else {
+ if (buf.length() > i) {
+ buf.append(' ');
+ }
+ buf.append(isRows ? "rows " : "range ");
+ buf.append("between ");
+ buf.append(expandBound(lowerBound, constants, inputFieldCount));
+ buf.append(" and ");
+ buf.append(expandBound(upperBound, constants, inputFieldCount));
+ if (exclude != RexWindowExclusion.EXCLUDE_NO_OTHER) {
+ buf.append(" ").append(exclude);
+ }
+ }
+ if (!aggCalls.isEmpty()) {
+ if (buf.length() > i) {
+ buf.append(' ');
+ }
+ buf.append("aggs ");
+ buf.append(aggCalls);
+ }
+ buf.append(")");
+ return buf.toString();
+ }
+
+ private static String expandBound(RexWindowBound bound,
Review Comment:
Yes, thanks for the reminder, I added tests to cover this.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]