数据库dBFS文件读取问题 [英] Databricks dbfs file read issue

查看:16
本文介绍了数据库dBFS文件读取问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打开我上载到dBFS位置的文件。然而,我在尝试打开文件时出错,但在执行ls操作时可以看到该文件。此外,将文件读取到RDD时也没有问题。有人能解释一下dBFS的行为吗?在浏览了文档之后,我也尝试了几次。This是我遵循的文档。

  #ls
  dbutils.fs.ls("/tmp/sample.txt")
Out[82]: [FileInfo(path='dbfs:/tmp/sample.txt', name='sample.txt', size=46044136)]

  #creating RDD from the txt file
  data_file = "/tmp/sample.txt"
  raw_data = sc.textFile(data_file)
  raw_data.take(1)
Out[99]: ["Oct 12 2009 	Nice trendy hotel location not too bad...........	"]

 #open the txt file
  with open ("/tmp/sample.txt" , 'r') as f:
  for i, line in enumerate (f):
      if (i%10000==0):
        print("read {0} reviews".format(i))
        print (gensim.utils.simple_preprocess(line))
FileNotFoundError: [Errno 2] No such file or directory: '/dbfs/tmp/sample.txt' 

#as per documentation
  with open ("/dbfs/tmp/sample.txt" , 'r') as f:
  for i, line in enumerate (f):
      if (i%10000==0):
        print("read {0} reviews".format(i))
        print (gensim.utils.simple_preprocess(line))
FileNotFoundError: [Errno 2] No such file or directory: '/dbfs/tmp/sample.txt'

对此我一直摸不着头脑。任何帮助都将不胜感激。

附注:如果有帮助,我正在使用社区版的Databricks。

推荐答案

这是使用dbr>;=7.x的社区版的限制。如果要在本地访问dBFS文件,则可以使用dbutils.fs.cp('dbfs:/file', 'file:/local-path')(或%fs cp dbfs:/file file:/local-path)将文件从dBFS复制到本地文件系统,您可以在本地文件系统中使用该文件。

这篇关于数据库dBFS文件读取问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆