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.Map;
0022
0023 import org.apache.hadoop.hive.ql.processors.CommandProcessor;
0024 import org.apache.hadoop.hive.ql.processors.CommandProcessorFactory;
0025 import org.apache.hadoop.hive.ql.session.OperationLog;
0026 import org.apache.hive.service.cli.HiveSQLException;
0027 import org.apache.hive.service.cli.OperationType;
0028 import org.apache.hive.service.cli.session.HiveSession;
0029
0030 public abstract class ExecuteStatementOperation extends Operation {
0031 protected String statement = null;
0032
0033 public ExecuteStatementOperation(HiveSession parentSession, String statement,
0034 Map<String, String> confOverlay, boolean runInBackground) {
0035 super(parentSession, confOverlay, OperationType.EXECUTE_STATEMENT, runInBackground);
0036 this.statement = statement;
0037 }
0038
0039 public String getStatement() {
0040 return statement;
0041 }
0042
0043 public static ExecuteStatementOperation newExecuteStatementOperation(HiveSession parentSession,
0044 String statement, Map<String, String> confOverlay, boolean runAsync, long queryTimeout)
0045 throws HiveSQLException {
0046 String[] tokens = statement.trim().split("\\s+");
0047 CommandProcessor processor = null;
0048 try {
0049 processor = CommandProcessorFactory.getForHiveCommand(tokens, parentSession.getHiveConf());
0050 } catch (SQLException e) {
0051 throw new HiveSQLException(e.getMessage(), e.getSQLState(), e);
0052 }
0053 if (processor == null) {
0054
0055 return new SQLOperation(parentSession, statement, confOverlay, runAsync, queryTimeout);
0056 }
0057 return new HiveCommandOperation(parentSession, statement, processor, confOverlay);
0058 }
0059
0060 protected void registerCurrentOperationLog() {
0061 if (isOperationLogEnabled) {
0062 if (operationLog == null) {
0063 LOG.warn("Failed to get current OperationLog object of Operation: " +
0064 getHandle().getHandleIdentifier());
0065 isOperationLogEnabled = false;
0066 return;
0067 }
0068 OperationLog.setCurrentOperationLog(operationLog);
0069 }
0070 }
0071 }