cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to read gcs paths with square barkets?

Sparktaculer
New Contributor II

Hi!

 

I'm trying to read a file using Scala from gcs that has square brackets in the file path.

I keep getting the following error:URISyntaxException: Illegal character in path at index 209

I tried putting an extra front slash in front of them but it still didn't work.

Would really appreciate you're help ere!

4 REPLIES 4

Hi @Retired_mod ! Thank you for your help.

However, when I tray using you're code I still get an error : "URISyntaxException: Illegal character in path at index "

I'm trying to read a txt file. This is the file path: 

"gs://my-bucket/my Data/sparkTests/GM-1220, reading a txt/Version1/3 Model Creation/3 models_to_check/[no_country] (2)/test.txt"
 
This is how I'm trying to read the file:
def loadFromGCS(gcsUrl: String๐Ÿ˜ž (String, Boolean, RecordClassifier) = {
  val content = spark.sparkContext.textFile(gcsUrl).collect().mkString("\n")
  print(content)}

 

Tharun-Kumar
Databricks Employee
Databricks Employee

Hi @Sparktaculer 

In Spark, you can disable the option globPaths. This will skip the pattern matching that happens during file reads.

spark.read.option("__globPaths__", False).format("").load("path[]")

 

Anonymous
Not applicable

Hi @Sparktaculer

We haven't heard from you since the last response from @Tharun-Kumar and @Retired_mod , and I was checking back to see if her suggestions helped you.

Or else, If you have any solution, please share it with the community, as it can be helpful to others. 

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

Sparktaculer
New Contributor II

Hi @Kaniz ! Thank you for your help.

However, when I try using you're code I still get an error: "URISyntaxException: Illegal character in path at index "

I'm trying to read a txt file. This is the file path: 

"gs://my-bucket/my Data/sparkTests/GM-1220, reading a txt/Version1/3 Model Creation/3 models_to_check/[no_country] (2)/test.txt"
This is how I'm trying to read the file:
def loadFromGCS(gcsUrlString
 (StringBooleanRecordClassifier) = {
  val content = spark.sparkContext.textFile(gcsUrl).collect().mkString("\n")
  print(content)}

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now