Skip to content

AWS Glue Crawler issue with double quotes and commas

1

I have multiple CSV Files arriving in an S3 location. I crawl the files using the glue crawler and store the data in the AWS Glue Data Catalog Table. Recently in a column of the CSV files we are receiving the file files in the format

Client SKU ID / EAN, Barcode,Child IDs / EANs, Bundled SKU
TP1201S-59,TP1201S-59,"TP1201B-Purple-59,TP1201T-Purple-59",YES

After the crawler runs the column Child IDs / EANs are split and the entire row is misaligned with the data.

After going through the blogs I tried using custom Classifier with both LazySerde and OpenCSVSerde Library but it did not work.

Then I also changed the table properties (Edit Table) after the crawler runs to use OpenCSVSerde and added the parameters escapeChar :
quoteChar: " seperatorChar: ,

After editing the properties I get the error in Athena when I query the data HIVE_BAD_DATA: Error Parsing a column in the table: Cannot convert value of type String to a LONG value

Which is usually the reformatting

What can I do to solve this problem. One would be to create a lambda that changes the CSV content on arrival and then the crawler processes it. But I want to explore on how can I crawl these file successfully without preprocessing

asked 2 years ago1.1K views

1 Answer
1

The issue you're experiencing is a common challenge when dealing with CSV files containing complex data structures, especially when fields contain commas and are enclosed in double quotes. Here are some approaches you can try to resolve this problem:

  1. Custom CSV Classifier: While you've already attempted this, it's worth double-checking your configuration. Ensure that you've set the quote character as double quotes (") and the delimiter as a comma (,) in your custom classifier. Also, make sure to specify that the columns are quoted.

  2. OpenCSVSerDe Configuration: Your approach of modifying the table properties to use OpenCSVSerDe is on the right track. However, the error you're encountering suggests there might be a mismatch between the data types defined in your table schema and the actual data in your CSV files. Double-check that the data types in your Glue Data Catalog table match the data in your CSV files, especially for columns that should be of type LONG.

  3. Grok Classifier: Consider using a Grok classifier instead of a CSV classifier. Grok patterns can be more flexible in handling complex data structures. You could create a pattern that recognizes the structure of your CSV, including the quoted fields with commas.

  4. ETL Job: If the above methods don't work, you might need to create an AWS Glue ETL job to preprocess your data. This job could read the raw CSV files, parse them correctly (handling the quoted fields with commas), and then write them out in a format that's easier for the crawler to handle.

  5. Custom Crawler: As a more advanced option, you could develop a custom crawler that understands the specific format of your CSV files, including how to handle quoted fields with commas.

  6. S3 Event Trigger: If preprocessing is unavoidable, instead of manually running a Lambda function, you could set up an S3 event trigger. This would automatically invoke a Lambda function or start a Glue job whenever a new file is uploaded to your S3 bucket, ensuring that all files are preprocessed before the crawler runs.

Remember, the goal is to ensure that your data is interpreted correctly at the time of ingestion. While preprocessing can solve the immediate issue, it's generally better to configure your ingestion process (crawler and classifier) to handle the data format correctly if possible.
Sources
Troubleshoot errors with .csv files and AWS Glue Crawler | AWS re:Post
Work with CSV data in AWS Glue - Amazon Athena
Not able to crawl multiple csvs with same specs to exclude double quotes within each field | AWS re:Post
Athena - Querying S3 file (CSV with JSON objects) | AWS re:Post

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.