ปัญหาระหว่างพยายามอ่านแฟ้มข้อความใน databricks ใช้แฟ้มภายในระบบรูปแบบ api เป็นมากกว่าไฟรูปแบบ api

0

คำถาม

ฉันกำลังพยายามอ่านเล็กน้อ txtname แฟ้มซึ่งจะถูกเพิ่มเป็นโต๊ะเพื่อนค่าปริยาย db บ Databricks. ระหว่างพยายามอ่านแฟ้มผ่านทางท้องถิ่นแฟ้มรูปแบบ api ฉันได้ FileNotFoundErrorแต่ฉันสามารถอ่านแฟ้มเดียวกันที่ ออลสปาร์ค RDD ใช้ SparkContext.

ได้โปรดหารหัสด้านล่างนี้:

with open("/FileStore/tables/boringwords.txt", "r") as f_read:
  for line in f_read:
    print(line)

นี่ทำให้ฉันเกิดข้อผิดพลาด:

FileNotFoundError                         Traceback (most recent call last)
<command-2618449717515592> in <module>
----> 1 with open("dbfs:/FileStore/tables/boringwords.txt", "r") as f_read:
      2   for line in f_read:
      3     print(line)

FileNotFoundError: [Errno 2] No such file or directory: 'dbfs:/FileStore/tables/boringwords.txt'

ที่ไหนที่ฉันไม่มีปัญหาการอ่านแฟ้มโดยใช้ SparkContext:

boring_words = sc.textFile("/FileStore/tables/boringwords.txt")
set(i.strip() for i in boring_words.collect())

และอย่างที่คาดหวัง,ฉันเข้าใจที่ผลลัพธ์สำหรับบล็อกของรหัส:

Out[4]: {'mad',
 'mobile',
 'filename',
 'circle',
 'cookies',
 'immigration',
 'anticipated',
 'editorials',
 'review'}

ฉันยังพูดถึงเรื่อง DBFS เอกสาร ที่นี่ต้องเข้าใจในท้องถิ่นแฟ้มรูปแบบ api ขอ limitations แต่ของไม่มีเบาะแสเกี่ยวกับเหมือนไม่มีปัญหาอยู่เลยสินะ ที่เขาแนะนำให้ผูกผ้ากันเปื้อนจะเป็น greatly นเกียรติอย่างยิ่ง ขอบคุณ!

apache-spark databricks pyspark sparkapi
2021-11-24 06:16:55
3
0

ปัญหาก็คือการที่คุณใช้ open ฟังก์ชันที่ใช้งานได้เพียงคนเดียวที่อยู่กับแฟ้มบนเครื่องและไม่รู้อะไรเกี่ยวกับ DBFS หรือกับระบบแฟ้ม เพื่อไปซื้อมันทำงานอยู่คุณต้องการที่จะใช้ DBFS ท้องถิ่นแฟ้มรูปแบบ api และต่อไปยังท้าย /dbfs ส่วนนำหน้าไปยังแฟ้มแหน่งจัดเก็บเอกสาร: /dbfs/FileStore/....:

with open("/dbfs/FileStore/tables/boringwords.txt", "r") as f_read:
  for line in f_read:
    print(line)
2021-11-24 07:56:14
0

อีกทางเลือกคุณสามารถเพียงใช้สร้างแฟ้ม csv วิธีการ:

df = spark.read.csv("dbfs:/FileStore/tables/boringwords.txt")
2021-11-24 08:51:27
0

อีกทางเลือกพวกเราสามารถใช้ dbutils

files = dbutils.fs.ls('/FileStore/tables/')
li = []
for fi in files: 
  print(fi.path)

ตัวอย่างเช่น

enter image description here

2021-11-24 18:26:17

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่