yiheng commented on a change in pull request #197: [LIVY-574][THRIFT 
SERVER][TEST] Add tests for metadata operations
URL: https://github.com/apache/incubator-livy/pull/197#discussion_r313451434
 
 

 ##########
 File path: 
thriftserver/server/src/main/scala/org/apache/livy/thriftserver/operation/MetadataOperation.scala
 ##########
 @@ -42,8 +46,14 @@ abstract class MetadataOperation(sessionHandle: 
SessionHandle, opType: Operation
     assertState(Seq(OperationState.FINISHED))
     validateFetchOrientation(orientation)
     if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
-      rowSet.setRowOffset(0)
+      offset = 0
+    }
+
+    if (offset >= rowSet.numRows) {
 
 Review comment:
   The problem is the last `assert` won't pass in the test.
   ```Scala
   val metadata = connection.getMetaData
   val tableTypesResultSet = metadata.getTableTypes()
   tableTypesResultSet.next()
   assert(tableTypesResultSet.getString(1) == "TABLE")
   tableTypesResultSet.next()
   assert(tableTypesResultSet.getString(1) == "VIEW")
   assert(!tableTypesResultSet.next())
   ```
   The `next()` of ResultSet will always be `true`. So when fetching table 
types or data types, the JDBC client will keep fetching forever. 
   
   The root cause is in the 
[HiveColumnBasedSet](https://github.com/apache/hive/blob/master/jdbc/src/java/org/apache/hive/jdbc/HiveQueryResultSet.java#L352),
 the `hasNext()` is always be true.
   ```Java
   if (!fetchedRowsItr.hasNext()) {
       return false;
   }
   ```
   The 
[Iterator.hasNext()](https://github.com/apache/hive/blob/master/service/src/java/org/apache/hive/service/cli/ColumnBasedSet.java#L179)
 implementation is this
   ```Java
   public boolean hasNext() {
     return index < numRows();
   }
   ```
   Please notice that when local iterator is finished, the HiveResultSet always 
fetch a new rowset from server, of which the index is 0. And the 
[numRows](https://github.com/apache/hive/blob/master/service/src/java/org/apache/hive/service/cli/ColumnBasedSet.java#L130)
 is only related with column size
   ```Java
   public int numRows() {
     return columns.isEmpty() ? 0 : columns.get(0).size();
   }
   ```
   As we always return a not empty colum result set, the `ResultSet.next()` is 
always true.

----------------------------------------------------------------
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


With regards,
Apache Git Services

Reply via email to