문제를 읽는 동안 텍스트 파일로서 databricks 를 사용하여 로컬 파일 API 는 보다는 오히려 불꽃 API

0

질문

내가 읽으려고 작은 txt 파일에 추가되는 테이블로 기본에서 db 를 Databricks. 하는 동안 파일을 읽을 통해 로컬 파일 API,I get a 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 의 제한은 없었지만 지도에서 문제입니다. 어떤 도움을 주시면 감사하겠습니다. 감사합니다!

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ý
..................................................................................................................