How to sort the Int type instead of the String type when sparksql operates the csv sort

Dataset<Row> df = spark.read().format("csv").load("C:\\develop\\intellij-workspace\\SparkSqlDemos\\resources\\down.csv");
df.createOrReplaceTempView("down");
Dataset<Row> dfSQL = spark.sql("SELECT * FROM down order by _c3");
//CAST
//Dataset<Row> dfSQL = spark.sql("SELECT * FROM down order by CAST(_c3 as SIGNED)");

how to sort by Int type

Mar.12,2021

.option("inferSchema", true)

see the org.apache.spark.sql.DataFrameReader document. By changing the inferSchema option in the option method to true, the data type is pushed to a numeric value, instead of defaulting to String

.
Menu