In Java spark, how to select columns based on index

Viewed 29

how can i only select 2nd and 5th column from a csv file (no column name in file) in java spark, code as below:

Dataset<Row> dataset = getSparkSession().get().read()
                .option("delimiter", "|")
                .option("header", false)
                .csv(fileName);
1 Answers

you will get the schema by below command:

dataset.printSchema();

after that select the column you want

dataset.select("c1",c4");

Related