文字(DataStreamReader)

載入文字檔串流並回傳一個資料框架,其結構以一個名為 value的字串欄位開始,接著是任何分割欄位。 文字檔必須編碼為 UTF-8。 文字檔中的每一行預設都是產生資料框中的一列新筆。

語法

text(path, **options)

參數

參數 類型 說明
path str 文字輸入路徑。

退貨

DataFrame

Examples

從暫存文字檔載入串流:

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()