Back to home page

OSCL-LXR

 
 

    


0001 /**
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements.  See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership.  The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License.  You may obtain a copy of the License at
0009  *
0010  *     http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing, software
0013  * distributed under the License is distributed on an "AS IS" BASIS,
0014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015  * See the License for the specific language governing permissions and
0016  * limitations under the License.
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 }