I use a trial version of localstack-pro. I try to run a parameterized SQL query from java code via aws sdk. I run this code:
...
String query = " select * from hdl.tns where source = ?";
StartQueryExecutionRequest startQueryExecutionRequest =
StartQueryExecutionRequest.builder().
queryString(query).
executionParameters(List.of("myval")).
queryExecutionContext(queryExecutionContext).
resultConfiguration(resultConfiguration).
build();
StartQueryExecutionResponse startQueryExecutionResponse = client.startQueryExecution(startQueryExecutionRequest);
And in localstack console, I see this error:
mocked-aws | 2023-06-07T13:58:09.096 ERROR --- [ Thread-431] l.services.athena.provider : Athena error for query " select * from hdl.tns where source = ?"
mocked-aws | Traceback (most recent call last):
mocked-aws | File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack_ext/services/athena/provider.py.enc", line 32, in Q
mocked-aws | run_safe(lambda:resources.create_s3_bucket(F,s3_client=G));L=B[D];J=query_utils.execute_query(L,database=T,context=O);A.exec_results[B[C]]=J;LOG.debug('Athena result for query "%s":\n%s',B[D],J);U=convert_to_csv(J);M=f"{K}/results.csv";V=f"s3://{F}/{M}";H['ResultConfiguration']=ResultConfiguration(OutputLocation=V);G.put_object(Body=to_bytes(U),Bucket=F,Key=M)
mocked-aws | File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack_ext/services/athena/query_utils.py.enc", line 32, in execute_query
mocked-aws | E=C.prepared_statements if C else _B;return execute_presto_query(A,database=B,prepared_statements=E)
mocked-aws | File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack_ext/utils/bigdata/bigdata_utils.py.enc", line 205, in execute_presto_query
mocked-aws | def execute_presto_query(query,database=_B,prepared_statements=_B):A=execute_presto_queries([query],database=database,prepared_statements=prepared_statements);return A[0]
mocked-aws | File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack_ext/utils/bigdata/bigdata_utils.py.enc", line 227, in execute_presto_queries
mocked-aws | for I in queries:J=H(I);B.append(J)
mocked-aws | File "/opt/code/localstack/.venv/lib/python3.10/site-packages/localstack_ext/utils/bigdata/bigdata_utils.py.enc", line 224, in H
mocked-aws | raise Exception(f"Unable to get result from Presto server after {PRESTO_STARTUP_QUERY_RETRIES} retries: {A}")
mocked-aws | Exception: Unable to get result from Presto server after 15 retries: PrestoUserError(type=USER_ERROR, name=INVALID_PARAMETER_USAGE, message="line 1:2: Incorrect number of parameters: expected 1 but found 0", query_id=20230607_135742_00012_d2ep6)
It looks like the server side does not see provided parameter, or maybe I provide it in the wrong way, or maybe I mentioned it in the query in the wrong way. I did it according to the official AWS documentation How can I resolve the issue?