[ 
https://issues.apache.org/jira/browse/CALCITE-6781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17912500#comment-17912500
 ] 

Caican Cai edited comment on CALCITE-6781 at 1/13/25 1:10 PM:
--------------------------------------------------------------

[~zabetak] thanks for the reminder.
Recently I am adapting the delete statement of es, but when I support delete * 
from where condition and similar statements, an error will be reported in the 
isUpdateCapable method, as follows

{code:java}
java.util.NoSuchElementException: Expecting cursor position to be Position.OK, 
actual is Position.AFTER_END
{code}

The reason is that the openResultSet.next() of the delete statement is false. 
In the current isUpdateCapable method, whether openResultSet.next() is true or 
false, it will perform subsequent operations.
But when openResultSet.next() is false, 
{code:java}
statement.openResultSet.getObject(ROWCOUNT_COLUMN_NAME)
{code}
 will throw the exception I encountered above

So when openResultSet.next() is false, it should return null directly.

I am not very familiar with the avatica module, and I am not sure where to add 
the test

I also have a second solution signature.statementType.canUpdate() returns false 
which can also solve this problem


was (Author: JIRAUSER302115):
[~zabetak] thanks for the reminder.
Recently I am adapting the delete statement of es, but when I support delete * 
from where condition and similar statements, an error will be reported in the 
isUpdateCapable method, as follows

{code:java}
java.util.NoSuchElementException: Expecting cursor position to be Position.OK, 
actual is Position.AFTER_END
{code}

The reason is that the openResultSet.next() of the delete statement is false. 
In the current isUpdateCapable method, whether openResultSet.next() is true or 
false, it will perform subsequent operations.
But when openResultSet.next() is false, 
{code:java}
statement.openResultSet.getObject(ROWCOUNT_COLUMN_NAME)
{code}
 will throw the exception I encountered above

So when openResultSet.next() is false, it should return false directly.

I am not very familiar with the avatica module, and I am not sure where to add 
the test

I also have a second solution signature.statementType.canUpdate() returns false 
which can also solve this problem

> The isUpdateCapable method of calcite.avatica will incorrectly traverse the 
> returned result value
> -------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-6781
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6781
>             Project: Calcite
>          Issue Type: Bug
>          Components: avatica
>    Affects Versions: avatica-1.25.0
>            Reporter: Caican Cai
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: avatica-1.26.0
>
>
> When the delete statement is executed, statement.openResultSet.next will 
> return false, and we do not need to perform subsequent operations.
> {code:java}
>   private void isUpdateCapable(final AvaticaStatement statement)
>       throws SQLException {
>     Meta.Signature signature = statement.getSignature();
>     if (signature == null || signature.statementType == null) {
>       return;
>     }
>     if (signature.statementType.canUpdate() && statement.updateCount == -1) {
>       statement.openResultSet.next();
>       Object obj = statement.openResultSet.getObject(ROWCOUNT_COLUMN_NAME);
>       if (obj instanceof Number) {
>         statement.updateCount = ((Number) obj).intValue();
>       } else if (obj instanceof List) {
>         @SuppressWarnings("unchecked")
>         final List<Number> numbers = (List<Number>) obj;
>         statement.updateCount = numbers.get(0).intValue();
>       } else {
>         throw HELPER.createException("Not a valid return result.");
>       }
>       statement.openResultSet = null;
>     }
>   }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to