Modified: 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java
URL: 
http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java?rev=1550684&r1=1550683&r2=1550684&view=diff
==============================================================================
--- 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java
 (original)
+++ 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/GetTypeInfoOperation.java
 Fri Dec 13 10:56:38 2013
@@ -18,6 +18,8 @@
 
 package org.apache.hive.service.cli.operation;
 
+import java.util.EnumSet;
+
 import org.apache.hive.service.cli.FetchOrientation;
 import org.apache.hive.service.cli.HiveSQLException;
 import org.apache.hive.service.cli.OperationState;
@@ -130,6 +132,10 @@ public class GetTypeInfoOperation extend
   @Override
   public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) 
throws HiveSQLException {
     assertState(OperationState.FINISHED);
+    validateDefaultFetchOrientation(orientation);
+    if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
+      rowSet.setStartOffset(0);
+    }
     return rowSet.extractSubset((int)maxRows);
   }
 }

Modified: 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
URL: 
http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java?rev=1550684&r1=1550683&r2=1550684&view=diff
==============================================================================
--- 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
 (original)
+++ 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/HiveCommandOperation.java
 Fri Dec 13 10:56:38 2013
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
+import java.util.EnumSet;
 import java.util.List;
 import java.util.Map;
 
@@ -152,6 +153,10 @@ public class HiveCommandOperation extend
    */
   @Override
   public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) 
throws HiveSQLException {
+    validateDefaultFetchOrientation(orientation);
+    if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
+      resetResultReader();
+    }
     List<String> rows = readResults((int) maxRows);
     RowSet rowSet = new RowSet();
 
@@ -178,7 +183,6 @@ public class HiveCommandOperation extend
         throw new HiveSQLException(e);
       }
     }
-
     List<String> results = new ArrayList<String>();
 
     for (int i = 0; i < nLines || nLines <= 0; ++i) {
@@ -199,11 +203,15 @@ public class HiveCommandOperation extend
   }
 
   private void cleanTmpFile() {
+    resetResultReader();
+    SessionState sessionState = getParentSession().getSessionState();
+    File tmp = sessionState.getTmpOutputFile();
+    tmp.delete();
+  }
+
+  private void resetResultReader() {
     if (resultReader != null) {
-      SessionState sessionState = getParentSession().getSessionState();
-      File tmp = sessionState.getTmpOutputFile();
       IOUtils.cleanup(LOG, resultReader);
-      tmp.delete();
       resultReader = null;
     }
   }

Modified: 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/Operation.java
URL: 
http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/Operation.java?rev=1550684&r1=1550683&r2=1550684&view=diff
==============================================================================
--- 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/Operation.java
 (original)
+++ 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/Operation.java
 Fri Dec 13 10:56:38 2013
@@ -17,6 +17,8 @@
  */
 package org.apache.hive.service.cli.operation;
 
+import java.util.EnumSet;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hive.conf.HiveConf;
@@ -40,6 +42,9 @@ public abstract class Operation {
   public static final long DEFAULT_FETCH_MAX_ROWS = 100;
   protected boolean hasResultSet;
 
+  protected static final EnumSet<FetchOrientation> 
DEFAULT_FETCH_ORIENTATION_SET =
+      EnumSet.of(FetchOrientation.FETCH_NEXT,FetchOrientation.FETCH_FIRST);
+  
   protected Operation(HiveSession parentSession, OperationType opType) {
     super();
     this.parentSession = parentSession;
@@ -124,4 +129,28 @@ public abstract class Operation {
   public RowSet getNextRowSet() throws HiveSQLException {
     return getNextRowSet(FetchOrientation.FETCH_NEXT, DEFAULT_FETCH_MAX_ROWS);
   }
+
+  /**
+   * Verify if the given fetch orientation is part of the default orientation 
types.
+   * @param orientation
+   * @throws HiveSQLException
+   */
+  protected void validateDefaultFetchOrientation(FetchOrientation orientation)
+      throws HiveSQLException {
+    validateFetchOrientation(orientation, DEFAULT_FETCH_ORIENTATION_SET);
+  }
+
+  /**
+   * Verify if the given fetch orientation is part of the supported 
orientation types.
+   * @param orientation
+   * @param supportedOrientations
+   * @throws HiveSQLException
+   */
+  protected void validateFetchOrientation(FetchOrientation orientation,
+      EnumSet<FetchOrientation> supportedOrientations) throws HiveSQLException 
{
+    if (!supportedOrientations.contains(orientation)) {
+      throw new HiveSQLException("The fetch type " + orientation.toString() +
+        " is not supported for this resultset", "HY106");
+    }
+  }
 }

Modified: 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
URL: 
http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java?rev=1550684&r1=1550683&r2=1550684&view=diff
==============================================================================
--- 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
 (original)
+++ 
hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java
 Fri Dec 13 10:56:38 2013
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.Serializable;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.EnumSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -68,6 +69,7 @@ public class SQLOperation extends Execut
   private SerDe serde = null;
   private final boolean runAsync;
   private Future<?> backgroundHandle;
+  private boolean fetchStarted = false;
 
   public SQLOperation(HiveSession parentSession, String statement, Map<String,
       String> confOverlay, boolean runInBackground) {
@@ -228,10 +230,18 @@ public class SQLOperation extends Execut
   @Override
   public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) 
throws HiveSQLException {
     assertState(OperationState.FINISHED);
+    validateDefaultFetchOrientation(orientation);
     ArrayList<String> rows = new ArrayList<String>();
     driver.setMaxRows((int)maxRows);
 
     try {
+      /* if client is requesting fetch-from-start and its not the first time 
reading from this operation
+       * then reset the fetch position to beginging
+       */
+      if (orientation.equals(FetchOrientation.FETCH_FIRST) && fetchStarted) {
+        driver.resetFetch();
+      }
+      fetchStarted = true;
       driver.getResults(rows);
 
       getSerDe();

Modified: 
hive/branches/tez/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java
URL: 
http://svn.apache.org/viewvc/hive/branches/tez/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java?rev=1550684&r1=1550683&r2=1550684&view=diff
==============================================================================
--- 
hive/branches/tez/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java
 (original)
+++ 
hive/branches/tez/shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java
 Fri Dec 13 10:56:38 2013
@@ -37,13 +37,11 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.PathFilter;
 import org.apache.hadoop.fs.ProxyFileSystem;
 import org.apache.hadoop.fs.RemoteIterator;
-import org.apache.hadoop.fs.LocatedFileStatus;
-import org.apache.hadoop.fs.RemoteIterator;
 import org.apache.hadoop.fs.Trash;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
-import org.apache.hadoop.mapred.MiniMRCluster;
 import org.apache.hadoop.mapred.ClusterStatus;
 import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.MiniMRCluster;
 import org.apache.hadoop.mapred.Reporter;
 import org.apache.hadoop.mapred.WebHCatJTShim23;
 import org.apache.hadoop.mapreduce.Job;
@@ -437,10 +435,12 @@ public class Hadoop23Shims extends Hadoo
           fs.listLocatedStatus(path);
       private FileStatus next;
       {
-        if (inner.hasNext()) {
+        next = null;
+        while (inner.hasNext() && next == null) {
           next = inner.next();
-        } else {
-          next = null;
+          if (filter != null && !filter.accept(next.getPath())) {
+            next = null;
+          }
         }
       }
 


Reply via email to