Skip to content

Athena unload lowercases all camelCase columns in parquet

0

I am using Athena UNLOAD query to unload results of SELECT in parquet format. I have columns in snake_case in Athena Table. So I did SELECT snake_case as snakeCase .. in my query. The problem is I see all the Column in unload parquet files area lowercased. It seems ATHENA UNLOAD Command does not care about the case and lower case every column.

Example Query :

UNLOAD ( SELECT abc_de AS  abcDe, fgh_ij AS fghIj FROM 
        tablename  WHERE fgh_ij IN ( '123','456' ) and year = 2024 and month = 06 and day = 24
) 
TO 's3://dummy-bucketf2e78a99-gfm8/athena/data/test/' 
WITH (format='PARQUET', compression='None')

The results in parquet file has columns like this: abcde , fghij

Is there any workaround or any parameter which I am missing here ?

asked 2 years ago290 views

1 Answer
0

Hi Rahul,

You are not missing any parameter. Athena accepts mixed case in DDL and DML queries, but lower cases the names when it executes the query. Reference: Name databases, tables, and columns

If you are not able to design your application around lower case, then the most reliable workaround is to rename columns after export using tools that support Parquet schema modification:

AWS Glue ETL Job

Read the Parquet files and write them back with renamed columns.

Reference: AWS Glue Developer Guide

Apache Spark

Use PySpark or Scala to read and rename columns.

Reference: Apache Spark Documentation

Pandas (Python)

For smaller datasets:

import pandas as pd
df = pd.read_parquet('s3://bucket/path/')
df.rename(columns={'abcde': 'abcDe', 'fghij': 'fghIj'}, inplace=True)
df.to_parquet('s3://bucket/new-path/')

Reference: Pandas Documentation


Additional References

AWS
EXPERT

answered 9 months 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.