0
votes

I have read a CSV into dataframe using java spark dataframe, now I have to apply some width to each colum and write that data into a fixed width file. For example..column 1 has 2 bit width, column 2 has 7 bit...like that I have 85 columns. Can someone explain me how can I wrote data in dataframe to a fixed width file using java spark. I need solution in java spark only

1
Map each row of the dataframe to a single string with the spacing you need - OneCricketeer

1 Answers

0
votes

Without more description (and code example), I'd propose something like:

public Dataset<String> toFixedWidthString(Dataset<MyClass> inputDataset, int width) {
    return inputDataset.map(myClass ->
        String.format("%" + width + "s", myClass.toString()), Encoders.STRING());
}