WindowSpecification { public String toSqlString() { StringBuilder sb = new StringBuilder(); if (!partitionColumns.isEmpty()) { sb.append("PARTITION BY "); sb.append(String.join(", ", partitionColumns)); sb.append(System.lineSeparator()); } if (!sort.isEmpty()) { sb.append("ORDER BY "); sb.append( Streams.stream(sort.iterator()) .map(this::formatOrdering) .collect(Collectors.joining(", "))); } return sb.toString(); } private  WindowSpecification(String windowName, Set<String> partitionColumns, Sort sort); String toSqlString(); boolean isEmpty(); @Override String toString(); String getWindowName(); Set<String> getPartitionColumns(); Optional<Sort> getSort(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testToSqlString() { WindowSpecification windowSpecification = WindowSpecification.builder() .setWindowName("mainWindow") .setSort(Sort.on("col1", Sort.Order.ASCEND).next("col2", Sort.Order.DESCEND)) .setPartitionColumns(ImmutableList.of("col1", "col2")) .build(); String expected = "PARTITION BY col1, col2" + System.lineSeparator() + "ORDER BY col1 ASC, col2 DESC"; assertEquals(expected, windowSpecification.toSqlString()); }