0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 package org.apache.hive.service.cli.operation;
0019
0020 import java.sql.SQLException;
0021 import java.util.HashMap;
0022 import java.util.Map;
0023
0024 import org.apache.hadoop.hive.ql.processors.CommandProcessor;
0025 import org.apache.hadoop.hive.ql.processors.CommandProcessorFactory;
0026 import org.apache.hadoop.hive.ql.session.OperationLog;
0027 import org.apache.hive.service.cli.HiveSQLException;
0028 import org.apache.hive.service.cli.OperationType;
0029 import org.apache.hive.service.cli.session.HiveSession;
0030
0031 public abstract class ExecuteStatementOperation extends Operation {
0032 protected String statement = null;
0033 protected Map<String, String> confOverlay = new HashMap<String, String>();
0034
0035 public ExecuteStatementOperation(HiveSession parentSession, String statement,
0036 Map<String, String> confOverlay, boolean runInBackground) {
0037 super(parentSession, OperationType.EXECUTE_STATEMENT, runInBackground);
0038 this.statement = statement;
0039 setConfOverlay(confOverlay);
0040 }
0041
0042 public String getStatement() {
0043 return statement;
0044 }
0045
0046 public static ExecuteStatementOperation newExecuteStatementOperation(
0047 HiveSession parentSession, String statement, Map<String, String> confOverlay, boolean runAsync)
0048 throws HiveSQLException {
0049 String[] tokens = statement.trim().split("\\s+");
0050 CommandProcessor processor = null;
0051 try {
0052 processor = CommandProcessorFactory.getForHiveCommand(tokens, parentSession.getHiveConf());
0053 } catch (SQLException e) {
0054 throw new HiveSQLException(e.getMessage(), e.getSQLState(), e);
0055 }
0056 if (processor == null) {
0057 return new SQLOperation(parentSession, statement, confOverlay, runAsync);
0058 }
0059 return new HiveCommandOperation(parentSession, statement, processor, confOverlay);
0060 }
0061
0062 protected Map<String, String> getConfOverlay() {
0063 return confOverlay;
0064 }
0065
0066 protected void setConfOverlay(Map<String, String> confOverlay) {
0067 if (confOverlay != null) {
0068 this.confOverlay = confOverlay;
0069 }
0070 }
0071
0072 protected void registerCurrentOperationLog() {
0073 if (isOperationLogEnabled) {
0074 if (operationLog == null) {
0075 LOG.warn("Failed to get current OperationLog object of Operation: " +
0076 getHandle().getHandleIdentifier());
0077 isOperationLogEnabled = false;
0078 return;
0079 }
0080 OperationLog.setCurrentOperationLog(operationLog);
0081 }
0082 }
0083 }