I'm trying to come up with a way in Java to dynamically/programatically (is that word?) build a WindowSpec so that I can pass in parameters for the partitioning and order by clauses. I've got it partially working. I can pass in a simple comma separated string for each clause and build the window spec. The only thing I can't figure out is how to specifiy the order by direction, if I don't want ascending.
For ex, let's assume I've got a simple string for sortKeys
like table1.a, table1.b
. I can build my expression like so:
List<String> sorts = Arrays.asList(sortKeys.split(","));
Column[] sortCols = new Column[sorts.size()];
for (int i = 0; i < sorts.size(); i++) {
sortCols[i] = new Column(sorts.get(i).trim() );
}
Then I can pass that into my WindowSpec:
WindowSpec w = org.apache.spark.sql.expressions.Window.partitionBy(partCols).orderBy(sortCols);
This all works fine. But how do I specify the direction of the order by for each column?