sales.csv 内容
date,category,product,full_name,sales
2023-01-01,Electronics,Laptop,John Smith,1200.0
2023-01-02,Electronics,Smartphone,Jane Doe,800.0
2023-01-03,Books,Novel,Michael Johnson,15.0
2023-01-04,Electronics,Tablet,Emily Wilson,450.0
2023-01-05,Books,Textbook,James Brown,40.0
当使用 Spark SQL 的 DataFrame API 读取 CSV 文件时,你可以按照以下步骤进行操作。
package com.sparksql.operation;import org.apache.spark.sql.*;import org.apache.spark.sql.expressions.*;import static org.apache.spark.sql.functions.*;public class SparkDataFrame {public static void main(String[] args) {// 创建 SparkSessionSparkSession spark = SparkSession.builder().appName("SparkDataFrameTutorial").master("local[*]").getOrCreate();// 读取包含日期的 CSV 文件String csvPath = SparkDataFrame.class.getClassLoader().getResource("sparksqldata/sales.csv").getPat