private SqlCall toSql(RexProgram program, RexOver rexOver) {
final RexWindow rexWindow = rexOver.getWindow();
final SqlNodeList partitionList = new SqlNodeList(
toSql(program, rexWindow.partitionKeys), POS);
ImmutableList.Builder<SqlNode> orderNodes = ImmutableList.builder();
if (rexWindow.orderKeys != null) {
for (RexFieldCollation rfc : rexWindow.orderKeys) {
orderNodes.add(toSql(program, rfc));
}
}
final SqlNodeList orderList =
new SqlNodeList(orderNodes.build(), POS);
final SqlLiteral isRows =
SqlLiteral.createBoolean(rexWindow.isRows(), POS);
final SqlNode lowerBound =
createSqlWindowBound(rexWindow.getLowerBound());
final SqlNode upperBound =
createSqlWindowBound(rexWindow.getUpperBound());
final SqlLiteral allowPartial = null;
final SqlWindow sqlWindow = SqlWindow.create(null, null, partitionList,
orderList, isRows, lowerBound, upperBound, allowPartial, POS);
final List<SqlNode> nodeList = toSql(program, rexOver.getOperands());
return createOverCall(rexOver.getAggOperator(), nodeList, sqlWindow);
}