Athena - Dealing with CSV's with values enclosed in double quotes

I was trying to create an external table pointing to AWS detailed billing report CSV from Athena. The problem is, when I create an external table with the default ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' ESCAPED BY '\\' LOCATION 's3://mybucket/folder, I end up with values enclosed by double quotes in rows. That is a bit problematic because I won’t be able to run aggregate queries easily. When I looked up the documentation, here is what it says:

The serde_name indicates the SerDe to use, for example, org.apache.hadoop.hive.serde2.OpenCSVSerde. The WITH SERDEPROPERTIES clause allows you to provide one or more custom properties allowed by the SerDe. For example, the CSV SerDe allows custom separators (“separatorChar” = “\t”), custom quote characters (“quoteChar” = “'”), and escape characters (“escapeChar” = “\”).

That kind of makes you believe that OpenCSVSerde is supported. But when I try that, Athena showed the following error:

‘org.apache.hadoop.hive.serde2.OpenCSVSerde’ is not supported. (Service: AmazonAthena; Status Code: 400; Error Code: InvalidRequestException; Request ID: 78ab6af6-c052-11e6-ba09-37b63c32e0fa)

I think the documentation is misleading and needs to be corrected. Also, anyone know how can I get rid of double quotes enclosing rows while I create external table? I didn’t find that option on org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe which seems to be the supported Serde


Related discussions:

This isnt really a solution to your problem, but when I have used Hive in the past, I BELIEVE we opened up the raw CSVs in something like Python, pushed it into a Spark DF, and then wrote that out to Parquet. Python Pandas handles the quotation marks for you, so it should be resilient from that point onwards

This will execute, but I have yet to confirm that it worked for stripping the quotes from the raw data (having other issues).

ROW FORMAT SERDE ‘org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe’
WITH SERDEPROPERTIES (
‘serialization.format’ = ‘|’,
‘field.delim’ = ‘|’,
‘collection.delim’ = ‘undefined’,
‘mapkey.delim’ = ‘undefined’,
‘quoteChar’ = ‘"’
) LOCATION ‘s3://bucket/folder/’

It’s a known issue for them..
I had tons of issues but eventually this is working:

ROW FORMAT SERDE ‘org.apache.hadoop.hive.serde2.RegexSerDe’
WITH SERDEPROPERTIES (
“input.regex” =“"([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])","([^,])".”
)

Basically you need to have 1

"([^,]*)"

per column you want to strip out. just put these as the number of columnts you have and set the datatype to match the field (costs should be double - the rest will be string)

Just in case this is still an issue, I resolved it by using OpenCSVSerde which just became available this past Feb

ROW FORMAT SERDE ‘org.apache.hadoop.hive.serde2.OpenCSVSerde’
WITH SERDEPROPERTIES (
“separatorChar” = “,”,
“quoteChar” = “"”
)

In my case, I had JSON that was formatted “[{”“prop”“:”“value”“},{”"…

sorry but it doesn’t work

works like charm. Thanks a lot!!