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.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       // runAsync, queryTimeout makes sense only for a SQLOperation
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 }