case PRECEDING: if (amt == null) { rwb = RexWindowBound.create(SqlWindow.createUnboundedPreceding(pos), null); } else { sc = (SqlCall) SqlWindow.createPreceding(amt, pos); rwb = RexWindowBound.create(sc, cluster.getRexBuilder().makeCall(sc.getOperator(), amtLiteral)); rwb = RexWindowBound.create(SqlWindow.createCurrentRow(new SqlParserPos(1, 1)), null); break; rwb = RexWindowBound.create(SqlWindow.createUnboundedFollowing(new SqlParserPos(1, 1)), null); } else { sc = (SqlCall) SqlWindow.createFollowing(amt, pos); rwb = RexWindowBound.create(sc, cluster.getRexBuilder().makeCall(sc.getOperator(), amtLiteral));
jj_consume_token(AS); e = WindowSpecification(); e.setDeclName(id); list = startList(e); label_13: jj_consume_token(AS); e = WindowSpecification(); e.setDeclName(id); list.add(e);
SqlIdentifier declName = window.getDeclName(); if (!declName.isSimple()) { throw newValidationError(declName, RESOURCE.windowNameMustBeSimple()); (SqlNodeList) expand(window.getOrderList(), windowScope); window.setOrderList(expandedOrderList); expandedOrderList.validate(this, windowScope); (SqlNodeList) expand(window.getPartitionList(), windowScope); window.setPartitionList(expandedPartitionList); expandedPartitionList.validate(this, windowScope);
private void checkRollUpInWindow(SqlWindow window, SqlValidatorScope scope) { if (window != null) { for (SqlNode node : window.getPartitionList()) { checkRollUp(null, window, node, scope, "PARTITION BY"); } for (SqlNode node : window.getOrderList()) { checkRollUp(null, window, node, scope, "ORDER BY"); } } }
window.setLowerBound(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO)); window.setUpperBound(SqlWindow.createCurrentRow(SqlParserPos.ZERO)); window.setRows(SqlLiteral.createBoolean(true, SqlParserPos.ZERO)); final SqlNodeList partitionList = window.getPartitionList(); final ImmutableList.Builder<RexNode> partitionKeys = ImmutableList.builder(); partitionKeys.add(bb.convertExpression(partition)); RexNode lowerBound = bb.convertExpression(window.getLowerBound()); RexNode upperBound = bb.convertExpression(window.getUpperBound()); SqlNodeList orderList = window.getOrderList(); if ((orderList.size() == 0) && !window.isRows()) { new HistogramShuttle( partitionKeys.build(), orderKeys.build(), RexWindowBound.create(window.getLowerBound(), lowerBound), RexWindowBound.create(window.getUpperBound(), upperBound), window, isDistinct);
/** * Fill in missing bounds. Default bounds are "BETWEEN UNBOUNDED PRECEDING * AND CURRENT ROW" when ORDER BY present and "BETWEEN UNBOUNDED PRECEDING * AND UNBOUNDED FOLLOWING" when no ORDER BY present. */ public void populateBounds() { if (lowerBound == null && upperBound == null) { setLowerBound( SqlWindow.createUnboundedPreceding(getParserPosition())); } if (lowerBound == null) { setLowerBound( SqlWindow.createCurrentRow(getParserPosition())); } if (upperBound == null) { SqlParserPos pos = orderList.getParserPosition(); setUpperBound( orderList.size() == 0 ? SqlWindow.createUnboundedFollowing(pos) : SqlWindow.createCurrentRow(pos)); } }
/** * Creates a window <code>(RANGE <i>columnName</i> UNBOUNDED * PRECEDING)</code>. * * @param columnName Order column */ public SqlWindow createUnboundedPrecedingWindow(final String columnName) { return SqlWindow.create( null, null, new SqlNodeList(SqlParserPos.ZERO), new SqlNodeList( ImmutableList.of( new SqlIdentifier(columnName, SqlParserPos.ZERO)), SqlParserPos.ZERO), SqlLiteral.createBoolean(false, SqlParserPos.ZERO), SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO), SqlWindow.createCurrentRow(SqlParserPos.ZERO), SqlLiteral.createBoolean(false, SqlParserPos.ZERO), SqlParserPos.ZERO); }
SqlNode lowerBound = window.getLowerBound(); SqlNode upperBound = window.getUpperBound(); if(window.getOrderList().size() != 0 && !window.isRows() && SqlWindow.isUnboundedPreceding(lowerBound) && (upperBound == null || SqlWindow.isCurrentRow(upperBound) || SqlWindow.isUnboundedFollowing(upperBound))) { isSupported = true; if (window.isRows() && SqlWindow.isUnboundedPreceding(lowerBound) && (upperBound == null || SqlWindow.isCurrentRow(upperBound))) { isSupported = true; if (!window.isRows() && SqlWindow.isCurrentRow(lowerBound) && SqlWindow.isCurrentRow(upperBound)) { isSupported = true; if(window.getOrderList().size() == 0 && SqlWindow.isUnboundedPreceding(lowerBound) && SqlWindow.isUnboundedFollowing(upperBound)) { isSupported = true; if(!window.isAllowPartial()) { unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION, "Dremio doesn't currently support DISALLOW PARTIAL.");
public RexNode makeOver( SqlAggFunction operator, List<RexNode> expressions, List<RexNode> partitionKeys ) { final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class); // TODO // This is a temporal fix to make HAWQ work with OVER + UNLIMITED BOUNDS // HAWQ requires ORDER BY if andy BOUNDS are set even unlimited upper and lower BOUNDS (which is equal to // the entire partition - e.g. not setting BOUNDs at all -- // Note that the unnecessary ORDER BY have negative performance impact and has to be remove once either HAWQ // start supporting unbounded bounds without order by or Calcite can generate shorthand OVER PARTITION BY // syntax. List<RexFieldCollation> orderKeys = expressions.stream().map( rexNode -> new RexFieldCollation(rexNode, flags)).collect(Collectors.toList()); return makeOver( operator, expressions, partitionKeys, ImmutableList.copyOf(orderKeys), RexWindowBound.create(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO), null), RexWindowBound.create(SqlWindow.createUnboundedFollowing(SqlParserPos.ZERO), null), true, true, false ); }
{if (true) return SqlWindow.create( null, id, partitionList, orderList, isRows, lowerBound, upperBound, allowPartial, s.end(this));}
final SqlNodeList partitions = getPartitionList(); if (0 != partitions.size()) { throw validator.newValidationError(partitions.get(0), final SqlNodeList baseOrder = getOrderList(); final SqlNodeList refOrder = that.getOrderList(); if ((0 != baseOrder.size()) && (0 != refOrder.size())) { throw validator.newValidationError(baseOrder.get(0), final SqlNode lowerBound = that.getLowerBound(); final SqlNode upperBound = that.getUpperBound(); if ((null != lowerBound) || (null != upperBound)) { throw validator.newValidationError(that.isRows, if (setOperand(partitionListNew, that.partitionList, validator)) { partitionListNew = that.partitionList; if (setOperand(orderListNew, that.orderList, validator)) { orderListNew = that.orderList; if (setOperand(lowerBoundNew, that.lowerBound, validator)) { lowerBoundNew = that.lowerBound; if (setOperand(upperBoundNew, that.upperBound, validator)) { upperBoundNew = that.upperBound; return new SqlWindow( SqlParserPos.ZERO, declNameNew,
/** * Creates a window <code>(RANGE <i>columnName</i> CURRENT ROW)</code>. * * @param columnName Order column */ public SqlWindow createCurrentRowWindow(final String columnName) { return SqlWindow.create( null, null, new SqlNodeList(SqlParserPos.ZERO), new SqlNodeList( ImmutableList.of( new SqlIdentifier(columnName, SqlParserPos.ZERO)), SqlParserPos.ZERO), SqlLiteral.createBoolean(true, SqlParserPos.ZERO), SqlWindow.createCurrentRow(SqlParserPos.ZERO), SqlWindow.createCurrentRow(SqlParserPos.ZERO), SqlLiteral.createBoolean(true, SqlParserPos.ZERO), SqlParserPos.ZERO); }
final SqlNode lowerBound = window.getLowerBound(); final SqlNode upperBound = window.getUpperBound(); Object lowerLitType = null; Object upperLitType = null;
window.setLowerBound(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO)); window.setUpperBound(SqlWindow.createCurrentRow(SqlParserPos.ZERO)); window.setRows(SqlLiteral.createBoolean(true, SqlParserPos.ZERO)); final SqlNodeList partitionList = window.getPartitionList(); final ImmutableList.Builder<RexNode> partitionKeys = ImmutableList.builder(); partitionKeys.add(bb.convertExpression(partition)); RexNode lowerBound = bb.convertExpression(window.getLowerBound()); RexNode upperBound = bb.convertExpression(window.getUpperBound()); SqlNodeList orderList = window.getOrderList(); if ((orderList.size() == 0) && !window.isRows()) { new HistogramShuttle( partitionKeys.build(), orderKeys.build(), RexWindowBound.create(window.getLowerBound(), lowerBound), RexWindowBound.create(window.getUpperBound(), upperBound), window, isDistinct);
/** * Fill in missing bounds. Default bounds are "BETWEEN UNBOUNDED PRECEDING * AND CURRENT ROW" when ORDER BY present and "BETWEEN UNBOUNDED PRECEDING * AND UNBOUNDED FOLLOWING" when no ORDER BY present. */ public void populateBounds() { if (lowerBound == null && upperBound == null) { setLowerBound( SqlWindow.createUnboundedPreceding(getParserPosition())); } if (lowerBound == null) { setLowerBound( SqlWindow.createCurrentRow(getParserPosition())); } if (upperBound == null) { SqlParserPos pos = orderList.getParserPosition(); setUpperBound( orderList.size() == 0 ? SqlWindow.createUnboundedFollowing(pos) : SqlWindow.createCurrentRow(pos)); } }
/** * Creates a window <code>(RANGE <i>columnName</i> UNBOUNDED * PRECEDING)</code>. * * @param columnName Order column */ public SqlWindow createUnboundedPrecedingWindow(final String columnName) { return SqlWindow.create( null, null, new SqlNodeList(SqlParserPos.ZERO), new SqlNodeList( ImmutableList.of( new SqlIdentifier(columnName, SqlParserPos.ZERO)), SqlParserPos.ZERO), SqlLiteral.createBoolean(false, SqlParserPos.ZERO), SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO), SqlWindow.createCurrentRow(SqlParserPos.ZERO), SqlLiteral.createBoolean(false, SqlParserPos.ZERO), SqlParserPos.ZERO); }
SqlNode lowerBound = window.getLowerBound(); SqlNode upperBound = window.getUpperBound(); if(window.getOrderList().size() != 0 && !window.isRows() && SqlWindow.isUnboundedPreceding(lowerBound) && (upperBound == null || SqlWindow.isCurrentRow(upperBound) || SqlWindow.isUnboundedFollowing(upperBound))) { isSupported = true; if (window.isRows() && SqlWindow.isUnboundedPreceding(lowerBound) && (upperBound == null || SqlWindow.isCurrentRow(upperBound))) { isSupported = true; if (!window.isRows() && SqlWindow.isCurrentRow(lowerBound) && SqlWindow.isCurrentRow(upperBound)) { isSupported = true; if(window.getOrderList().size() == 0 && SqlWindow.isUnboundedPreceding(lowerBound) && SqlWindow.isUnboundedFollowing(upperBound)) { isSupported = true; if(!window.isAllowPartial()) { unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION, "Disallowing partial windows is currently not supported \n" +
public SqlCall createCall( SqlLiteral functionQualifier, SqlParserPos pos, SqlNode... operands) { assert functionQualifier == null; assert operands.length == 8; return create( (SqlIdentifier) operands[0], (SqlIdentifier) operands[1], (SqlNodeList) operands[2], (SqlNodeList) operands[3], (SqlLiteral) operands[4], operands[5], operands[6], (SqlLiteral) operands[7], pos); }
final SqlNodeList partitions = getPartitionList(); if (0 != partitions.size()) { throw validator.newValidationError(partitions.get(0), final SqlNodeList baseOrder = getOrderList(); final SqlNodeList refOrder = that.getOrderList(); if ((0 != baseOrder.size()) && (0 != refOrder.size())) { throw validator.newValidationError(baseOrder.get(0), final SqlNode lowerBound = that.getLowerBound(); final SqlNode upperBound = that.getUpperBound(); if ((null != lowerBound) || (null != upperBound)) { throw validator.newValidationError(that.isRows, if (setOperand(partitionListNew, that.partitionList, validator)) { partitionListNew = that.partitionList; if (setOperand(orderListNew, that.orderList, validator)) { orderListNew = that.orderList; if (setOperand(lowerBoundNew, that.lowerBound, validator)) { lowerBoundNew = that.lowerBound; if (setOperand(upperBoundNew, that.upperBound, validator)) { upperBoundNew = that.upperBound; return new SqlWindow( SqlParserPos.ZERO, declNameNew,
/** * Creates a window <code>(RANGE <i>columnName</i> CURRENT ROW)</code>. * * @param columnName Order column */ public SqlWindow createCurrentRowWindow(final String columnName) { return SqlWindow.create( null, null, new SqlNodeList(SqlParserPos.ZERO), new SqlNodeList( ImmutableList.of( new SqlIdentifier(columnName, SqlParserPos.ZERO)), SqlParserPos.ZERO), SqlLiteral.createBoolean(true, SqlParserPos.ZERO), SqlWindow.createCurrentRow(SqlParserPos.ZERO), SqlWindow.createCurrentRow(SqlParserPos.ZERO), SqlLiteral.createBoolean(true, SqlParserPos.ZERO), SqlParserPos.ZERO); }