989 B
989 B
自定义多列排序
@Test
public void readTest() {
AppBuilder builder = AppBuilder.builder(AppConf.share());
List<Row> list = new ArrayList<>();
list.add(builder.reader().createRow(2, "A"));
list.add(builder.reader().createRow(3, "C"));
list.add(builder.reader().createRow(1, "D"));
list.add(builder.reader().createRow(6, "E"));
list.add(builder.reader().createRow(2, "D"));
list.add(builder.reader().createRow(9, "B"));
Dataset<Row> ds = builder.reader().createByList(list, new StructType().add("num", DataTypes.IntegerType).add("str", DataTypes.StringType));
Integer[] index = new Integer[]{9,3,1,6};
String[] index2 = new String[]{"E", "D", "C", "B", "A"};
ds.orderBy(
functions.array_position(functions.lit(index), functions.col("num")).desc(),
functions.array_position(functions.lit(index2), functions.col("str"))
).show();
}