在 _spark_metadata 中未找到任何内容

Found nothing in _spark_metadata

我正在尝试从特定文件夹中读取 CSV 文件,并将相同的内容写入本地电脑上不同位置的其他 CSV 文件以用于学习目的。我可以读取文件并在控制台上显示内容。但是,如果我想将它写入指定输出目录中的另一个 CSV 文件,我会得到一个名为“_spark_metadata”的文件夹,其中不包含任何内容。

我一步步把整个代码贴在这里:

正在创建 Spark 会话:

spark = SparkSession \
.builder \
.appName('csv01') \
.master('local[*]') \
.getOrCreate();

spark.conf.set("spark.sql.streaming.checkpointLocation", <String path to checkpoint location directory> )
userSchema = StructType().add("name", "string").add("age", "integer")

从 CSV 文件读取

df = spark \
.readStream \
.schema(userSchema) \
.option("sep",",") \
.csv(<String path to local input directory containing CSV file>)

写入 CSV 文件

df.writeStream \
.format("csv") \
.option("path", <String path to local output directory containing CSV file>) \
.start()

在 "String path to local output directory containing CSV file" 中,我只得到一个文件夹 _spark_metadata,其中不包含 CSV 文件。

非常感谢对此的任何帮助

您不使用 readStream 从静态数据中读取。您可以使用它来读取文件 添加到 该文件夹的目录。

你只需要spark.read.csv