MCPcopy Create free account
hub / github.com/apache/calcite / overlay

Method overlay

core/src/main/java/org/apache/calcite/sql/SqlWindow.java:496–559  ·  view source on GitHub ↗

Creates a new window by combining this one with another. For example, WINDOW (w PARTITION BY x ORDER BY y) overlay WINDOW w AS (PARTITION BY z) yields WINDOW (PARTITION BY z ORDER BY y) Does not alter this or t

(SqlWindow that, SqlValidator validator)

Source from the content-addressed store, hash-verified

494 * @return A new window
495 */
496 public SqlWindow overlay(SqlWindow that, SqlValidator validator) {
497 // check 7.11 rule 10c
498 final SqlNodeList partitions = getPartitionList();
499 if (!partitions.isEmpty()) {
500 throw validator.newValidationError(partitions.get(0),
501 RESOURCE.partitionNotAllowed());
502 }
503
504 // 7.11 rule 10d
505 final SqlNodeList baseOrder = getOrderList();
506 final SqlNodeList refOrder = that.getOrderList();
507 if (!baseOrder.isEmpty() && !refOrder.isEmpty()) {
508 throw validator.newValidationError(baseOrder.get(0),
509 RESOURCE.orderByOverlap());
510 }
511
512 // 711 rule 10e
513 final SqlNode lowerBound = that.getLowerBound();
514 final SqlNode upperBound = that.getUpperBound();
515 final SqlLiteral exclude = that.getExclude();
516 if ((null != lowerBound) || (null != upperBound)
517 || exclude.symbolValue(Exclusion.class) != Exclusion.EXCLUDE_NO_OTHER) {
518 throw validator.newValidationError(that.isRows,
519 RESOURCE.refWindowWithFrame());
520 }
521
522 SqlIdentifier declNameNew = declName;
523 SqlIdentifier refNameNew;
524 SqlNodeList partitionListNew = partitionList;
525 SqlNodeList orderListNew = orderList;
526 SqlLiteral isRowsNew = isRows;
527 SqlNode lowerBoundNew = lowerBound;
528 SqlNode upperBoundNew = upperBound;
529 SqlLiteral allowPartialNew = allowPartial;
530
531 // Clear the reference window, because the reference is now resolved.
532 // The overlaying window may have its own reference, of course.
533 refNameNew = null;
534
535 // Overlay other parameters.
536 if (setOperand(partitionListNew, that.partitionList, validator)) {
537 partitionListNew = that.partitionList;
538 }
539 if (setOperand(orderListNew, that.orderList, validator)) {
540 orderListNew = that.orderList;
541 }
542 if (setOperand(lowerBoundNew, that.lowerBound, validator)) {
543 lowerBoundNew = that.lowerBound;
544 }
545 if (setOperand(upperBoundNew, that.upperBound, validator)) {
546 upperBoundNew = that.upperBound;
547 }
548 return new SqlWindow(
549 SqlParserPos.ZERO,
550 declNameNew,
551 refNameNew,
552 partitionListNew,
553 orderListNew,

Callers 2

resolveWindowMethod · 0.95
testOverlayMethod · 0.45

Calls 14

getPartitionListMethod · 0.95
isEmptyMethod · 0.95
getMethod · 0.95
getOrderListMethod · 0.95
symbolValueMethod · 0.95
setOperandMethod · 0.95
partitionNotAllowedMethod · 0.80
orderByOverlapMethod · 0.80
refWindowWithFrameMethod · 0.80
newValidationErrorMethod · 0.65
getOrderListMethod · 0.65
getExcludeMethod · 0.65

Tested by 1

testOverlayMethod · 0.36