- Newest
- Most votes
- Most comments
Hello,
We understand that you're experiencing inconsistencies when reading JSON fields from a large dataset in Amazon Athena. This can occur due to various factors, and we'd like to provide some insights and potential solutions.
I see that you have have formatted your data as described, but, it's important to note that when using the OpenX JSON SerDe (Serializer/Deserializer), results can be non-deterministic. This means that the query output may contain more or fewer rows than expected, or even unexpected null values where none exist in the underlying data. This behavior is inherent to the OpenX JSON SerDe and can lead to the inconsistencies you're observing.
To address this issue, you can try the following:
-Try Switching to Hive JSON SerDe (if not already using): The Hive JSON SerDe tends to be more reliable in handling complex JSON structures. By changing to this SerDe, you may see more consistent results across your queries.
-Add 'ignore.malformed.json' property: We totally understand that your JSON is well-formed, However, just for the testing purpose could you please try setting the 'ignore.malformed.json' property to 'true' which might help. This setting instructs Athena to ignore any problematic records it encounters, potentially leading to more consistent results. The trade-off is that some data might be excluded from your query results.
If you've tried these suggestions and are still experiencing issues, we recommend opening a support case with AWS. By providing specific details such as your query ID and sample data, our AWS support team can perform a more in-depth analysis of your particular situation.
We're here to support you in optimizing your AWS experience.
The issue you're experiencing with Athena inconsistently reading JSON fields for a large dataset is not uncommon and can be attributed to several factors.
First, it's important to note that Athena doesn't have inherent limitations in handling millions of records. However, the inconsistency you're observing could be related to how Athena processes JSON data, especially with large datasets spread across multiple files.
One possible cause could be related to the JSON SerDe (Serializer/Deserializer) libraries that Athena uses to interpret JSON data. If the JSON structure is complex or if there are any slight variations in the JSON format across files, it might lead to occasional misreading of fields.
Another factor could be related to how the JSON files are formatted. Athena performs best when each JSON record is on a single line, without pretty-printing. If your files contain multiple records and are not strictly formatted this way, it could lead to parsing issues.
The intermittent nature of the problem (0-3 mismatches per run, different records failing on subsequent runs) suggests that there might be some race conditions or timing issues during query execution. This could be exacerbated by the large volume of data and files you're working with.
To resolve this issue, consider the following approaches:
-
Review your JSON files to ensure they are formatted optimally for Athena. Each JSON record should be on a single line, and avoid pretty-printing.
-
Check the SerDe properties in your table definition. You might want to add the 'ignore.malformed.json' property set to 'true' to skip any malformed records.
-
If possible, try consolidating your data into larger files. Having millions of small files can sometimes lead to performance and consistency issues.
-
Review the data types defined in your Athena table to ensure they match exactly with the JSON data types.
-
Consider using a more robust ETL process, such as AWS Glue, to preprocess your JSON data before querying with Athena.
-
If the issue persists, you might want to implement error handling in your query to identify and log the specific records causing issues.
Remember, while Athena is powerful for querying large datasets, complex operations on very large, distributed datasets can sometimes lead to inconsistencies. Implementing some of these suggestions should help improve the consistency of your query results.
Sources
Best practices for reading JSON data - Amazon Athena
Troubleshoot issues in Athena - Amazon Athena
Troubleshoot JSON queries - Amazon Athena
answered 2 years ago
1. Review your JSON files to ensure they are formatted optimally for Athena. Each JSON record should be on a single line, and avoid pretty-printing.
They are formatted as described
2. Check the SerDe properties in your table definition. You might want to add the 'ignore.malformed.json' property set to 'true' to skip any malformed records.
There is no malformed json or it would fail the same records each time.
3. If possible, try consolidating your data into larger files. Having millions of small files can sometimes lead to performance and consistency issues.
Unfortunately not possible in our case.
4. Review the data types defined in your Athena table to ensure they match exactly with the JSON data types.
They do - and again, the same cards would fail each time if this was the issue.
5. Consider using a more robust ETL process, such as AWS Glue, to preprocess your JSON data before querying with Athena.
I am confident the ETL process is robust, as the mismatches are provably false negatives. It is simply the athena query failing to handle a large dataset.
Relevant content
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 3 years ago

Thank you so much for the reply, switching to HIVE SerDe seems to have fixed the issue entirely.