Skip to content

Commit

Permalink
Merge pull request #419 from atlanhq/DVX-169
Browse files Browse the repository at this point in the history
Allow CSV xformer to output multiple rows for each input row
  • Loading branch information
cmgrote authored Jan 10, 2024
2 parents 7488711 + e0c1f61 commit 19810e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ abstract class CSVXformer(
logger.info { "Transforming a total of $totalRowCount rows..." }
// Actually do the mapping, of only those rows we need to transform...
reader.stream().skip(1).forEach { row -> // TODO: parallelize?
val rowByHeader = getRowByHeader(row.fields)
if (includeRow(rowByHeader)) {
val mappedValues = mapRow(rowByHeader)
writer.writeRow(mappedValues)
val inputRow = getRowByHeader(row.fields)
if (includeRow(inputRow)) {
mapRow(inputRow).forEach { outputRow ->
writer.writeRow(outputRow)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ interface RowTransformer {
* Actually translate the provided row into a row of output values.
*
* @param inputRow map from column name to value of that column for the row being processed
* @return a list of values in the same order as headers for the output file
* @return a list of rows the input row transforms into (to allow multiple output rows for a single input row),
* with each output row itself being a list of values in the same order as headers for the output file
*/
fun mapRow(inputRow: Map<String, String>): List<String>
fun mapRow(inputRow: Map<String, String>): List<List<String>>
}

0 comments on commit 19810e0

Please sign in to comment.