This is an automated email from the ASF dual-hosted git repository.

xiangfu0 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 0c2fd239d78 PinotPreparedStatement.execute() method fixed to fulfil 
jdbc specification. (#19043)
0c2fd239d78 is described below

commit 0c2fd239d788c7e2336607232164bd5e85f9f730
Author: Vojtech Mucha <[email protected]>
AuthorDate: Thu Aug 6 23:25:56 2026 +0200

    PinotPreparedStatement.execute() method fixed to fulfil jdbc specification. 
(#19043)
---
 .../pinot/client/PinotPreparedStatement.java       |  7 +--
 .../pinot/client/PinotPreparedStatementTest.java   | 64 ++++++++++++++++++++++
 2 files changed, 65 insertions(+), 6 deletions(-)

diff --git 
a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotPreparedStatement.java
 
b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotPreparedStatement.java
index 06ada14ac8a..2d415e1f5f3 100644
--- 
a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotPreparedStatement.java
+++ 
b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotPreparedStatement.java
@@ -164,12 +164,7 @@ public class PinotPreparedStatement extends 
AbstractBasePreparedStatement {
   public boolean execute()
       throws SQLException {
     _resultSet = executeQuery();
-    if (_resultSet.next()) {
-      _resultSet.beforeFirst();
-      return true;
-    } else {
-      return false;
-    }
+    return true;
   }
 
   @Override
diff --git 
a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
 
b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
index 802ca6ade08..172cb62c09a 100644
--- 
a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
+++ 
b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
@@ -21,13 +21,16 @@ package org.apache.pinot.client;
 import java.math.BigDecimal;
 import java.sql.Date;
 import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.Properties;
+import java.util.concurrent.CompletableFuture;
 import org.apache.commons.codec.binary.Hex;
 import org.apache.pinot.client.utils.DateTimeUtils;
 import org.apache.pinot.client.utils.DriverUtils;
 import 
org.apache.pinot.spi.utils.CommonConstants.Broker.Request.QueryOptionKey;
+import org.apache.pinot.spi.utils.JsonUtils;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -159,4 +162,65 @@ public class PinotPreparedStatementTest {
         
DriverUtils.createSetQueryOptionString(QueryOptionKey.ENABLE_NULL_HANDLING, 
true) + BASIC_TEST_QUERY;
     Assert.assertEquals(_dummyPinotClientTransport.getLastQuery().substring(0, 
expectedSql.length()), expectedSql);
   }
+
+  @Test
+  public void testExecuteReturnsResultSetForEmptyResults()
+      throws Exception {
+    PreparedStatement preparedStatement = 
createPreparedStatement("{\"resultTable\":{"
+        + 
"\"dataSchema\":{\"columnNames\":[\"value\"],\"columnDataTypes\":[\"INT\"]},\"rows\":[]}}");
+
+    Assert.assertTrue(preparedStatement.execute());
+    ResultSet resultSet = preparedStatement.getResultSet();
+    Assert.assertNotNull(resultSet);
+    Assert.assertFalse(resultSet.next());
+  }
+
+  @Test
+  public void testExecuteDoesNotAdvanceResultSet()
+      throws Exception {
+    PreparedStatement preparedStatement = 
createPreparedStatement("{\"resultTable\":{"
+        + 
"\"dataSchema\":{\"columnNames\":[\"value\"],\"columnDataTypes\":[\"INT\"]},\"rows\":[[42]]}}");
+
+    Assert.assertTrue(preparedStatement.execute());
+    ResultSet resultSet = preparedStatement.getResultSet();
+    Assert.assertNotNull(resultSet);
+    Assert.assertTrue(resultSet.isBeforeFirst());
+    Assert.assertTrue(resultSet.next());
+    Assert.assertEquals(resultSet.getInt(1), 42);
+  }
+
+  private static PreparedStatement createPreparedStatement(String responseJson)
+      throws Exception {
+    Properties props = new Properties();
+    props.put(PinotConnection.BROKER_LIST, "dummy");
+    PinotConnection connection = new PinotConnection(props, "dummy", new 
ResponsePinotClientTransport(responseJson),
+        "dummy", DummyPinotControllerTransport.create());
+    return connection.prepareStatement(BASIC_TEST_QUERY);
+  }
+
+  private static class ResponsePinotClientTransport implements 
PinotClientTransport {
+    private final BrokerResponse _response;
+
+    ResponsePinotClientTransport(String responseJson)
+        throws Exception {
+      _response = 
BrokerResponse.fromJson(JsonUtils.stringToJsonNode(responseJson));
+    }
+
+    @Override
+    public BrokerResponse executeQuery(String brokerAddress, String query)
+        throws PinotClientException {
+      return _response;
+    }
+
+    @Override
+    public CompletableFuture<BrokerResponse> executeQueryAsync(String 
brokerAddress, String query)
+        throws PinotClientException {
+      return CompletableFuture.completedFuture(_response);
+    }
+
+    @Override
+    public void close()
+        throws PinotClientException {
+    }
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to