hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gunt...@apache.org
Subject svn commit: r1552041 [7/7] - in /hive/branches/tez: ./ ant/src/org/apache/hadoop/hive/ant/ conf/ hbase-handler/src/java/org/apache/hadoop/hive/hbase/ hcatalog/src/test/e2e/templeton/tests/ hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/tem...
Date Wed, 18 Dec 2013 17:22:05 GMT
Modified: hive/branches/tez/service/src/java/org/apache/hive/service/cli/CLIService.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/CLIService.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/java/org/apache/hive/service/cli/CLIService.java (original)
+++ hive/branches/tez/service/src/java/org/apache/hive/service/cli/CLIService.java Wed Dec 18 17:22:02 2013
@@ -123,9 +123,9 @@ public class CLIService extends Composit
    */
   @Override
   public SessionHandle openSessionWithImpersonation(String username, String password, Map<String, String> configuration,
-       String delegationToken) throws HiveSQLException {
+      String delegationToken) throws HiveSQLException {
     SessionHandle sessionHandle = sessionManager.openSession(username, password, configuration,
-          true, delegationToken);
+        true, delegationToken);
     LOG.info(sessionHandle + ": openSession()");
     return sessionHandle;
   }
@@ -146,7 +146,8 @@ public class CLIService extends Composit
   @Override
   public GetInfoValue getInfo(SessionHandle sessionHandle, GetInfoType getInfoType)
       throws HiveSQLException {
-    GetInfoValue infoValue = sessionManager.getSession(sessionHandle).getInfo(getInfoType);
+    GetInfoValue infoValue = sessionManager.getSession(sessionHandle)
+        .getInfo(getInfoType);
     LOG.info(sessionHandle + ": getInfo()");
     return infoValue;
   }
@@ -158,7 +159,7 @@ public class CLIService extends Composit
   @Override
   public OperationHandle executeStatement(SessionHandle sessionHandle, String statement,
       Map<String, String> confOverlay)
-      throws HiveSQLException {
+          throws HiveSQLException {
     OperationHandle opHandle = sessionManager.getSession(sessionHandle)
         .executeStatement(statement, confOverlay);
     LOG.info(sessionHandle + ": executeStatement()");
@@ -185,7 +186,8 @@ public class CLIService extends Composit
   @Override
   public OperationHandle getTypeInfo(SessionHandle sessionHandle)
       throws HiveSQLException {
-    OperationHandle opHandle = sessionManager.getSession(sessionHandle).getTypeInfo();
+    OperationHandle opHandle = sessionManager.getSession(sessionHandle)
+        .getTypeInfo();
     LOG.info(sessionHandle + ": getTypeInfo()");
     return opHandle;
   }
@@ -196,7 +198,8 @@ public class CLIService extends Composit
   @Override
   public OperationHandle getCatalogs(SessionHandle sessionHandle)
       throws HiveSQLException {
-    OperationHandle opHandle = sessionManager.getSession(sessionHandle).getCatalogs();
+    OperationHandle opHandle = sessionManager.getSession(sessionHandle)
+        .getCatalogs();
     LOG.info(sessionHandle + ": getCatalogs()");
     return opHandle;
   }
@@ -207,7 +210,7 @@ public class CLIService extends Composit
   @Override
   public OperationHandle getSchemas(SessionHandle sessionHandle,
       String catalogName, String schemaName)
-      throws HiveSQLException {
+          throws HiveSQLException {
     OperationHandle opHandle = sessionManager.getSession(sessionHandle)
         .getSchemas(catalogName, schemaName);
     LOG.info(sessionHandle + ": getSchemas()");
@@ -220,9 +223,9 @@ public class CLIService extends Composit
   @Override
   public OperationHandle getTables(SessionHandle sessionHandle,
       String catalogName, String schemaName, String tableName, List<String> tableTypes)
-      throws HiveSQLException {
-    OperationHandle opHandle = sessionManager
-        .getSession(sessionHandle).getTables(catalogName, schemaName, tableName, tableTypes);
+          throws HiveSQLException {
+    OperationHandle opHandle = sessionManager.getSession(sessionHandle)
+        .getTables(catalogName, schemaName, tableName, tableTypes);
     LOG.info(sessionHandle + ": getTables()");
     return opHandle;
   }
@@ -233,7 +236,8 @@ public class CLIService extends Composit
   @Override
   public OperationHandle getTableTypes(SessionHandle sessionHandle)
       throws HiveSQLException {
-    OperationHandle opHandle = sessionManager.getSession(sessionHandle).getTableTypes();
+    OperationHandle opHandle = sessionManager.getSession(sessionHandle)
+        .getTableTypes();
     LOG.info(sessionHandle + ": getTableTypes()");
     return opHandle;
   }
@@ -244,7 +248,7 @@ public class CLIService extends Composit
   @Override
   public OperationHandle getColumns(SessionHandle sessionHandle,
       String catalogName, String schemaName, String tableName, String columnName)
-      throws HiveSQLException {
+          throws HiveSQLException {
     OperationHandle opHandle = sessionManager.getSession(sessionHandle)
         .getColumns(catalogName, schemaName, tableName, columnName);
     LOG.info(sessionHandle + ": getColumns()");
@@ -257,7 +261,7 @@ public class CLIService extends Composit
   @Override
   public OperationHandle getFunctions(SessionHandle sessionHandle,
       String catalogName, String schemaName, String functionName)
-      throws HiveSQLException {
+          throws HiveSQLException {
     OperationHandle opHandle = sessionManager.getSession(sessionHandle)
         .getFunctions(catalogName, schemaName, functionName);
     LOG.info(sessionHandle + ": getFunctions()");
@@ -268,11 +272,12 @@ public class CLIService extends Composit
    * @see org.apache.hive.service.cli.ICLIService#getOperationStatus(org.apache.hive.service.cli.OperationHandle)
    */
   @Override
-  public OperationState getOperationStatus(OperationHandle opHandle)
+  public OperationStatus getOperationStatus(OperationHandle opHandle)
       throws HiveSQLException {
-    OperationState opState = sessionManager.getOperationManager().getOperationState(opHandle);
+    OperationStatus opStatus = sessionManager.getOperationManager()
+        .getOperationStatus(opHandle);
     LOG.info(opHandle + ": getOperationStatus()");
-    return opState;
+    return opStatus;
   }
 
   /* (non-Javadoc)
@@ -281,8 +286,8 @@ public class CLIService extends Composit
   @Override
   public void cancelOperation(OperationHandle opHandle)
       throws HiveSQLException {
-    sessionManager.getOperationManager().getOperation(opHandle).
-        getParentSession().cancelOperation(opHandle);
+    sessionManager.getOperationManager().getOperation(opHandle)
+        .getParentSession().cancelOperation(opHandle);
     LOG.info(opHandle + ": cancelOperation()");
   }
 
@@ -292,8 +297,8 @@ public class CLIService extends Composit
   @Override
   public void closeOperation(OperationHandle opHandle)
       throws HiveSQLException {
-    sessionManager.getOperationManager().getOperation(opHandle).
-        getParentSession().closeOperation(opHandle);
+    sessionManager.getOperationManager().getOperation(opHandle)
+        .getParentSession().closeOperation(opHandle);
     LOG.info(opHandle + ": closeOperation");
   }
 
@@ -303,8 +308,8 @@ public class CLIService extends Composit
   @Override
   public TableSchema getResultSetMetadata(OperationHandle opHandle)
       throws HiveSQLException {
-    TableSchema tableSchema = sessionManager.getOperationManager().getOperation(opHandle).
-        getParentSession().getResultSetMetadata(opHandle);
+    TableSchema tableSchema = sessionManager.getOperationManager()
+        .getOperation(opHandle).getParentSession().getResultSetMetadata(opHandle);
     LOG.info(opHandle + ": getResultSetMetadata()");
     return tableSchema;
   }
@@ -315,8 +320,8 @@ public class CLIService extends Composit
   @Override
   public RowSet fetchResults(OperationHandle opHandle, FetchOrientation orientation, long maxRows)
       throws HiveSQLException {
-    RowSet rowSet = sessionManager.getOperationManager().getOperation(opHandle).
-        getParentSession().fetchResults(opHandle, orientation, maxRows);
+    RowSet rowSet = sessionManager.getOperationManager().getOperation(opHandle)
+        .getParentSession().fetchResults(opHandle, orientation, maxRows);
     LOG.info(opHandle + ": fetchResults()");
     return rowSet;
   }
@@ -327,8 +332,8 @@ public class CLIService extends Composit
   @Override
   public RowSet fetchResults(OperationHandle opHandle)
       throws HiveSQLException {
-    RowSet rowSet = sessionManager.getOperationManager().getOperation(opHandle).
-        getParentSession().fetchResults(opHandle);
+    RowSet rowSet = sessionManager.getOperationManager().getOperation(opHandle)
+        .getParentSession().fetchResults(opHandle);
     LOG.info(opHandle + ": fetchResults()");
     return rowSet;
   }
@@ -339,7 +344,7 @@ public class CLIService extends Composit
     if (!hiveConf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL) ||
         !hiveConf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS)) {
       throw new UnsupportedOperationException(
-        "delegation token is can only be obtained for a secure remote metastore");
+          "delegation token is can only be obtained for a secure remote metastore");
     }
 
     try {

Modified: hive/branches/tez/service/src/java/org/apache/hive/service/cli/CLIServiceClient.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/CLIServiceClient.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/java/org/apache/hive/service/cli/CLIServiceClient.java (original)
+++ hive/branches/tez/service/src/java/org/apache/hive/service/cli/CLIServiceClient.java Wed Dec 18 17:22:02 2013
@@ -19,8 +19,6 @@
 package org.apache.hive.service.cli;
 
 import java.util.Collections;
-import java.util.List;
-import java.util.Map;
 
 
 /**
@@ -29,127 +27,12 @@ import java.util.Map;
  */
 public abstract class CLIServiceClient implements ICLIService {
 
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#openSession(java.lang.String, java.lang.String, java.util.Map)
-   */
-  @Override
-  public abstract SessionHandle openSession(String username, String password,
-      Map<String, String> configuration) throws HiveSQLException;
-
-
   public SessionHandle openSession(String username, String password)
       throws HiveSQLException {
     return openSession(username, password, Collections.<String, String>emptyMap());
   }
 
   /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#closeSession(org.apache.hive.service.cli.SessionHandle)
-   */
-  @Override
-  public abstract void closeSession(SessionHandle sessionHandle) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#getInfo(org.apache.hive.service.cli.SessionHandle, java.util.List)
-   */
-  @Override
-  public abstract GetInfoValue getInfo(SessionHandle sessionHandle, GetInfoType getInfoType)
-      throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#executeStatement(org.apache.hive.service.cli.SessionHandle,
-   *  java.lang.String, java.util.Map)
-   */
-  @Override
-  public abstract OperationHandle executeStatement(SessionHandle sessionHandle, String statement,
-      Map<String, String> confOverlay) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#executeStatementAsync(org.apache.hive.service.cli.SessionHandle,
-   *  java.lang.String, java.util.Map)
-   */
-  @Override
-  public abstract OperationHandle executeStatementAsync(SessionHandle sessionHandle, String statement,
-      Map<String, String> confOverlay) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#getTypeInfo(org.apache.hive.service.cli.SessionHandle)
-   */
-  @Override
-  public abstract OperationHandle getTypeInfo(SessionHandle sessionHandle) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#getCatalogs(org.apache.hive.service.cli.SessionHandle)
-   */
-  @Override
-  public abstract OperationHandle getCatalogs(SessionHandle sessionHandle) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#getSchemas(org.apache.hive.service.cli.SessionHandle, java.lang.String, java.lang.String)
-   */
-  @Override
-  public abstract OperationHandle getSchemas(SessionHandle sessionHandle, String catalogName,
-      String schemaName) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#getTables(org.apache.hive.service.cli.SessionHandle, java.lang.String, java.lang.String, java.lang.String, java.util.List)
-   */
-  @Override
-  public abstract OperationHandle getTables(SessionHandle sessionHandle, String catalogName,
-      String schemaName, String tableName, List<String> tableTypes) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#getTableTypes(org.apache.hive.service.cli.SessionHandle)
-   */
-  @Override
-  public abstract OperationHandle getTableTypes(SessionHandle sessionHandle) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#getColumns(org.apache.hive.service.cli.SessionHandle, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
-   */
-  @Override
-  public abstract OperationHandle getColumns(SessionHandle sessionHandle, String catalogName,
-      String schemaName, String tableName, String columnName) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#getFunctions(org.apache.hive.service.cli.SessionHandle, java.lang.String)
-   */
-  @Override
-  public abstract OperationHandle getFunctions(SessionHandle sessionHandle,
-      String catalogName, String schemaName, String functionName)
-      throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#getOperationStatus(org.apache.hive.service.cli.OperationHandle)
-   */
-  @Override
-  public abstract OperationState getOperationStatus(OperationHandle opHandle) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#cancelOperation(org.apache.hive.service.cli.OperationHandle)
-   */
-  @Override
-  public abstract void cancelOperation(OperationHandle opHandle) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#closeOperation(org.apache.hive.service.cli.OperationHandle)
-   */
-  @Override
-  public abstract void closeOperation(OperationHandle opHandle) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#getResultSetMetadata(org.apache.hive.service.cli.OperationHandle)
-   */
-  @Override
-  public abstract TableSchema getResultSetMetadata(OperationHandle opHandle) throws HiveSQLException;
-
-  /* (non-Javadoc)
-   * @see org.apache.hive.service.cli.ICLIService#fetchResults(org.apache.hive.service.cli.OperationHandle, org.apache.hive.service.cli.FetchOrientation, long)
-   */
-  @Override
-  public abstract RowSet fetchResults(OperationHandle opHandle, FetchOrientation orientation, long maxRows)
-      throws HiveSQLException;
-
-  /* (non-Javadoc)
    * @see org.apache.hive.service.cli.ICLIService#fetchResults(org.apache.hive.service.cli.OperationHandle)
    */
   @Override

Modified: hive/branches/tez/service/src/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java (original)
+++ hive/branches/tez/service/src/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java Wed Dec 18 17:22:02 2013
@@ -143,7 +143,7 @@ public class EmbeddedCLIServiceClient ex
   @Override
   public OperationHandle getFunctions(SessionHandle sessionHandle,
       String catalogName, String schemaName, String functionName)
-      throws HiveSQLException {
+          throws HiveSQLException {
     return cliService.getFunctions(sessionHandle, catalogName, schemaName, functionName);
   }
 
@@ -151,7 +151,7 @@ public class EmbeddedCLIServiceClient ex
    * @see org.apache.hive.service.cli.CLIServiceClient#getOperationStatus(org.apache.hive.service.cli.OperationHandle)
    */
   @Override
-  public OperationState getOperationStatus(OperationHandle opHandle) throws HiveSQLException {
+  public OperationStatus getOperationStatus(OperationHandle opHandle) throws HiveSQLException {
     return cliService.getOperationStatus(opHandle);
   }
 

Modified: hive/branches/tez/service/src/java/org/apache/hive/service/cli/ICLIService.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/ICLIService.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/java/org/apache/hive/service/cli/ICLIService.java (original)
+++ hive/branches/tez/service/src/java/org/apache/hive/service/cli/ICLIService.java Wed Dec 18 17:22:02 2013
@@ -27,11 +27,11 @@ public interface ICLIService {
 
   public abstract SessionHandle openSession(String username, String password,
       Map<String, String> configuration)
-      throws HiveSQLException;
+          throws HiveSQLException;
 
   public abstract SessionHandle openSessionWithImpersonation(String username, String password,
       Map<String, String> configuration, String delegationToken)
-      throws HiveSQLException;
+          throws HiveSQLException;
 
   public abstract void closeSession(SessionHandle sessionHandle)
       throws HiveSQLException;
@@ -41,11 +41,11 @@ public interface ICLIService {
 
   public abstract OperationHandle executeStatement(SessionHandle sessionHandle, String statement,
       Map<String, String> confOverlay)
-      throws HiveSQLException;
+          throws HiveSQLException;
 
   public abstract OperationHandle executeStatementAsync(SessionHandle sessionHandle,
       String statement, Map<String, String> confOverlay)
-      throws HiveSQLException;
+          throws HiveSQLException;
 
   public abstract OperationHandle getTypeInfo(SessionHandle sessionHandle)
       throws HiveSQLException;
@@ -55,24 +55,24 @@ public interface ICLIService {
 
   public abstract OperationHandle getSchemas(SessionHandle sessionHandle,
       String catalogName, String schemaName)
-      throws HiveSQLException;
+          throws HiveSQLException;
 
   public abstract OperationHandle getTables(SessionHandle sessionHandle,
       String catalogName, String schemaName, String tableName, List<String> tableTypes)
-      throws HiveSQLException;
+          throws HiveSQLException;
 
   public abstract OperationHandle getTableTypes(SessionHandle sessionHandle)
       throws HiveSQLException;
 
   public abstract OperationHandle getColumns(SessionHandle sessionHandle,
       String catalogName, String schemaName, String tableName, String columnName)
-      throws HiveSQLException;
+          throws HiveSQLException;
 
   public abstract OperationHandle getFunctions(SessionHandle sessionHandle,
       String catalogName, String schemaName, String functionName)
-      throws HiveSQLException;
+          throws HiveSQLException;
 
-  public abstract OperationState getOperationStatus(OperationHandle opHandle)
+  public abstract OperationStatus getOperationStatus(OperationHandle opHandle)
       throws HiveSQLException;
 
   public abstract void cancelOperation(OperationHandle opHandle)
@@ -86,7 +86,7 @@ public interface ICLIService {
 
   public abstract RowSet fetchResults(OperationHandle opHandle, FetchOrientation orientation,
       long maxRows)
-      throws HiveSQLException;
+          throws HiveSQLException;
 
   public abstract RowSet fetchResults(OperationHandle opHandle)
       throws HiveSQLException;

Modified: hive/branches/tez/service/src/java/org/apache/hive/service/cli/OperationState.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/OperationState.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/java/org/apache/hive/service/cli/OperationState.java (original)
+++ hive/branches/tez/service/src/java/org/apache/hive/service/cli/OperationState.java Wed Dec 18 17:22:02 2013
@@ -94,7 +94,7 @@ public enum OperationState {
   }
 
   public void validateTransition(OperationState newState)
-  throws HiveSQLException {
+      throws HiveSQLException {
     validateTransition(this, newState);
   }
 

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=1552041&r1=1552040&r2=1552041&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 Wed Dec 18 17:22:02 2013
@@ -26,6 +26,7 @@ import org.apache.hive.service.cli.Fetch
 import org.apache.hive.service.cli.HiveSQLException;
 import org.apache.hive.service.cli.OperationHandle;
 import org.apache.hive.service.cli.OperationState;
+import org.apache.hive.service.cli.OperationStatus;
 import org.apache.hive.service.cli.OperationType;
 import org.apache.hive.service.cli.RowSet;
 import org.apache.hive.service.cli.TableSchema;
@@ -41,6 +42,7 @@ public abstract class Operation {
   public static final Log LOG = LogFactory.getLog(Operation.class.getName());
   public static final long DEFAULT_FETCH_MAX_ROWS = 100;
   protected boolean hasResultSet;
+  protected volatile HiveSQLException operationException;
 
   protected static final EnumSet<FetchOrientation> DEFAULT_FETCH_ORIENTATION_SET =
       EnumSet.of(FetchOrientation.FETCH_NEXT,FetchOrientation.FETCH_FIRST);
@@ -71,8 +73,8 @@ public abstract class Operation {
     return opHandle.getOperationType();
   }
 
-  public OperationState getState() {
-    return state;
+  public OperationStatus getStatus() {
+    return new OperationStatus(state, operationException);
   }
 
   public boolean hasResultSet() {
@@ -90,6 +92,10 @@ public abstract class Operation {
     return this.state;
   }
 
+  protected void setOperationException(HiveSQLException operationException) {
+    this.operationException = operationException;
+  }
+
   protected final void assertState(OperationState state) throws HiveSQLException {
     if (this.state != state) {
       throw new HiveSQLException("Expected state " + state + ", but found " + this.state);
@@ -97,19 +103,19 @@ public abstract class Operation {
   }
 
   public boolean isRunning() {
-    return OperationState.RUNNING.equals(getState());
+    return OperationState.RUNNING.equals(state);
   }
 
   public boolean isFinished() {
-    return OperationState.FINISHED.equals(getState());
+    return OperationState.FINISHED.equals(state);
   }
 
   public boolean isCanceled() {
-    return OperationState.CANCELED.equals(getState());
+    return OperationState.CANCELED.equals(state);
   }
 
   public boolean isFailed() {
-    return OperationState.ERROR.equals(getState());
+    return OperationState.ERROR.equals(state);
   }
 
   public abstract void run() throws HiveSQLException;

Modified: hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/OperationManager.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/OperationManager.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/OperationManager.java (original)
+++ hive/branches/tez/service/src/java/org/apache/hive/service/cli/operation/OperationManager.java Wed Dec 18 17:22:02 2013
@@ -27,7 +27,7 @@ import org.apache.hive.service.AbstractS
 import org.apache.hive.service.cli.FetchOrientation;
 import org.apache.hive.service.cli.HiveSQLException;
 import org.apache.hive.service.cli.OperationHandle;
-import org.apache.hive.service.cli.OperationState;
+import org.apache.hive.service.cli.OperationStatus;
 import org.apache.hive.service.cli.RowSet;
 import org.apache.hive.service.cli.TableSchema;
 import org.apache.hive.service.cli.session.HiveSession;
@@ -67,7 +67,7 @@ public class OperationManager extends Ab
 
   public ExecuteStatementOperation newExecuteStatementOperation(HiveSession parentSession,
       String statement, Map<String, String> confOverlay, boolean runAsync)
-    throws HiveSQLException {
+          throws HiveSQLException {
     ExecuteStatementOperation executeStatementOperation = ExecuteStatementOperation
         .newExecuteStatementOperation(parentSession, statement, confOverlay, runAsync);
     addOperation(executeStatementOperation);
@@ -140,8 +140,8 @@ public class OperationManager extends Ab
     return handleToOperation.remove(opHandle);
   }
 
-  public OperationState getOperationState(OperationHandle opHandle) throws HiveSQLException {
-    return getOperation(opHandle).getState();
+  public OperationStatus getOperationStatus(OperationHandle opHandle) throws HiveSQLException {
+    return getOperation(opHandle).getStatus();
   }
 
   public void cancelOperation(OperationHandle opHandle) throws HiveSQLException {
@@ -167,7 +167,7 @@ public class OperationManager extends Ab
 
   public RowSet getOperationNextRowSet(OperationHandle opHandle,
       FetchOrientation orientation, long maxRows)
-      throws HiveSQLException {
+          throws HiveSQLException {
     return getOperation(opHandle).getNextRowSet(orientation, maxRows);
   }
 }

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=1552041&r1=1552040&r2=1552041&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 Wed Dec 18 17:22:02 2013
@@ -22,7 +22,6 @@ 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;
@@ -41,17 +40,17 @@ import org.apache.hadoop.hive.ql.process
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hadoop.hive.serde.serdeConstants;
 import org.apache.hadoop.hive.serde2.SerDe;
+import org.apache.hadoop.hive.serde2.SerDeException;
 import org.apache.hadoop.hive.serde2.SerDeUtils;
 import org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe;
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
-import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils;
-import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils.ObjectInspectorCopyOption;
 import org.apache.hadoop.hive.serde2.objectinspector.StructField;
 import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
 import org.apache.hadoop.io.BytesWritable;
 import org.apache.hive.service.cli.FetchOrientation;
 import org.apache.hive.service.cli.HiveSQLException;
 import org.apache.hive.service.cli.OperationState;
+import org.apache.hive.service.cli.OperationStatus;
 import org.apache.hive.service.cli.RowSet;
 import org.apache.hive.service.cli.TableSchema;
 import org.apache.hive.service.cli.session.HiveSession;
@@ -68,7 +67,7 @@ public class SQLOperation extends Execut
   private Schema mResultSchema = null;
   private SerDe serde = null;
   private final boolean runAsync;
-  private Future<?> backgroundHandle;
+  private volatile Future<?> backgroundHandle;
   private boolean fetchStarted = false;
 
   public SQLOperation(HiveSession parentSession, String statement, Map<String,
@@ -160,7 +159,7 @@ public class SQLOperation extends Execut
   public void run() throws HiveSQLException {
     setState(OperationState.PENDING);
     prepare(getConfigForOperation());
-    if (!shouldRunAsync()) {
+    if (!runAsync) {
       runInternal(getConfigForOperation());
     } else {
       Runnable backgroundOperation = new Runnable() {
@@ -171,16 +170,15 @@ public class SQLOperation extends Execut
           try {
             runInternal(getConfigForOperation());
           } catch (HiveSQLException e) {
+            setOperationException(e);
             LOG.error("Error: ", e);
-            // TODO: Return a more detailed error to the client,
-            // currently the async thread only writes to the log and sets the OperationState
           }
         }
       };
       try {
         // This submit blocks if no background threads are available to run this operation
         backgroundHandle =
-          getParentSession().getSessionManager().submitBackgroundOperation(backgroundOperation);
+            getParentSession().getSessionManager().submitBackgroundOperation(backgroundOperation);
       } catch (RejectedExecutionException rejected) {
         setState(OperationState.ERROR);
         throw new HiveSQLException("All the asynchronous threads are currently busy, " +
@@ -191,7 +189,7 @@ public class SQLOperation extends Execut
 
   private void cleanup(OperationState state) throws HiveSQLException {
     setState(state);
-    if (shouldRunAsync()) {
+    if (runAsync) {
       if (backgroundHandle != null) {
         backgroundHandle.cancel(true);
       }
@@ -226,75 +224,75 @@ public class SQLOperation extends Execut
     return resultSchema;
   }
 
+  private transient final List<Object> convey = new ArrayList<Object>();
 
   @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);
+    assertState(OperationState.FINISHED);
 
     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
+       * then reset the fetch position to beginning
        */
       if (orientation.equals(FetchOrientation.FETCH_FIRST) && fetchStarted) {
         driver.resetFetch();
       }
       fetchStarted = true;
-      driver.getResults(rows);
-
-      getSerDe();
-      StructObjectInspector soi = (StructObjectInspector) serde.getObjectInspector();
-      List<? extends StructField> fieldRefs = soi.getAllStructFieldRefs();
-      RowSet rowSet = new RowSet();
-
-      Object[] deserializedFields = new Object[fieldRefs.size()];
-      Object rowObj;
-      ObjectInspector fieldOI;
-
-      for (String rowString : rows) {
-        rowObj = serde.deserialize(new BytesWritable(rowString.getBytes()));
-        for (int i = 0; i < fieldRefs.size(); i++) {
-          StructField fieldRef = fieldRefs.get(i);
-          fieldOI = fieldRef.getFieldObjectInspector();
-          deserializedFields[i] = convertLazyToJava(soi.getStructFieldData(rowObj, fieldRef), fieldOI);
-        }
-        rowSet.addRow(resultSchema, deserializedFields);
+      driver.setMaxRows((int) maxRows);
+      if (driver.getResults(convey)) {
+        return decode(convey);
       }
-      return rowSet;
+      return new RowSet();
     } catch (IOException e) {
       throw new HiveSQLException(e);
     } catch (CommandNeedRetryException e) {
       throw new HiveSQLException(e);
     } catch (Exception e) {
       throw new HiveSQLException(e);
+    } finally {
+      convey.clear();
     }
   }
 
-  /**
-   * Convert a LazyObject to a standard Java object in compliance with JDBC 3.0 (see JDBC 3.0
-   * Specification, Table B-3: Mapping from JDBC Types to Java Object Types).
-   *
-   * This method is kept consistent with {@link HiveResultSetMetaData#hiveTypeToSqlType}.
-   */
-  private static Object convertLazyToJava(Object o, ObjectInspector oi) {
-    Object obj = ObjectInspectorUtils.copyToStandardObject(o, oi, ObjectInspectorCopyOption.JAVA);
-
-    if (obj == null) {
-      return null;
+  private RowSet decode(List<Object> rows) throws Exception {
+    if (driver.isFetchingTable()) {
+      return prepareFromRow(rows);
     }
-    if(oi.getTypeName().equals(serdeConstants.BINARY_TYPE_NAME)) {
-      return new String((byte[])obj);
-    }
-    // for now, expose non-primitive as a string
-    // TODO: expose non-primitive as a structured object while maintaining JDBC compliance
-    if (oi.getCategory() != ObjectInspector.Category.PRIMITIVE) {
-      return SerDeUtils.getJSONString(o, oi);
+    return decodeFromString(rows);
+  }
+
+  // already encoded to thrift-able object in ThriftFormatter
+  private RowSet prepareFromRow(List<Object> rows) throws Exception {
+    RowSet rowSet = new RowSet();
+    for (Object row : rows) {
+      rowSet.addRow(resultSchema, (Object[]) row);
     }
-    return obj;
+    return rowSet;
   }
 
+  private RowSet decodeFromString(List<Object> rows) throws SQLException, SerDeException {
+    getSerDe();
+    StructObjectInspector soi = (StructObjectInspector) serde.getObjectInspector();
+    List<? extends StructField> fieldRefs = soi.getAllStructFieldRefs();
+    RowSet rowSet = new RowSet();
+
+    Object[] deserializedFields = new Object[fieldRefs.size()];
+    Object rowObj;
+    ObjectInspector fieldOI;
+
+    for (Object rowString : rows) {
+      rowObj = serde.deserialize(new BytesWritable(((String)rowString).getBytes()));
+      for (int i = 0; i < fieldRefs.size(); i++) {
+        StructField fieldRef = fieldRefs.get(i);
+        fieldOI = fieldRef.getFieldObjectInspector();
+        Object fieldData = soi.getStructFieldData(rowObj, fieldRef);
+        deserializedFields[i] = SerDeUtils.toThriftPayload(fieldData, fieldOI);
+      }
+      rowSet.addRow(resultSchema, deserializedFields);
+    }
+    return rowSet;
+  }
 
   private SerDe getSerDe() throws SQLException {
     if (serde != null) {
@@ -302,8 +300,6 @@ public class SQLOperation extends Execut
     }
     try {
       List<FieldSchema> fieldSchemas = mResultSchema.getFieldSchemas();
-      List<String> columnNames = new ArrayList<String>();
-      List<String> columnTypes = new ArrayList<String>();
       StringBuilder namesSb = new StringBuilder();
       StringBuilder typesSb = new StringBuilder();
 
@@ -313,8 +309,6 @@ public class SQLOperation extends Execut
             namesSb.append(",");
             typesSb.append(",");
           }
-          columnNames.add(fieldSchemas.get(pos).getName());
-          columnTypes.add(fieldSchemas.get(pos).getType());
           namesSb.append(fieldSchemas.get(pos).getName());
           typesSb.append(fieldSchemas.get(pos).getType());
         }
@@ -341,10 +335,6 @@ public class SQLOperation extends Execut
     return serde;
   }
 
-  private boolean shouldRunAsync() {
-    return runAsync;
-  }
-
   /**
    * If there are query specific settings to overlay, then create a copy of config
    * There are two cases we need to clone the session config that's being passed to hive driver
@@ -357,7 +347,7 @@ public class SQLOperation extends Execut
    */
   private HiveConf getConfigForOperation() throws HiveSQLException {
     HiveConf sqlOperationConf = getParentSession().getHiveConf();
-    if (!getConfOverlay().isEmpty() || shouldRunAsync()) {
+    if (!getConfOverlay().isEmpty() || runAsync) {
       // clone the partent session config for this query
       sqlOperationConf = new HiveConf(sqlOperationConf);
 

Modified: hive/branches/tez/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java (original)
+++ hive/branches/tez/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java Wed Dec 18 17:22:02 2013
@@ -32,6 +32,8 @@ import org.apache.hadoop.hive.conf.HiveC
 import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
 import org.apache.hadoop.hive.metastore.IMetaStoreClient;
 import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.ql.exec.FetchFormatter;
+import org.apache.hadoop.hive.ql.exec.ListSinkOperator;
 import org.apache.hadoop.hive.ql.history.HiveHistory;
 import org.apache.hadoop.hive.ql.session.SessionState;
 import org.apache.hive.common.util.HiveVersionInfo;
@@ -88,6 +90,9 @@ public class HiveSessionImpl implements 
     // set an explicit session name to control the download directory name
     hiveConf.set(ConfVars.HIVESESSIONID.varname,
         sessionHandle.getHandleIdentifier().toString());
+    // use thrift transportable formatter
+    hiveConf.set(ListSinkOperator.OUTPUT_FORMATTER,
+        FetchFormatter.ThriftFormatter.class.getName());
     sessionState = new SessionState(hiveConf);
     SessionState.start(sessionState);
   }
@@ -197,7 +202,11 @@ public class HiveSessionImpl implements 
       opHandleSet.add(opHandle);
       return opHandle;
     } catch (HiveSQLException e) {
-      operationManager.closeOperation(opHandle);
+      // Cleanup opHandle in case the query is synchronous
+      // Async query needs to retain and pass back the opHandle for error reporting
+      if (!runAsync) {
+        operationManager.closeOperation(opHandle);
+      }
       throw e;
     } finally {
       release();

Modified: hive/branches/tez/service/src/java/org/apache/hive/service/cli/session/SessionManager.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/session/SessionManager.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/java/org/apache/hive/service/cli/session/SessionManager.java (original)
+++ hive/branches/tez/service/src/java/org/apache/hive/service/cli/session/SessionManager.java Wed Dec 18 17:22:02 2013
@@ -43,13 +43,10 @@ import org.apache.hive.service.cli.opera
 public class SessionManager extends CompositeService {
 
   private static final Log LOG = LogFactory.getLog(CompositeService.class);
-
   private HiveConf hiveConf;
-
   private final Map<SessionHandle, HiveSession> handleToSession =
       new ConcurrentHashMap<SessionHandle, HiveSession>();
   private final OperationManager operationManager = new OperationManager();
-
   private ThreadPoolExecutor backgroundOperationPool;
 
   public SessionManager() {
@@ -96,19 +93,19 @@ public class SessionManager extends Comp
   }
 
   public SessionHandle openSession(String username, String password, Map<String, String> sessionConf)
-          throws HiveSQLException {
-     return openSession(username, password, sessionConf, false, null);
+      throws HiveSQLException {
+    return openSession(username, password, sessionConf, false, null);
   }
 
   public SessionHandle openSession(String username, String password, Map<String, String> sessionConf,
-          boolean withImpersonation, String delegationToken) throws HiveSQLException {
+      boolean withImpersonation, String delegationToken) throws HiveSQLException {
     if (username == null) {
       username = threadLocalUserName.get();
     }
     HiveSession session;
     if (withImpersonation) {
       HiveSessionImplwithUGI hiveSessionUgi = new HiveSessionImplwithUGI(username, password,
-        sessionConf, delegationToken);
+          sessionConf, delegationToken);
       session = HiveSessionProxy.getProxy(hiveSessionUgi, hiveSessionUgi.getSessionUgi());
       hiveSessionUgi.setProxySession(session);
     } else {

Modified: hive/branches/tez/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java (original)
+++ hive/branches/tez/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java Wed Dec 18 17:22:02 2013
@@ -37,7 +37,7 @@ import org.apache.hive.service.cli.GetIn
 import org.apache.hive.service.cli.GetInfoValue;
 import org.apache.hive.service.cli.HiveSQLException;
 import org.apache.hive.service.cli.OperationHandle;
-import org.apache.hive.service.cli.OperationState;
+import org.apache.hive.service.cli.OperationStatus;
 import org.apache.hive.service.cli.RowSet;
 import org.apache.hive.service.cli.SessionHandle;
 import org.apache.hive.service.cli.TableSchema;
@@ -114,6 +114,7 @@ public abstract class ThriftCLIService e
 
   @Override
   public TOpenSessionResp OpenSession(TOpenSessionReq req) throws TException {
+    LOG.info("Client protocol version: " + req.getClient_protocol());
     TOpenSessionResp resp = new TOpenSessionResp();
     try {
       SessionHandle sessionHandle = getSessionHandle(req);
@@ -210,8 +211,8 @@ public abstract class ThriftCLIService e
           resp.setOperationHandle(operationHandle.toTOperationHandle());
           resp.setStatus(OK_STATUS);
     } catch (Exception e) {
-       LOG.warn("Error executing statement: ", e);
-       resp.setStatus(HiveSQLException.toTStatus(e));
+      LOG.warn("Error executing statement: ", e);
+      resp.setStatus(HiveSQLException.toTStatus(e));
     }
     return resp;
   }
@@ -328,8 +329,15 @@ public abstract class ThriftCLIService e
   public TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req) throws TException {
     TGetOperationStatusResp resp = new TGetOperationStatusResp();
     try {
-      OperationState operationState = cliService.getOperationStatus(new OperationHandle(req.getOperationHandle()));
-      resp.setOperationState(operationState.toTOperationState());
+      OperationStatus operationStatus = cliService.getOperationStatus(
+          new OperationHandle(req.getOperationHandle()));
+      resp.setOperationState(operationStatus.getState().toTOperationState());
+      HiveSQLException opException = operationStatus.getOperationException();
+      if (opException != null) {
+        resp.setSqlState(opException.getSQLState());
+        resp.setErrorCode(opException.getErrorCode());
+        resp.setErrorMessage(opException.getMessage());
+      }
       resp.setStatus(OK_STATUS);
     } catch (Exception e) {
       LOG.warn("Error getting operation status: ", e);

Modified: hive/branches/tez/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIServiceClient.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIServiceClient.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIServiceClient.java (original)
+++ hive/branches/tez/service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIServiceClient.java Wed Dec 18 17:22:02 2013
@@ -28,6 +28,7 @@ import org.apache.hive.service.cli.GetIn
 import org.apache.hive.service.cli.HiveSQLException;
 import org.apache.hive.service.cli.OperationHandle;
 import org.apache.hive.service.cli.OperationState;
+import org.apache.hive.service.cli.OperationStatus;
 import org.apache.hive.service.cli.RowSet;
 import org.apache.hive.service.cli.SessionHandle;
 import org.apache.hive.service.cli.TableSchema;
@@ -295,12 +296,18 @@ public class ThriftCLIServiceClient exte
    * @see org.apache.hive.service.cli.ICLIService#getOperationStatus(org.apache.hive.service.cli.OperationHandle)
    */
   @Override
-  public OperationState getOperationStatus(OperationHandle opHandle) throws HiveSQLException {
+  public OperationStatus getOperationStatus(OperationHandle opHandle) throws HiveSQLException {
     try {
       TGetOperationStatusReq req = new TGetOperationStatusReq(opHandle.toTOperationHandle());
       TGetOperationStatusResp resp = cliService.GetOperationStatus(req);
+      // Checks the status of the RPC call, throws an exception in case of error
       checkStatus(resp.getStatus());
-      return OperationState.getOperationState(resp.getOperationState());
+      OperationState opState = OperationState.getOperationState(resp.getOperationState());
+      HiveSQLException opException = null;
+      if (opState == OperationState.ERROR) {
+        opException = new HiveSQLException(resp.getErrorMessage(), resp.getSqlState(), resp.getErrorCode());
+      }
+      return new OperationStatus(opState, opException);
     } catch (HiveSQLException e) {
       throw e;
     } catch (Exception e) {

Modified: hive/branches/tez/service/src/test/org/apache/hive/service/cli/CLIServiceTest.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/test/org/apache/hive/service/cli/CLIServiceTest.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/test/org/apache/hive/service/cli/CLIServiceTest.java (original)
+++ hive/branches/tez/service/src/test/org/apache/hive/service/cli/CLIServiceTest.java Wed Dec 18 17:22:02 2013
@@ -20,6 +20,7 @@ package org.apache.hive.service.cli;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.junit.Assert.assertTrue;
 
@@ -28,6 +29,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.ErrorMsg;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -56,8 +58,8 @@ public abstract class CLIServiceTest {
 
   @Test
   public void openSessionTest() throws Exception {
-    SessionHandle sessionHandle = client
-        .openSession("tom", "password", Collections.<String, String>emptyMap());
+    SessionHandle sessionHandle = client.openSession(
+        "tom", "password", Collections.<String, String>emptyMap());
     assertNotNull(sessionHandle);
     client.closeSession(sessionHandle);
 
@@ -68,8 +70,9 @@ public abstract class CLIServiceTest {
 
   @Test
   public void getFunctionsTest() throws Exception {
-    SessionHandle sessionHandle = client.openSession("tom", "password", new HashMap<String, String>());
+    SessionHandle sessionHandle = client.openSession("tom", "password");
     assertNotNull(sessionHandle);
+
     OperationHandle opHandle = client.getFunctions(sessionHandle, null, null, "*");
     TableSchema schema = client.getResultSetMetadata(opHandle);
 
@@ -97,13 +100,15 @@ public abstract class CLIServiceTest {
     assertEquals("SPECIFIC_NAME", columnDesc.getName());
     assertEquals(Type.STRING_TYPE, columnDesc.getType());
 
+    // Cleanup
     client.closeOperation(opHandle);
     client.closeSession(sessionHandle);
   }
 
   @Test
   public void getInfoTest() throws Exception {
-    SessionHandle sessionHandle = client.openSession("tom", "password", new HashMap<String, String>());
+    SessionHandle sessionHandle = client.openSession(
+        "tom", "password", Collections.<String, String>emptyMap());
     assertNotNull(sessionHandle);
 
     GetInfoValue value = client.getInfo(sessionHandle, GetInfoType.CLI_DBMS_NAME);
@@ -121,30 +126,39 @@ public abstract class CLIServiceTest {
   @Test
   public void testExecuteStatement() throws Exception {
     HashMap<String, String> confOverlay = new HashMap<String, String>();
-    SessionHandle sessionHandle = client.openSession("tom", "password",
-        new HashMap<String, String>());
+    SessionHandle sessionHandle = client.openSession(
+        "tom", "password", new HashMap<String, String>());
     assertNotNull(sessionHandle);
 
-    // Change lock manager, otherwise unit-test doesn't go through
-    String queryString = "SET hive.lock.manager=" +
-        "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
-    client.executeStatement(sessionHandle, queryString, confOverlay);
+    OperationHandle opHandle;
+
+    String queryString = "SET " + HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname
+        + " = false";
+    opHandle = client.executeStatement(sessionHandle, queryString, confOverlay);
+    client.closeOperation(opHandle);
 
-    // Drop the table if it exists
     queryString = "DROP TABLE IF EXISTS TEST_EXEC";
-    client.executeStatement(sessionHandle, queryString, confOverlay);
+    opHandle = client.executeStatement(sessionHandle, queryString, confOverlay);
+    client.closeOperation(opHandle);
 
     // Create a test table
     queryString = "CREATE TABLE TEST_EXEC(ID STRING)";
-    client.executeStatement(sessionHandle, queryString, confOverlay);
+    opHandle = client.executeStatement(sessionHandle, queryString, confOverlay);
+    client.closeOperation(opHandle);
 
     // Blocking execute
     queryString = "SELECT ID FROM TEST_EXEC";
-    OperationHandle ophandle = client.executeStatement(sessionHandle, queryString, confOverlay);
-
+    opHandle = client.executeStatement(sessionHandle, queryString, confOverlay);
     // Expect query to be completed now
     assertEquals("Query should be finished",
-        OperationState.FINISHED, client.getOperationStatus(ophandle));
+        OperationState.FINISHED, client.getOperationStatus(opHandle).getState());
+    client.closeOperation(opHandle);
+
+    // Cleanup
+    queryString = "DROP TABLE IF EXISTS TEST_EXEC";
+    opHandle = client.executeStatement(sessionHandle, queryString, confOverlay);
+    client.closeOperation(opHandle);
+    client.closeSession(sessionHandle);
   }
 
   @Test
@@ -156,32 +170,40 @@ public abstract class CLIServiceTest {
     long pollTimeout = System.currentTimeMillis() + 100000;
     assertNotNull(sessionHandle);
     OperationState state = null;
-    OperationHandle ophandle = null;
+    OperationHandle opHandle;
+    OperationStatus opStatus = null;
 
     // Change lock manager, otherwise unit-test doesn't go through
-    String queryString = "SET hive.lock.manager=" +
-        "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
-    client.executeStatement(sessionHandle, queryString, confOverlay);
+    String queryString = "SET " + HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname
+        + " = false";
+    opHandle = client.executeStatement(sessionHandle, queryString, confOverlay);
+    client.closeOperation(opHandle);
 
     // Drop the table if it exists
     queryString = "DROP TABLE IF EXISTS TEST_EXEC_ASYNC";
-    client.executeStatement(sessionHandle, queryString, confOverlay);
+    opHandle = client.executeStatement(sessionHandle, queryString, confOverlay);
+    client.closeOperation(opHandle);
 
     // Create a test table
     queryString = "CREATE TABLE TEST_EXEC_ASYNC(ID STRING)";
-    client.executeStatement(sessionHandle, queryString, confOverlay);
+    opHandle = client.executeStatement(sessionHandle, queryString, confOverlay);
+    client.closeOperation(opHandle);
 
     // Test async execution response when query is malformed
-    String wrongQuery = "SELECT NAME FROM TEST_EXEC";
+    // Compile time error
+    // This query will error out during compilation (which is done synchronous as of now)
+    String wrongQueryString = "SELECT NON_EXISTANT_COLUMN FROM TEST_EXEC_ASYNC";
     try {
-      ophandle = client.executeStatementAsync(sessionHandle, wrongQuery, confOverlay);
+      opHandle = client.executeStatementAsync(sessionHandle, wrongQueryString, confOverlay);
       fail("Async syntax excution should fail");
     } catch (HiveSQLException e) {
       // expected error
     }
+    
 
-    wrongQuery = "CREATE TABLE NON_EXISTING_TAB (ID STRING) location 'hdfs://fooNN:10000/a/b/c'";
-    ophandle = client.executeStatementAsync(sessionHandle, wrongQuery, confOverlay);
+    // Runtime error
+    wrongQueryString = "CREATE TABLE NON_EXISTING_TAB (ID STRING) location 'hdfs://fooNN:10000/a/b/c'";
+    opHandle = client.executeStatementAsync(sessionHandle, wrongQueryString, confOverlay);
 
     int count = 0;
     while (true) {
@@ -190,25 +212,28 @@ public abstract class CLIServiceTest {
         System.out.println("Polling timed out");
         break;
       }
-      state = client.getOperationStatus(ophandle);
-      System.out.println("Polling: " + ophandle + " count=" + (++count)
+      opStatus = client.getOperationStatus(opHandle);
+      state = opStatus.getState();
+      System.out.println("Polling: " + opHandle + " count=" + (++count)
           + " state=" + state);
 
-      if (OperationState.CANCELED == state || state == OperationState.CLOSED
+      if (state == OperationState.CANCELED || state == OperationState.CLOSED
           || state == OperationState.FINISHED || state == OperationState.ERROR) {
         break;
       }
       Thread.sleep(1000);
     }
-    assertEquals("Query should return an error state",
-        OperationState.ERROR, client.getOperationStatus(ophandle));
-
+    assertEquals("Operation should be in error state", OperationState.ERROR, state);
+    // sqlState, errorCode should be set
+    assertEquals(opStatus.getOperationException().getSQLState(), "08S01");
+    assertEquals(opStatus.getOperationException().getErrorCode(), 1);
+    client.closeOperation(opHandle);
+    
     // Test async execution when query is well formed
     queryString = "SELECT ID FROM TEST_EXEC_ASYNC";
-    ophandle =
-        client.executeStatementAsync(sessionHandle, queryString, confOverlay);
-
-    assertTrue(ophandle.hasResultSet());
+    opHandle = client.executeStatementAsync(sessionHandle, queryString, confOverlay);
+    assertTrue(opHandle.hasResultSet());
+    
     count = 0;
     while (true) {
       // Break if polling times out
@@ -216,26 +241,33 @@ public abstract class CLIServiceTest {
         System.out.println("Polling timed out");
         break;
       }
-      state = client.getOperationStatus(ophandle);
-      System.out.println("Polling: " + ophandle + " count=" + (++count)
+      opStatus = client.getOperationStatus(opHandle);
+      state = opStatus.getState();
+      System.out.println("Polling: " + opHandle + " count=" + (++count)
           + " state=" + state);
 
-      if (OperationState.CANCELED == state || state == OperationState.CLOSED
+      if (state == OperationState.CANCELED || state == OperationState.CLOSED
           || state == OperationState.FINISHED || state == OperationState.ERROR) {
         break;
       }
       Thread.sleep(1000);
     }
-    assertEquals("Query should be finished",
-        OperationState.FINISHED, client.getOperationStatus(ophandle));
+    assertEquals("Query should be finished", OperationState.FINISHED, state);
+    client.closeOperation(opHandle);
 
     // Cancellation test
-    ophandle = client.executeStatementAsync(sessionHandle, queryString, confOverlay);
-    System.out.println("cancelling " + ophandle);
-    client.cancelOperation(ophandle);
-    state = client.getOperationStatus(ophandle);
-    System.out.println(ophandle + " after cancelling, state= " + state);
+    opHandle = client.executeStatementAsync(sessionHandle, queryString, confOverlay);
+    System.out.println("cancelling " + opHandle);
+    client.cancelOperation(opHandle);
+    state = client.getOperationStatus(opHandle).getState();
+    System.out.println(opHandle + " after cancelling, state= " + state);
     assertEquals("Query should be cancelled", OperationState.CANCELED, state);
+
+    // Cleanup
+    queryString = "DROP TABLE IF EXISTS TEST_EXEC_ASYNC";
+    opHandle = client.executeStatement(sessionHandle, queryString, confOverlay);
+    client.closeOperation(opHandle);
+    client.closeSession(sessionHandle);
   }
 
   /**
@@ -271,7 +303,7 @@ public abstract class CLIServiceTest {
     assertNotNull(opHandle);
     // query should pass and create the table
     assertEquals("Query should be finished",
-        OperationState.FINISHED, client.getOperationStatus(opHandle));
+        OperationState.FINISHED, client.getOperationStatus(opHandle).getState());
     client.closeOperation(opHandle);
 
     // select from  the new table should pass
@@ -280,10 +312,10 @@ public abstract class CLIServiceTest {
     assertNotNull(opHandle);
     // query should pass and create the table
     assertEquals("Query should be finished",
-        OperationState.FINISHED, client.getOperationStatus(opHandle));
+        OperationState.FINISHED, client.getOperationStatus(opHandle).getState());
     client.closeOperation(opHandle);
 
-    // the settings in confoverly should not be part of session config
+    // the settings in conf overlay should not be part of session config
     // another query referring that property with the conf overlay should fail
     selectTab = "SELECT * FROM ${hiveconf:" + tabNameVar + "}";
     try {
@@ -297,8 +329,6 @@ public abstract class CLIServiceTest {
     dropTable = "DROP TABLE IF EXISTS " + tabName;
     opHandle = client.executeStatement(sessionHandle, dropTable, null);
     client.closeOperation(opHandle);
-
-
     client.closeSession(sessionHandle);
   }
 }

Modified: hive/branches/tez/service/src/test/org/apache/hive/service/cli/thrift/ThriftCLIServiceTest.java
URL: http://svn.apache.org/viewvc/hive/branches/tez/service/src/test/org/apache/hive/service/cli/thrift/ThriftCLIServiceTest.java?rev=1552041&r1=1552040&r2=1552041&view=diff
==============================================================================
--- hive/branches/tez/service/src/test/org/apache/hive/service/cli/thrift/ThriftCLIServiceTest.java (original)
+++ hive/branches/tez/service/src/test/org/apache/hive/service/cli/thrift/ThriftCLIServiceTest.java Wed Dec 18 17:22:02 2013
@@ -31,12 +31,12 @@ import javax.security.auth.login.LoginEx
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
 import org.apache.hadoop.hive.metastore.MetaStoreUtils;
+import org.apache.hadoop.hive.ql.ErrorMsg;
 import org.apache.hive.service.Service;
 import org.apache.hive.service.auth.HiveAuthFactory;
 import org.apache.hive.service.auth.PlainSaslHelper;
 import org.apache.hive.service.cli.CLIService;
 import org.apache.hive.service.cli.HiveSQLException;
-import org.apache.hive.service.cli.OperationState;
 import org.apache.hive.service.cli.SessionHandle;
 import org.apache.hive.service.cli.session.HiveSession;
 import org.apache.hive.service.cli.session.SessionManager;
@@ -67,8 +67,6 @@ public abstract class ThriftCLIServiceTe
   protected static String anonymousUser = "anonymous";
   protected static String anonymousPasswd = "anonymous";
 
-
-
   /**
    * @throws java.lang.Exception
    */
@@ -162,6 +160,10 @@ public abstract class ThriftCLIServiceTe
     client.CloseSession(closeReq);
   }
 
+  /**
+   * Test synchronous query execution
+   * @throws Exception
+   */
   @Test
   public void testExecuteStatement() throws Exception {
     // Create a new request object
@@ -172,19 +174,19 @@ public abstract class ThriftCLIServiceTe
     // Change lock manager to embedded mode
     String queryString = "SET hive.lock.manager=" +
         "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
-    executeQuerySync(queryString, sessHandle);
+    executeQuery(queryString, sessHandle, false);
 
     // Drop the table if it exists
     queryString = "DROP TABLE IF EXISTS TEST_EXEC_THRIFT";
-    executeQuerySync(queryString, sessHandle);
+    executeQuery(queryString, sessHandle, false);
 
     // Create a test table
     queryString = "CREATE TABLE TEST_EXEC_THRIFT(ID STRING)";
-    executeQuerySync(queryString, sessHandle);
+    executeQuery(queryString, sessHandle, false);
 
-    // Execute another query to test
+    // Execute another query
     queryString = "SELECT ID FROM TEST_EXEC_THRIFT";
-    TExecuteStatementResp execResp = executeQuerySync(queryString, sessHandle);
+    TExecuteStatementResp execResp = executeQuery(queryString, sessHandle, false);
     TOperationHandle operationHandle = execResp.getOperationHandle();
     assertNotNull(operationHandle);
 
@@ -192,28 +194,133 @@ public abstract class ThriftCLIServiceTe
     opStatusReq.setOperationHandle(operationHandle);
     assertNotNull(opStatusReq);
     TGetOperationStatusResp opStatusResp = client.GetOperationStatus(opStatusReq);
-
+    TOperationState state = opStatusResp.getOperationState();
     // Expect query to be completed now
-    assertEquals("Query should be finished",
-        OperationState.FINISHED, OperationState.getOperationState(opStatusResp.getOperationState()));
+    assertEquals("Query should be finished", TOperationState.FINISHED_STATE, state);
 
+    // Cleanup
     queryString = "DROP TABLE TEST_EXEC_THRIFT";
-    executeQuerySync(queryString, sessHandle);
+    executeQuery(queryString, sessHandle, false);
+
+    // Close the session; ignore exception if any
+    TCloseSessionReq closeReq = new TCloseSessionReq(sessHandle);
+    client.CloseSession(closeReq);
+  }
+
+  /**
+   * Test asynchronous query execution and error message reporting to the client
+   * @throws Exception
+   */
+  @Test
+  public void testExecuteStatementAsync() throws Exception {
+    // Create a new request object
+    TOpenSessionReq openReq = new TOpenSessionReq();
+    TSessionHandle sessHandle = client.OpenSession(openReq).getSessionHandle();
+    assertNotNull(sessHandle);
+
+    // Change lock manager to embedded mode
+    String queryString = "SET hive.lock.manager=" +
+        "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
+    executeQuery(queryString, sessHandle, false);
+
+    // Drop the table if it exists
+    queryString = "DROP TABLE IF EXISTS TEST_EXEC_ASYNC_THRIFT";
+    executeQuery(queryString, sessHandle, false);
+
+    // Create a test table
+    queryString = "CREATE TABLE TEST_EXEC_ASYNC_THRIFT(ID STRING)";
+    executeQuery(queryString, sessHandle, false);
+
+    // Execute another query
+    queryString = "SELECT ID FROM TEST_EXEC_ASYNC_THRIFT";
+    System.out.println("Will attempt to execute: " + queryString);
+    TExecuteStatementResp execResp = executeQuery(queryString, sessHandle, true);
+    TOperationHandle operationHandle = execResp.getOperationHandle();
+    assertNotNull(operationHandle);
+
+    // Poll on the operation status till the query is completed
+    boolean isQueryRunning = true;
+    TGetOperationStatusReq opStatusReq;
+    TGetOperationStatusResp opStatusResp = null;
+    TOperationState state = null;
+    long pollTimeout = System.currentTimeMillis() + 100000;
+
+    while(isQueryRunning) {
+      // Break if polling times out
+      if (System.currentTimeMillis() > pollTimeout) {
+        System.out.println("Polling timed out");
+        break;
+      }
+      opStatusReq = new TGetOperationStatusReq();
+      opStatusReq.setOperationHandle(operationHandle);
+      assertNotNull(opStatusReq);
+      opStatusResp = client.GetOperationStatus(opStatusReq);
+      state = opStatusResp.getOperationState();
+      System.out.println("Current state: " + state);
+
+      if (state == TOperationState.CANCELED_STATE || state == TOperationState.CLOSED_STATE
+          || state == TOperationState.FINISHED_STATE || state == TOperationState.ERROR_STATE) {
+        isQueryRunning = false;
+      }
+      Thread.sleep(1000);
+    }
+
+    // Expect query to be successfully completed now
+    assertEquals("Query should be finished",
+        TOperationState.FINISHED_STATE, state);
+
+    // Execute a malformed query
+    // This query will give a runtime error
+    queryString = "CREATE TABLE NON_EXISTING_TAB (ID STRING) location 'hdfs://fooNN:10000/a/b/c'";
+    System.out.println("Will attempt to execute: " + queryString);
+    execResp = executeQuery(queryString, sessHandle, true);
+    operationHandle = execResp.getOperationHandle();
+    assertNotNull(operationHandle);
+    isQueryRunning = true;
+    while(isQueryRunning) {
+      // Break if polling times out
+      if (System.currentTimeMillis() > pollTimeout) {
+        System.out.println("Polling timed out");
+        break;
+      }
+      opStatusReq = new TGetOperationStatusReq();
+      opStatusReq.setOperationHandle(operationHandle);
+      assertNotNull(opStatusReq);
+      opStatusResp = client.GetOperationStatus(opStatusReq);
+      state = opStatusResp.getOperationState();
+      System.out.println("Current state: " + state);
+
+      if (state == TOperationState.CANCELED_STATE || state == TOperationState.CLOSED_STATE
+          || state == TOperationState.FINISHED_STATE || state == TOperationState.ERROR_STATE) {
+        isQueryRunning = false;
+      }
+      Thread.sleep(1000);
+    }
+
+    // Expect query to return an error state
+    assertEquals("Operation should be in error state", TOperationState.ERROR_STATE, state);
+
+    // sqlState, errorCode should be set to appropriate values
+    assertEquals(opStatusResp.getSqlState(), "08S01");
+    assertEquals(opStatusResp.getErrorCode(), 1);
+
+    // Cleanup
+    queryString = "DROP TABLE TEST_EXEC_ASYNC_THRIFT";
+    executeQuery(queryString, sessHandle, false);
 
     // Close the session; ignore exception if any
     TCloseSessionReq closeReq = new TCloseSessionReq(sessHandle);
     client.CloseSession(closeReq);
   }
 
-  private TExecuteStatementResp executeQuerySync(String queryString, TSessionHandle sessHandle)
+  private TExecuteStatementResp executeQuery(String queryString, TSessionHandle sessHandle, boolean runAsync)
       throws Exception {
     TExecuteStatementReq execReq = new TExecuteStatementReq();
     execReq.setSessionHandle(sessHandle);
     execReq.setStatement(queryString);
-    execReq.setRunAsync(false);
+    execReq.setRunAsync(runAsync);
     TExecuteStatementResp execResp = client.ExecuteStatement(execReq);
     assertNotNull(execResp);
-    assertFalse(execResp.getStatus().getStatusCode() == TStatusCode.ERROR_STATUS);
     return execResp;
   }
 



Mime
View raw message