Java 8 и Spark 2.4.x здесь. Опять же, мне нужна помощь с использованием Java ( не Scala) API!
Я пытаюсь перебрать все строки Dataset
и для каждой строки запустите серию вычислений, которые обновят значения столбцов этой конкретной строки. Я понимаю, что Datasets
являются неизменяемыми, и поэтому это моя лучшая попытка на данный момент:
// what we are ranging over and generating output based on
Dataset input = getSomehow();
// the output DS; must have same schema/columns as 'input'
// and will also have the same # of rows but MAY have different
// column values in each row
Dataset output = input;
input.foreach(row -> {
// this will hold the new values we compute below
// each key matches the name of a column we wish to update
// each value is the new value of the row's column
Map<String,Object> rowMap = new HashMap<>();
// do complex computation that will update 0+ 'columns' on
// the 'row' (key/value pairs in the map)
if (someComplexLogicIsTrue()) {
// just an example; here 'price' is a column on 'input'
rowMap.put("price", 29.99);
}
// now we want to take all the key/value pairs from the rowMap and use
// them to update this row's column values (more specifically, any columns
// whose names match a key in the rowMap)
for (String key : rowMap.keySet()) {
// compiler error: variable used in lambda expression should be final
// or effectively final
output = input.withColumn(key, functions.lit(rowMap.get(key)));
}
});
Опять же, я ищу:
- Итерация всех строк набор данных и для каждой строки:
- Используйте значения некоторых из своих столбцов для обновления других столбцов (но только для этой строки), используя некоторые пользовательские / сложные логики c (это выходит за рамки этого вопроса )
- Создание выходного набора данных, в котором все вычисления применены к каждой из его строк
Любые подсказки относительно того, как я мог бы выполнить sh это в Java API? Заранее спасибо!