Skip to content

AWS Athena Query Error

0

Getting this below error on executing the following query. How can this be resolved? The same query works fine when executed from Postgres SQL workbench.

GENERIC_USER_ERROR: Encountered an exception[java.lang.RuntimeException] from your LambdaFunction[arn:aws:lambda:us-west-2:063173320901:function:eventbus-rds-athena-connector] executed in context[S3SpillLocation{bucket='eventbus-athena-spill-bucket', key='athena-spill/830312b2-f07b-4340-afbf-06b1e1ea2c46/105eedb3-c54a-4b34-a6ec-0789a313f5c8', directory=true}] with message[org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid >= character varying Hint: No operator matches the given name and argument types. You might need to add explicit type casts. Position: 117]

Query ID: 830312b2-f07b-4340-afbf-06b1e1ea2c46

Query:

SELECT 
    das.dev_manager_name AS manager_Name,
    das.dev_manager_email AS dev_manager_email,
    SUM(CASE WHEN kcv.verified THEN 1 ELSE 0 END) AS verifiedClientCount,
    SUM(CASE WHEN NOT kcv.verified THEN 1 ELSE 0 END) AS unverifiedClientCount,
    SUM(CASE WHEN kcv.client_migration_status = 'COMPLETED' THEN 1 ELSE 0 END) AS migratedClientCount,
    SUM(CASE WHEN kcv.client_migration_status <> 'COMPLETED' THEN 1 ELSE 0 END) AS nonMigratedClientCount
FROM 
    "eventbus".kafka_client_view kcv
JOIN 
    "eventbus".aws_resource_source ars ON kcv.aws_resource_source_id = ars.aws_resource_source_id
JOIN 
    "eventbus".devportal_asset_source das ON ars.devportal_asset = das.devportal_asset_id
GROUP BY 
    das.dev_manager_name, das.dev_manager_email
ORDER BY 
    das.dev_manager_name; 

asked 2 years ago386 views

2 Answers
0

Tried the suggested approach and here is the updated query I tried. But again got the same error. Query ID: b2a1a5ba-f43b-4fee-854f-0ffbbd9c2a23

Error:

GENERIC_USER_ERROR: Encountered an exception[java.lang.RuntimeException] from your LambdaFunction[arn:aws:lambda:us-west-2:063173320901:function:eventbus-rds-athena-connector] executed in context[S3SpillLocation{bucket='eventbus-athena-spill-bucket', key='athena-spill/b2a1a5ba-f43b-4fee-854f-0ffbbd9c2a23/33635a51-634f-43f2-8743-4872777ed77c', directory=true}] with message[org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid >= character varying Hint: No operator matches the given name and argument types. You might need to add explicit type casts. Position: 117]

Query:

SELECT 
    das.dev_manager_name AS manager_Name,
    das.dev_manager_email AS dev_manager_email,
    SUM(CASE WHEN kcv.verified THEN 1 ELSE 0 END) AS verifiedClientCount,
    SUM(CASE WHEN NOT kcv.verified THEN 1 ELSE 0 END) AS unverifiedClientCount,
    SUM(CASE WHEN kcv.client_migration_status = 'COMPLETED' THEN 1 ELSE 0 END) AS migratedClientCount,
    SUM(CASE WHEN kcv.client_migration_status <> 'COMPLETED' THEN 1 ELSE 0 END) AS nonMigratedClientCount
FROM 
    "eventbus".kafka_client_view kcv
JOIN 
    "eventbus".aws_resource_source ars 
        ON CAST(kcv.aws_resource_source_id AS VARCHAR) = CAST(ars.aws_resource_source_id AS VARCHAR)
JOIN 
    "eventbus".devportal_asset_source das 
        ON CAST(ars.devportal_asset AS VARCHAR) = CAST(das.devportal_asset_id AS VARCHAR)
GROUP BY 
    das.dev_manager_name, das.dev_manager_email
ORDER BY 
    das.dev_manager_name; 

answered 2 years ago

-1

The error you're encountering suggests that there's a type mismatch in your query when it's being executed in AWS Athena. Specifically, the error indicates that Athena is trying to compare a UUID type with a character varying (string) type, which is not a valid operation.

This issue is likely occurring because Athena and PostgreSQL handle data types differently, particularly when it comes to UUIDs. While PostgreSQL might be able to implicitly cast between UUID and string types, Athena is more strict and requires explicit type casting.

To resolve this, you should try to explicitly cast the UUID to a string (VARCHAR) in your query. Look for any joins or comparisons involving UUID fields and add an explicit cast. For example, if 'aws_resource_source_id' is a UUID field, you might modify the join condition like this:

JOIN "eventbus".aws_resource_source ars 
    ON CAST(kcv.aws_resource_source_id AS VARCHAR) = CAST(ars.aws_resource_source_id AS VARCHAR)

Similarly, if 'devportal_asset' or 'devportal_asset_id' is a UUID, you may need to cast it as well:

JOIN "eventbus".devportal_asset_source das 
    ON CAST(ars.devportal_asset AS VARCHAR) = CAST(das.devportal_asset_id AS VARCHAR)

If you're unsure which field is causing the issue, you may need to review the schema of your tables in Athena and identify any UUID fields that are being compared or joined with other fields.

Remember that while this solution should resolve the immediate error, it may impact query performance. If possible, it's generally better to ensure that joined fields have matching data types in your table definitions to avoid the need for casting during queries.
Sources
Athena Query Error using Python | AWS re:Post
Athena engine version 3 - Amazon Athena

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