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

ASF GitHub Bot commented on DRILL-7048:
---------------------------------------

vvysotskyi commented on pull request #1714: DRILL-7048: Implement JDBC 
Statement.setMaxRows() with System Option
URL: https://github.com/apache/drill/pull/1714#discussion_r269711718
 
 

 ##########
 File path: 
exec/jdbc/src/test/java/org/apache/drill/jdbc/PreparedStatementTest.java
 ##########
 @@ -410,6 +417,155 @@ public void testNonTriggeredQueryTimeout() throws 
SQLException {
     }
   }
 
+  ////////////////////////////////////////
+  // Query maxRows methods:
+
+  /**
+   * Test for reading of default max rows
+   */
+  @Test
+  public void   testDefaultGetMaxRows() throws SQLException {
+    try (PreparedStatement pStmt = 
connection.prepareStatement(SYS_OPTIONS_SQL)) {
+      int maxRowsValue = pStmt.getMaxRows();
+      assertEquals(0, maxRowsValue);
+    }
+  }
+
+  /**
+   * Test Invalid parameter by giving negative maxRows value
+   */
+  @Test
+  public void testInvalidSetMaxRows() throws SQLException {
+    try (PreparedStatement pStmt = 
connection.prepareStatement(SYS_OPTIONS_SQL)) {
+      //Setting negative value
+      int valueToSet = -10;
+      try {
+        pStmt.setMaxRows(valueToSet);
+      } catch ( final SQLException e) {
+        assertThat( e.getMessage(), containsString("VALIDATION ERROR: Option 
exec.query.max_rows must be between 0 and ") );
+      }
+    }
+  }
+
+  /**
+   * Test setting a valid maxRows value
+   */
+  @Test
+  public void testValidSetMaxRows() throws SQLException {
+    try (PreparedStatement pStmt = 
connection.prepareStatement(SYS_OPTIONS_SQL)) {
+      //Setting positive value
+      int valueToSet = RANDOMIZER.nextInt(59)+1;
+      pStmt.setMaxRows(valueToSet);
+      assertEquals( valueToSet, pStmt.getMaxRows() );
+    }
+  }
+
+  /**
+   * Test setting maxSize as zero (i.e. no Limit)
+   */
+  @Test
+  public void testSetMaxRowsAsZero() throws SQLException {
+    try (PreparedStatement pStmt = 
connection.prepareStatement(SYS_OPTIONS_SQL)) {
+      pStmt.setMaxRows(0);
+      pStmt.execute();
+      ResultSet rs = pStmt.getResultSet();
+      int rowCount = 0;
+      while (rs.next()) {
+        rs.getBytes(1);
+        rowCount++;
+      }
+      rs.close();
+      assertTrue(rowCount > 0);
+    }
+  }
+
+  /**
+   * Test setting maxSize at a value lower than existing query limit
+   */
+  @Test
+  public void testSetMaxRowsLowerThanQueryLimit() throws SQLException {
+    try (PreparedStatement pStmt = 
connection.prepareStatement(SYS_OPTIONS_SQL_LIMIT_10)) {
+      int valueToSet = RANDOMIZER.nextInt(9)+1; //range:[1-9]
+      pStmt.setMaxRows(valueToSet);
+      pStmt.executeQuery();
+      ResultSet rs = pStmt.getResultSet();
+      int rowCount = 0;
+      while (rs.next()) {
+        rs.getBytes(1);
+        rowCount++;
+      }
+      rs.close();
+      assertEquals(valueToSet, rowCount);
+    }
+  }
+
+  /**
+   * Test setting maxSize at a value higher than existing query limit
+   */
+  @Test
+  public void testSetMaxRowsHigherThanQueryLimit() throws SQLException {
+    try (PreparedStatement pStmt = 
connection.prepareStatement(SYS_OPTIONS_SQL_LIMIT_10)) {
+      int valueToSet = RANDOMIZER.nextInt(10)+11; //range:[11-20]
+      pStmt.setMaxRows(valueToSet);
+      pStmt.executeQuery();
+      ResultSet rs = pStmt.getResultSet();
+      int rowCount = 0;
+      while (rs.next()) {
+        rs.getBytes(1);
+        rowCount++;
+      }
+      rs.close();
+      assertTrue(valueToSet > rowCount);
+    }
+  }
+
+  /**
+   * Test setting maxSize at a value lower than existing SYSTEM limit
+   */
+  @Test
+  public void testSetMaxRowsLowerThanSystemLimit() throws SQLException {
+    int sysValueToSet = RANDOMIZER.nextInt(5)+6; //range:[6-10]
+    setSystemMaxRows(sysValueToSet);
+    try (PreparedStatement pStmt = 
connection.prepareStatement(SYS_OPTIONS_SQL)) {
+      int valueToSet = RANDOMIZER.nextInt(5)+1; //range:[1-5]
+      pStmt.setMaxRows(valueToSet);
+      pStmt.executeQuery();
+      ResultSet rs = pStmt.getResultSet();
+      int rowCount = 0;
+      while (rs.next()) {
+        rs.getBytes(1);
+        rowCount++;
+      }
+      rs.close();
+      assertEquals(valueToSet, rowCount);
+    }
+    setSystemMaxRows(0); //RESET
+  }
+
+  /**
+   * Test setting maxSize at a value higher than existing SYSTEM limit
+   */
+  @Test
+  public void testSetMaxRowsHigherThanSystemLimit() throws SQLException {
+    int sysValueToSet = RANDOMIZER.nextInt(5)+6; //range:[6-10]
 
 Review comment:
   ```suggestion
       int sysValueToSet = RANDOMIZER.nextInt(5) + 6; // range: [6-10]
   ```
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Implement JDBC Statement.setMaxRows() with System Option
> --------------------------------------------------------
>
>                 Key: DRILL-7048
>                 URL: https://issues.apache.org/jira/browse/DRILL-7048
>             Project: Apache Drill
>          Issue Type: New Feature
>          Components: Client - JDBC, Query Planning & Optimization
>    Affects Versions: 1.15.0
>            Reporter: Kunal Khatua
>            Assignee: Kunal Khatua
>            Priority: Major
>              Labels: doc-impacting
>             Fix For: 1.17.0
>
>
> With DRILL-6960, the webUI will get an auto-limit on the number of results 
> fetched.
> Since more of the plumbing is already there, it makes sense to provide the 
> same for the JDBC client.
> In addition, it would be nice if the Server can have a pre-defined value as 
> well (default 0; i.e. no limit) so that an _admin_ would be able to ensure a 
> max limit on the resultset size as well.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to