Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Use Statement and Prestatments to execute the same query with different results #460

Closed
STTianXiang opened this issue Mar 31, 2021 · 4 comments

Comments

@STTianXiang
Copy link

STTianXiang commented Mar 31, 2021

Environment
server:opendistro version 1.13
client:jdbc jar maven

com.amazon.opendistroforelasticsearch.client
opendistro-sql-jdbc
1.13.0.0

query sql like this:
select
count(sql_id) as access_num,count(case when result_msg = 'QUERY SUCCESS' then 1 end) as success_num
from index_really_magneto_query_log_2021-03-30

When the query is executed in the Statement mode ,the field success_num returns normal data information;
But
When the query is executed in the PreparedStatement mode ,the field success_num returns 0 ;

String query="select " + " count(sql_id) as access_num, " + " count(case when result_msg = 'QUERY SUCCESS' then 1 end) as success_num " + " from index_really_magneto_query_log_2021-03-29 " ; PreparedStatement stmt=Conn.prepareStatement(query); ResultSet rs=stmt.executeQuery(); ResultSet rs=stmt.executeQuery(); if(rs.next()){ System.out.println(rs.getLong("success_num")); System.out.println(rs.getLong("access_num")); }
Print result like this:
0
2442

Statement stmt = Conn.createStatement(); ResultSet rs=stmt.executeQuery(query); if(rs.next()){ System.out.println(rs.getLong("success_num")); System.out.println(rs.getLong("access_num")); }
Print result like this:
2440
2442

@STTianXiang STTianXiang changed the title use statement andpre Use Statement and Prestatments to execute the same query with different results Mar 31, 2021
@STTianXiang STTianXiang reopened this Mar 31, 2021
@STTianXiang STTianXiang reopened this Mar 31, 2021
@STTianXiang
Copy link
Author

@dai-chen
Copy link
Contributor

dai-chen commented Apr 2, 2021

@STTianXiang I think this is because the prepared statement was not supported by our new SQL engine. Then your query was handled by legacy which doesn't support COUNT(CASE .... Recently the prepared statement support is already merged in opendistro-for-elasticsearch/sql#1077. It would be available in next release. Thanks!

@STTianXiang
Copy link
Author

@STTianXiang I think this is because the prepared statement was not supported by our new SQL engine. Then your query was handled by legacy which doesn't support COUNT(CASE .... Recently the prepared statement support is already merged in opendistro-for-elasticsearch/sql#1077. It would be available in next release. Thanks!

Hi,@dai-chen
Thanks for you answer. Would you tell me the next release plan?

@dai-chen
Copy link
Contributor

dai-chen commented Apr 7, 2021

@STTianXiang I think this is because the prepared statement was not supported by our new SQL engine. Then your query was handled by legacy which doesn't support COUNT(CASE .... Recently the prepared statement support is already merged in opendistro-for-elasticsearch/sql#1077. It would be available in next release. Thanks!

Hi,@dai-chen
Thanks for you answer. Would you tell me the next release plan?

Hi @STTianXiang , it seems our most recent 1.13.2 is a minor release without latest code. You have to wait for next major ODFE release or build from our develop branch directly. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants