Below is an example of my data in raw format and in a table:
THis is a test|This is a \| test|"this is a \| test"
| col1 | col2 | col3 |
|---|---|---|
| THis is a test | This is a | test | "this is a | test" |
I am using the following script:
df = spark.read\
.option("header", "false")\
.option("escape", "\"")\
.option("delimiter", "|")\
.csv(file_dir)
However, the output looks like this:
df.show()
+--------------+-----------+-----+-----------------+
| _c0| _c1| _c2| _c3|
+--------------+-----------+-----+-----------------+
|THis is a test|This is a \| test|this is a \| test|
+--------------+-----------+-----+-----------------+
Essentially, I am trying to escape the delimiter if it is proceeded by a backslash regardless of quotes