cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Schema inferrence CSV picks up \r carriage returns

lprevost
Contributor

I'm using:


    frame = spark.read.csv(path=bucket+folder,
                                   inferSchema = True,
                                   header = True,
                                   multiLine=True
     )

to read in a series of CSV files.

For one of my column headers, the parser is picking up a \r in the column name when I dig into the schema. Note "finalLink\r" in the schema listing:

[.......k', 'StringType'), ('finalLink\r', 'StringType'), # this is the \r ('period_p', 'StringType'), ('year_p', 'IntegerType')]

What flags should I be using in order to avoid parsing the carriage returns? It could be that there is juust an extra one in one of the CSV files but am not sure what is causing it.

Lee

1 ACCEPTED SOLUTION

Accepted Solutions

Hubert-Dudek
Esteemed Contributor III

Files saved in Windows operation system contain carriage return and line feed in every line.

Please add following option it can help:

 .option("ignoreTrailingWhiteSpace", true)

View solution in original post

1 REPLY 1

Hubert-Dudek
Esteemed Contributor III

Files saved in Windows operation system contain carriage return and line feed in every line.

Please add following option it can help:

 .option("ignoreTrailingWhiteSpace", true)

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