How to use file from Databricks FileStore

2019-02-25 19:20发布

Trying to use a .dat file for ip lookup. File is on Databricks file store from Scala code:

  def getCountryCode(ip: String) {
     val filePath = "FileStore/maxmind/GeoIPCountry.dat"
     val ipLookups = new IpLookups(geoFile = Option(new File(filePath)),
  ispFile = None, orgFile = None, domainFile = None, memCache = false, lruCache = 0)

     val location = ipLookups.performLookups(ip)._1.head
     println(location.countryCode)
  }

I am getting an exception:

java.io.FileNotFoundException: FileStore/maxmind/GeoIPCountry.dat (No such file or directory)

Method works on local environment with relative/absolute paths

1条回答
姐就是有狂的资本
2楼-- · 2019-02-25 19:49

Use fully qualified path to the file on the FUSE mounted file system:

val filePath = "/dbfs/FileStore/maxmind/GeoIPCountry.dat"

Reference: Using Local File I/O APIs.

查看更多
登录 后发表回答