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

**URL:** <https://awshq.com/t/athena-dealing-with-csvs-with-values-enclosed-in-double-quotes/2736>\
**Category:** Billing & Cost\
**Tags:** billing, athena\
**Created:** [December 12, 2016, 10:11am UTC](https://awshq.com/t/athena-dealing-with-csvs-with-values-enclosed-in-double-quotes/2736 "2016-12-12T10:11:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashtavakra](https://awshq.com/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@ashtavakra](https://awshq.com/u/ashtavakra)\
**Post date:** [December 12, 2016, 10:11am UTC](https://awshq.com/t/athena-dealing-with-csvs-with-values-enclosed-in-double-quotes/2736/1 "2016-12-12T10:11:16Z")

</div>

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](http://docs.aws.amazon.com/athena/latest/ug/ddl/create-table.html), 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:**

- [how does AWS Glue make the tables? (based on what)](https://awshq.com/t/how-does-aws-glue-make-the-tables-based-on-what/15811)
- [Hidden cost for AWS Athena?](https://awshq.com/t/hidden-cost-for-aws-athena/12404)
- [RDS vs s3+Athena](https://awshq.com/t/rds-vs-s3-athena/17692)
- [Maybe I’m late to this, but I finally spent time comparing CUR and FOCUS (CUR 2.0 exposes ~115-131 fields, while FOCUS exposes ~60 … but theres more)](https://awshq.com/t/maybe-im-late-to-this-but-i-finally-spent-time-comparing-cur-and-focus-cur-2-0-exposes-115-131-fields-while-focus-exposes-60-but-theres-more/21412)
- [Analyzing AWS VPC Flow Logs using Apache Parquet Files and Amazon Athena](https://awshq.com/t/analyzing-aws-vpc-flow-logs-using-apache-parquet-files-and-amazon-athena/5173)

---

<div class="post-metadata">

**Author:** ![reddithenry](https://awshq.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@reddithenry](https://awshq.com/u/reddithenry)\
**Post date:** [December 12, 2016, 10:53am UTC](https://awshq.com/t/athena-dealing-with-csvs-with-values-enclosed-in-double-quotes/2736/2 "2016-12-12T10:53:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![grandmah](https://awshq.com/letter_avatar_proxy/v4/letter/g/b9e5f3/32.png) [@grandmah](https://awshq.com/u/grandmah)\
**Post date:** [February 2, 2017, 8:51pm UTC](https://awshq.com/t/athena-dealing-with-csvs-with-values-enclosed-in-double-quotes/2736/3 "2017-02-02T20:51:12Z")

</div>

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/’

---

<div class="post-metadata">

**Author:** ![DjDeaf](https://awshq.com/letter_avatar_proxy/v4/letter/d/94ad74/32.png) [@DjDeaf](https://awshq.com/u/DjDeaf)\
**Post date:** [March 7, 2017, 9:30am UTC](https://awshq.com/t/athena-dealing-with-csvs-with-values-enclosed-in-double-quotes/2736/4 "2017-03-07T09:30:47Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Dominiccabral](https://awshq.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@Dominiccabral](https://awshq.com/u/Dominiccabral)\
**Post date:** [May 10, 2017, 4:23pm UTC](https://awshq.com/t/athena-dealing-with-csvs-with-values-enclosed-in-double-quotes/2736/5 "2017-05-10T16:23:48Z")

</div>

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”“},{”"…

---

<div class="post-metadata">

**Author:** ![mikypuff](https://awshq.com/letter_avatar_proxy/v4/letter/m/e19adc/32.png) [@mikypuff](https://awshq.com/u/mikypuff)\
**Post date:** [May 16, 2017, 12:41pm UTC](https://awshq.com/t/athena-dealing-with-csvs-with-values-enclosed-in-double-quotes/2736/6 "2017-05-16T12:41:32Z")

</div>

> [@grandmah](#):
>
> 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 ( …

sorry but it doesn’t work

---

<div class="post-metadata">

**Author:** ![mikypuff](https://awshq.com/letter_avatar_proxy/v4/letter/m/e19adc/32.png) [@mikypuff](https://awshq.com/u/mikypuff)\
**Post date:** [May 16, 2017, 1:06pm UTC](https://awshq.com/t/athena-dealing-with-csvs-with-values-enclosed-in-double-quotes/2736/7 "2017-05-16T13:06:39Z")

</div>

> [@DjDeaf](#):
>
> 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” …

works like charm. Thanks a lot!!
