paul-rogers commented on issue #12682:
URL: https://github.com/apache/druid/issues/12682#issuecomment-1162526755

   To add a bit more detail:
   
   According to the [JDBC 4.1 
Spec](https://download.oracle.com/otn-pub/jcp/jdbc-4_1-mrel-spec/jdbc4.1-fr-spec.pdf?AuthParam=1655858260_d6388aeec9aeb8e5616d221749b1ff71),
 a JDBC `Statement` is closed when:
   
   > An application calls the method Statement.close to indicate that it has 
finished processing a statement. All Statement objects will be closed when the 
connection that created them is closed.
   
   And, on page 137:
   
   > Some JDBC driver implementations may also implicitly close the ResultSet 
when the ResultSet type is TYPE_FORWARD_ONLY and the next method of ResultSet 
returns false.
   
   This means that, if a statement encounters EOF on its result set, we can 
close the `ResultSet` associated with a statement, but not the statement 
itself. Yet, Druid explicitly closes statements on errors. Consider this test 
in `DruidAvaticaHandlerTest`:
   
   ```java
     @Test
     public void testNotTooManyStatementsWhenYouFullyIterateThem() throws 
Exception
     {
       for (int i = 0; i < 50; i++) {
         final ResultSet resultSet = client.createStatement().executeQuery(
             "SELECT COUNT(*) AS cnt FROM druid.foo"
         );
         Assert.assertEquals(
             ImmutableList.of(
                 ImmutableMap.of("cnt", 6L)
             ),
             getRows(resultSet)
         );
       }
     }
   ```
   
   The test should instead demonstrate the reuse of statements:
   
   ```java
     @Test
     public void testManyUsesOfTheSameStatement() throws Exception
     {
       try (Statement statement = client.createStatement()) {
         for (int i = 0; i < 50; i++) {
           final ResultSet resultSet = statement.executeQuery(
               "SELECT COUNT(*) AS cnt FROM druid.foo"
           );
           Assert.assertEquals(
               ImmutableList.of(
                   ImmutableMap.of("cnt", 6L)
               ),
               getRows(resultSet)
           );
         }
       }
     }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to