diff --git service/if/TCLIService.thrift service/if/TCLIService.thrift index 4d7e89e..9726b48 100644 --- service/if/TCLIService.thrift +++ service/if/TCLIService.thrift @@ -568,6 +568,31 @@ struct TGetInfoResp { 2: required TGetInfoValue infoValue } +// Compile() +// +// Compile a statement. +// The returned OperationHandle can be used to: +// 1. execute the Compile statement +// 2. check on the status of the statement, and to fetch +// results once the statement has finished executing. +struct TCompileReq { + // The session to execute the statement against + 1: required TSessionHandle sessionHandle + + // The statement to be executed (DML, DDL, SET, etc) + 2: required string statement + + // Configuration properties that are overlayed on top of the + // the existing session configuration before this statement + // is executed. These properties apply to this statement + // only and will not affect the subsequent state of the Session. + 3: optional map confOverlay +} + +struct TCompileResp { + 1: required TStatus status + 2: optional TOperationHandle operationHandle +} // ExecuteStatement() // @@ -969,6 +994,8 @@ service TCLIService { TGetInfoResp GetInfo(1:TGetInfoReq req); + TCompileResp Compile(1:TCompileReq req); + TExecuteStatementResp ExecuteStatement(1:TExecuteStatementReq req); TGetTypeInfoResp GetTypeInfo(1:TGetTypeInfoReq req); diff --git service/src/java/org/apache/hive/service/cli/CLIService.java service/src/java/org/apache/hive/service/cli/CLIService.java index b53599b..f150784 100644 --- service/src/java/org/apache/hive/service/cli/CLIService.java +++ service/src/java/org/apache/hive/service/cli/CLIService.java @@ -325,4 +325,13 @@ public synchronized String getDelegationTokenFromMetaStore(String owner) } } } + + @Override + public OperationHandle compile(SessionHandle sessionHandle, String statement, + Map confOverlay) throws HiveSQLException { + OperationHandle opHandle = sessionManager.getSession(sessionHandle) + .compile(statement, confOverlay); + LOG.info(sessionHandle + ": compile()"); + return opHandle; + } } diff --git service/src/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java service/src/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java index 38d64c8..2490cab 100644 --- service/src/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java +++ service/src/java/org/apache/hive/service/cli/EmbeddedCLIServiceClient.java @@ -176,4 +176,9 @@ public RowSet fetchResults(OperationHandle opHandle, FetchOrientation orientatio return cliService.fetchResults(opHandle, orientation, maxRows); } + @Override + public OperationHandle compile(SessionHandle sessionHandle, String statement, + Map confOverlay) throws HiveSQLException { + return sqlService.compile(sessionHandle, statement, confOverlay); + } } diff --git service/src/java/org/apache/hive/service/cli/ICLIService.java service/src/java/org/apache/hive/service/cli/ICLIService.java index 7e863b5..f29cb9c 100644 --- service/src/java/org/apache/hive/service/cli/ICLIService.java +++ service/src/java/org/apache/hive/service/cli/ICLIService.java @@ -43,6 +43,10 @@ public abstract OperationHandle executeStatement(SessionHandle sessionHandle, St Map confOverlay) throws HiveSQLException; + public abstract OperationHandle compile(SessionHandle sessionHandle, String statement, + Map confOverlay) + throws HiveSQLException; + public abstract OperationHandle getTypeInfo(SessionHandle sessionHandle) throws HiveSQLException; diff --git service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java index 9a1da59..509e9c2 100644 --- service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java +++ service/src/java/org/apache/hive/service/cli/operation/ExecuteStatementOperation.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; +import org.apache.hive.service.cli.HiveSQLException; import org.apache.hive.service.cli.OperationType; import org.apache.hive.service.cli.session.HiveSession; @@ -39,6 +40,9 @@ public String getStatement() { return statement; } + public void prepare() throws HiveSQLException { + } + public static ExecuteStatementOperation newExecuteStatementOperation( HiveSession parentSession, String statement, Map confOverlay) { String[] tokens = statement.trim().split("\\s+"); diff --git service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java index 2fee93e..fedf40d 100644 --- service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java +++ service/src/java/org/apache/hive/service/cli/operation/SQLOperation.java @@ -68,12 +68,18 @@ public SQLOperation(HiveSession parentSession, String statement, Map co } } + public OperationHandle compile(String statement, Map confOverlay) + throws HiveSQLException { + acquire(); + try { + ExecuteStatementOperation operation = getOperationManager() + .newExecuteStatementOperation(this, statement, confOverlay); + operation.prepare(); + return operation.getHandle(); + } finally { + release(); + } + } + public OperationHandle getTypeInfo() throws HiveSQLException { acquire(); diff --git service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java index 43d79aa..74a734d 100644 --- service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java +++ service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java @@ -28,6 +28,7 @@ import org.apache.hadoop.hive.conf.HiveConf.ConfVars; import org.apache.hive.service.AbstractService; import org.apache.hive.service.auth.HiveAuthFactory; +import org.apache.hive.service.cli.CLIService; import org.apache.hive.service.cli.FetchOrientation; import org.apache.hive.service.cli.GetInfoType; import org.apache.hive.service.cli.GetInfoValue; @@ -35,7 +36,6 @@ import org.apache.hive.service.cli.OperationHandle; import org.apache.hive.service.cli.OperationState; import org.apache.hive.service.cli.RowSet; -import org.apache.hive.service.cli.CLIService; import org.apache.hive.service.cli.SessionHandle; import org.apache.hive.service.cli.TableSchema; import org.apache.thrift.TException; @@ -419,5 +419,22 @@ public void run() { t.printStackTrace(); } } - + + @Override + public TCompileResp Compile(TCompileReq req) throws TException { + TCompileResp resp = new TCompileResp(); + try { + SessionHandle sessionHandle = new SessionHandle(req.getSessionHandle()); + String statement = req.getStatement(); + Map confOverlay = req.getConfOverlay(); + OperationHandle operationHandle = + sqlService.compile(sessionHandle, statement, confOverlay); + resp.setOperationHandle(operationHandle.toTOperationHandle()); + resp.setStatus(OK_STATUS); + } catch (Exception e) { + e.printStackTrace(); + resp.setStatus(HiveSQLException.toTStatus(e)); + } + return resp; + } } diff --git service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIServiceClient.java service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIServiceClient.java index 5eb6157..c7e0a7c 100644 --- service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIServiceClient.java +++ service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIServiceClient.java @@ -370,4 +370,20 @@ public RowSet fetchResults(OperationHandle opHandle) throws HiveSQLException { // TODO: set the correct default fetch size return fetchResults(opHandle, FetchOrientation.FETCH_NEXT, 10000); } + + @Override + public OperationHandle compile(SessionHandle sessionHandle, String statement, + Map confOverlay) throws HiveSQLException { + try { + TCompileReq req = new TCompileReq(sessionHandle.toTSessionHandle(), statement); + req.setConfOverlay(confOverlay); + TCompileResp resp = sqlService.Compile(req); + checkStatus(resp.getStatus()); + return new OperationHandle(resp.getOperationHandle()); + } catch (HiveSQLException e) { + throw e; + } catch (Exception e) { + throw new HiveSQLException(e); + } + } }