cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
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)}

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group