How should the data engineer modify the Athena query to meet these requirements?
A data engineer is using Amazon Athena to analyze sales data that is in Amazon S3. The data engineer writes a query to retrieve sales amounts for 2023 for several products from a table named sales_data. However, the query does not return results for all of the products that are in the sales_data table.
The data engineer needs to troubleshoot the query to resolve the issue.
The data engineer’s original query is as follows:
SELECT product_name, sum(sales_amount)
FROM sales_data
WHERE year = 2023
GROUP BY product_name
How should the data engineer modify the Athena query to meet these requirements?
A . Replace sum(sales amount) with count(*J for the aggregation.
B . Change WHERE year = 2023 to WHERE extractlyear FROM sales data) = 2023.
C . Add HAVING sumfsales amount) > 0 after the GROUP BY clause.
D . Remove the GROUP BY clause
Answer: B
Explanation:
The original query does not return results for all of the products because the year column in the sales_data table is not an integer, but a timestamp. Therefore, the WHERE clause does not filter the data correctly, and only returns the products that have a null value for the year column. To fix this, the data engineer should use the extract function to extract the year from the timestamp and compare it with 2023. This way, the query will return the correct results for all of the products in the sales_data table. The other options are either incorrect or irrelevant, as they do not address the root cause of the issue. Replacing sum with count does not change the filtering condition, adding HAVING clause does not affect the grouping logic, and removing the GROUP BY clause does not solve the problem of missing products.
Reference: Troubleshooting JSON queries – Amazon Athena (Section: JSON related errors)
When I query a table in Amazon Athena, the TIMESTAMP result is empty (Section: Resolution)
AWS Certified Data Engineer – Associate DEA-C01 Complete Study Guide (Chapter 7, page 197)
Latest Amazon DEA-C01 Dumps Valid Version with 130 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund