Query errors with Athena JDBC only

0

Hi, we've run into a very peculiar issue with the Athena JDBC driver; in brief some queries fail with the following error only when executed via the JDBC driver (latest version, 3.5.0 at time of writing) - but the same queries execute successfully when run via the Athena console or via the AWS SDK for Java. The error we see is always the same:

SEVERE: Error occurred during DB operation: Could not get query execution ID: line 28:42: mismatched input 'IN'. Expecting: 'AND', 'EXCEPT', 'FETCH', 'GROUP', 'HAVING', 'INTERSECT', 'LIMIT', 'OFFSET', 'OR', 'ORDER', 'UNION', 'WINDOW', <EOF> (Service: Athena, Status Code: 400, Request ID: 158e5fcf-f7b3-46e6-9dd4-3148372aa34e)

An example of a query that triggers this error is SELECT * FROM <tablename> WHERE id IN ('123', 'abc')

There are a few other things worth sharing that may be relevant:

  • The error always references "line 28:42" - even if the query being executed only has a single line and contains fewer than 42 characters.
  • You can create a query that results in the same error (excepting the weirdness of the line numbers) by having an 'IN' clause with no values (e.g. SELECT * FROM <tablename> WHERE id IN ()).
  • The table being queried is a view rather than a 'real' table.
asked 20 days ago62 views
2 Answers
0

The issue you're experiencing with the Athena JDBC driver is unusual and seems to be related to how the driver is handling certain query structures, particularly the 'IN' clause. This problem appears to be specific to the JDBC driver implementation, as the same queries work fine through the Athena console and AWS SDK for Java.

The error message suggesting a mismatch at "line 28:42" regardless of the actual query length indicates that there might be some preprocessing or query transformation happening within the JDBC driver that's introducing this issue.

Here are some potential explanations and workarounds:

  1. JDBC Driver Bug: This could be a bug in the JDBC driver version 3.5.0. It's possible that the driver is incorrectly parsing or transforming the query, especially when dealing with 'IN' clauses.

  2. View Interaction: Since the table being queried is actually a view, there might be some unexpected interaction between the view definition and the JDBC driver's query handling.

  3. Empty IN Clause: The fact that you can reproduce a similar error with an empty 'IN' clause suggests that the driver might be having trouble with the syntax or parameter binding for 'IN' statements.

Possible workarounds:

  1. Try using an older version of the JDBC driver to see if the issue persists.

  2. Instead of using 'IN', you could rewrite your queries using 'OR' conditions. For example: SELECT * FROM <tablename> WHERE id = '123' OR id = 'abc'

  3. If possible, try materializing the view into a regular table to see if that resolves the issue.

  4. For parameterized queries, ensure that you're properly binding parameters for the 'IN' clause.

  5. If feasible, consider using the AWS SDK for Java for these problematic queries as a temporary workaround.

If these workarounds don't help, it would be advisable to contact AWS support with detailed information about your query, the JDBC driver version, and your Athena setup. They may be able to provide more specific guidance or confirm if this is a known issue with the driver.
Sources
Query fails (inconsistency) after last athena update | AWS re:Post
INTERNAL_ERROR_QUERY_ENGINE | AWS re:Post

profile picture
answered 20 days ago
0

Responding to the AI answer:

Try using an older version of the JDBC driver to see if the issue persists.

We've tried multiple version of the JDBC driver all result in the same error

Instead of using 'IN', you could rewrite your queries using 'OR' conditions. For example: SELECT * FROM <tablename> WHERE id = '123' OR id = 'abc'

We also tried this and saw the same error.

If possible, try materializing the view into a regular table to see if that resolves the issue.

I considered this but didn't do it due to the complexity of that task and the unsuitability of this as a solution for us.

For parameterized queries, ensure that you're properly binding parameters for the 'IN' clause.

We tested this both with the 'IN' values parametrized and directly interpolated into the query string. Both result in the same error.

If feasible, consider using the AWS SDK for Java for these problematic queries as a temporary workaround.

We've done this and confirmed that it works (and this is the work-around solution we have in place right now), but there are big benefits to using JDBC that we lose with this approach.

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

Guidelines for Answering Questions