加载文本文件流并返回一个数据帧,其架构以名为 value字符串列开头,后跟任何分区列。 文本文件必须编码为 UTF-8。 默认情况下,文本文件中的每个行都是生成的 DataFrame 中的新行。
Syntax
text(path, **options)
参数
| 参数 | 类型 | 说明 |
|---|---|---|
path |
str | 文本输入的路径。 |
退货
DataFrame
示例
从临时文本文件加载流:
import tempfile
import time
with tempfile.TemporaryDirectory(prefix="text") as d:
spark.createDataFrame(
[("hello",), ("this",)]).write.mode("overwrite").format("text").save(d)
q = spark.readStream.text(d).writeStream.format("console").start()
time.sleep(3)
q.stop()