내용으로 건너뛰기

Problem with null values in double-type column--AWS Athena

0

Hi there, it seems like AWS Athena is having a problem with the Null values in a column with double values. When I run SELECT [double-type column] FROM [table], I get the "HIVE_BAD_DATA: Error Parsing a column in the table: Cannot convert value of type String to a DOUBLE value" error message. However, when I select a specific value from the same column that I KNOW isn't null, it runs successfully and returns the value. Why and how can I fix this? Worth mentioning is that I created the data after crawling a CSV file.

질문됨 일 년 전380회 조회

1개 답변
0

This error occurs because the Open CSV SerDe in Athena doesn't properly handle empty or null values in columns defined as numeric data types (like DOUBLE). When you created your table from the CSV file, the crawler likely defined the column as a DOUBLE, but some rows contain empty or null values that can't be converted to the numeric type.

There are a few ways to solve this issue:

  1. Create the column with null values as STRING instead of DOUBLE, and then use CAST in your query to convert it to a numeric type while handling nulls:
SELECT CAST(your_column AS DOUBLE) AS your_column_converted FROM your_table
  1. Or provide a default value for nulls when casting:
SELECT COALESCE(CAST(your_column AS DOUBLE), 0) AS your_column_converted FROM your_table
  1. Modify your table schema in AWS Glue to change the data type of the problematic column from DOUBLE to STRING, then recrawl the data or manually update the table definition.

This issue is common when working with CSV data in Athena because the Open CSV SerDe recognizes data types like BOOLEAN, BIGINT, INT, and DOUBLE, but doesn't properly handle empty or null values in columns defined as numeric data types, leaving them as strings which then cause type conversion errors during queries.
Sources
Amazon Athena HIVE_BAD_DATA: Error Parsing a column in the table: Cannot convert value of type String to a REAL value | AWS re:Post
Troubleshoot issues in Athena - Amazon Athena
Open CSV SerDe for processing CSV - Amazon Athena

답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.