tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject tajo git commit: TAJO-1400: Add TajoStatement::setMaxRows method support.
Date Sun, 05 Apr 2015 14:29:30 GMT
Repository: tajo
Updated Branches:
  refs/heads/master dd4337341 -> 696d2aa7f


TAJO-1400: Add TajoStatement::setMaxRows method support.

Closes #421

Signed-off-by: Jihoon Son <jihoonson@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/696d2aa7
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/696d2aa7
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/696d2aa7

Branch: refs/heads/master
Commit: 696d2aa7fe6a507209c5b4660d4c4efb934d49b6
Parents: dd43373
Author: Yeonsu Han <hanyounsu@gmail.com>
Authored: Sun Apr 5 23:28:42 2015 +0900
Committer: Jihoon Son <jihoonson@apache.org>
Committed: Sun Apr 5 23:29:07 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 ++
 .../org/apache/tajo/client/QueryClient.java     |  4 ++
 .../org/apache/tajo/client/QueryClientImpl.java | 13 +++++++
 .../org/apache/tajo/client/TajoClientImpl.java  |  8 ++++
 .../org/apache/tajo/jdbc/FetchResultSet.java    |  5 ++-
 .../java/org/apache/tajo/jdbc/TestTajoJdbc.java | 40 +++++++++++++++++++-
 .../org/apache/tajo/jdbc/TajoStatement.java     |  7 +++-
 7 files changed, 76 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index e8a2c1f..4ec678f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,9 @@ Release 0.11.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-1400: Add TajoStatement::setMaxRows method support.
+    (Contributed by YeonSu Han, Committed by jihoon)
+
     TAJO-1421: Add 'ALTER TABLE SET PROPERTY' statement.
     (Contributed by Yongjin Choi. Committed by jaehwa)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
index 7c7db33..39b5fc3 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
@@ -45,6 +45,10 @@ public interface QueryClient extends Closeable {
   public Map<String, String> getClientSideSessionVars();
 
   public String getBaseDatabase();
+  
+  public void setMaxRows(int maxRows);
+  
+  public int getMaxRows();
 
   @Override
   public void close();

http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
index fae613a..4444a31 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
@@ -51,11 +51,14 @@ public class QueryClientImpl implements QueryClient {
   private static final Log LOG = LogFactory.getLog(QueryClientImpl.class);
   private final SessionConnection connection;
   private final int defaultFetchRows;
+//maxRows number is limit value of resultSet. The value must be >= 0, and 0 means there
is not limit.
+  private int maxRows;
 
   public QueryClientImpl(SessionConnection connection) {
     this.connection = connection;
     this.defaultFetchRows = this.connection.getProperties().getInt(SessionVars.FETCH_ROWNUM.getConfVars().keyname(),
         SessionVars.FETCH_ROWNUM.getConfVars().defaultIntVal);
+    this.maxRows = 0;
   }
 
   @Override
@@ -577,6 +580,16 @@ public class QueryClientImpl implements QueryClient {
     return status;
   }
 
+  @Override
+  public void setMaxRows(int maxRows) {
+		this.maxRows = maxRows;
+  }
+  
+  @Override
+  public int getMaxRows() {
+  	return this.maxRows;
+  }
+  
   public QueryInfoProto getQueryInfo(final QueryId queryId) throws ServiceException {
     return new ServerCallable<QueryInfoProto>(connection.connPool, connection.getTajoMasterAddr(),
         TajoMasterClientProtocol.class, false, true) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java
index e61bea0..612b56e 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/TajoClientImpl.java
@@ -166,6 +166,14 @@ public class TajoClientImpl extends SessionConnection implements TajoClient,
Que
     return queryClient.getQueryHistory(queryId);
   }
 
+  public void setMaxRows(int maxRows) {
+	  queryClient.setMaxRows(maxRows);
+  }
+
+  public int getMaxRows() {
+	  return queryClient.getMaxRows();
+  }
+  
   /*------------------------------------------------------------------------*/
   // CatalogClient wrappers
   /*------------------------------------------------------------------------*/

http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java b/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java
index 06773f4..efe070e 100644
--- a/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java
+++ b/tajo-client/src/main/java/org/apache/tajo/jdbc/FetchResultSet.java
@@ -32,10 +32,13 @@ public class FetchResultSet extends TajoResultSetBase {
   private int fetchRowNum;
   private TajoMemoryResultSet currentResultSet;
   private boolean finished = false;
+// maxRows number is limit value of resultSet. The value must be >= 0, and 0 means there
is not limit.
+  private int maxRows;
 
   public FetchResultSet(QueryClient tajoClient, Schema schema, QueryId queryId, int fetchRowNum)
{
     super(tajoClient.getClientSideSessionVars());
     this.tajoClient = tajoClient;
+    this.maxRows = tajoClient.getMaxRows();
     this.queryId = queryId;
     this.fetchRowNum = fetchRowNum;
     this.totalRow = Integer.MAX_VALUE;
@@ -48,7 +51,7 @@ public class FetchResultSet extends TajoResultSetBase {
 
   @Override
   protected Tuple nextTuple() throws IOException {
-    if (finished) {
+    if (finished || (maxRows > 0 && curRow >= maxRows)) {
       return null;
     }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java
index db6192c..36bbd94 100644
--- a/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java
+++ b/tajo-core/src/test/java/org/apache/tajo/jdbc/TestTajoJdbc.java
@@ -635,4 +635,42 @@ public class TestTajoJdbc extends QueryTestCaseBase {
       }
     }
   }
-}
\ No newline at end of file
+
+  @Test
+  public void testMaxRows() throws Exception {
+    String connUri = buildConnectionUri(tajoMasterAddress.getHostName(), tajoMasterAddress.getPort(),
+      DEFAULT_DATABASE_NAME);
+    Connection conn = DriverManager.getConnection(connUri);
+    assertTrue(conn.isValid(100));
+    Statement stmt = null;
+    ResultSet res = null;
+    //Parameter value setting for test.
+    final int maxRowsNum = 3;
+    int resultRowsNum = 0, returnMaxRows = 0;
+    try {
+      stmt = conn.createStatement();
+      //set maxRows(3)
+      stmt.setMaxRows(maxRowsNum);
+      //get MaxRows
+      returnMaxRows = stmt.getMaxRows();
+      res = stmt.executeQuery("select * from lineitem");
+      assertNotNull(res);
+      while (res.next()) {
+        //Actuality result Rows.
+        resultRowsNum++;	
+      }
+      //The test success, if maxRowsNum and resultRowsNum and returnMaxRows is same.
+      assertTrue(maxRowsNum == resultRowsNum && maxRowsNum == returnMaxRows);
+    } finally {
+      if (res != null) {
+        cleanupQuery(res);
+      }
+      if (stmt != null) {
+        stmt.close();
+      }
+      if (conn != null) {
+        conn.close();
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/696d2aa7/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java
----------------------------------------------------------------------
diff --git a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java
index 0a0a849..820e350 100644
--- a/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java
+++ b/tajo-jdbc/src/main/java/org/apache/tajo/jdbc/TajoStatement.java
@@ -241,7 +241,7 @@ public class TajoStatement implements Statement {
 
   @Override
   public int getMaxRows() throws SQLException {
-    throw new SQLFeatureNotSupportedException("getMaxRows not supported");
+    return tajoClient.getMaxRows() ;
   }
 
   @Override
@@ -340,7 +340,10 @@ public class TajoStatement implements Statement {
 
   @Override
   public void setMaxRows(int max) throws SQLException {
-    throw new SQLFeatureNotSupportedException("setMaxRows not supported");
+	  if (max < 0) {
+	     throw new SQLException("max must be >= 0");
+	  }
+	  tajoClient.setMaxRows(max);
   }
 
   @Override


Mime
View raw message