Index: ql/src/test/results/clientpositive/driverhook.q.out =================================================================== --- ql/src/test/results/clientpositive/driverhook.q.out (revision 0) +++ ql/src/test/results/clientpositive/driverhook.q.out (working copy) @@ -0,0 +1,21 @@ + + +-- This query should appear in the Hive CLI output. +-- We test DriverTestHook, which does exactly that. +-- This should not break. +SELECT * FROM src LIMIT 1 +PREHOOK: query: -- This query should appear in the Hive CLI output. +-- We test DriverTestHook, which does exactly that. +-- This should not break. +SELECT * FROM src LIMIT 1 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +#### A masked pattern was here #### +POSTHOOK: query: -- This query should appear in the Hive CLI output. +-- We test DriverTestHook, which does exactly that. +-- This should not break. +SELECT * FROM src LIMIT 1 +POSTHOOK: type: QUERY +POSTHOOK: Input: default@src +#### A masked pattern was here #### +238 val_238 Index: ql/src/test/queries/clientpositive/driverhook.q =================================================================== --- ql/src/test/queries/clientpositive/driverhook.q (revision 0) +++ ql/src/test/queries/clientpositive/driverhook.q (working copy) @@ -0,0 +1,6 @@ +SET hive.exec.driver.run.hooks=org.apache.hadoop.hive.ql.hooks.DriverTestHook; + +-- This query should appear in the Hive CLI output. +-- We test DriverTestHook, which does exactly that. +-- This should not break. +SELECT * FROM src LIMIT 1; Index: ql/src/java/org/apache/hadoop/hive/ql/hooks/DriverTestHook.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/hooks/DriverTestHook.java (revision 0) +++ ql/src/java/org/apache/hadoop/hive/ql/hooks/DriverTestHook.java (working copy) @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.ql.hooks; + +import java.io.PrintStream; + +import org.apache.hadoop.hive.ql.HiveDriverRunHook; +import org.apache.hadoop.hive.ql.HiveDriverRunHookContext; +import org.apache.hadoop.hive.ql.session.SessionState; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.conf.HiveConf; + +public class DriverTestHook implements HiveDriverRunHook { + + @Override + public void preDriverRun(HiveDriverRunHookContext hookContext) throws Exception { + SessionState sess = new SessionState((HiveConf)hookContext.getConf()); + PrintStream stream = sess.getConsole().getOutStream(); + stream.println(hookContext.getCommand()); + } + + @Override + public void postDriverRun(HiveDriverRunHookContext hookContext) throws Exception { + // do nothing + } +} Index: ql/src/java/org/apache/hadoop/hive/ql/HiveDriverRunHookContextImpl.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/HiveDriverRunHookContextImpl.java (revision 1377782) +++ ql/src/java/org/apache/hadoop/hive/ql/HiveDriverRunHookContextImpl.java (working copy) @@ -22,10 +22,12 @@ public class HiveDriverRunHookContextImpl implements HiveDriverRunHookContext { - Configuration conf; + private Configuration conf; + private String command; - public HiveDriverRunHookContextImpl(Configuration conf) { + public HiveDriverRunHookContextImpl(Configuration conf, String command) { this.conf = conf; + this.command = command; } @Override @@ -37,4 +39,14 @@ public void setConf(Configuration conf) { this.conf = conf; } + + @Override + public String getCommand() { + return command; + } + + @Override + public void setCommand(String command) { + this.command = command; + } } Index: ql/src/java/org/apache/hadoop/hive/ql/HiveDriverRunHookContext.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/HiveDriverRunHookContext.java (revision 1377782) +++ ql/src/java/org/apache/hadoop/hive/ql/HiveDriverRunHookContext.java (working copy) @@ -25,5 +25,6 @@ * HiveDriverRunHook. */ public interface HiveDriverRunHookContext extends Configurable{ - + public String getCommand(); + public void setCommand(String command); } Index: ql/src/java/org/apache/hadoop/hive/ql/Driver.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/Driver.java (revision 1377782) +++ ql/src/java/org/apache/hadoop/hive/ql/Driver.java (working copy) @@ -878,7 +878,7 @@ errorMessage = null; SQLState = null; - HiveDriverRunHookContext hookContext = new HiveDriverRunHookContextImpl(conf); + HiveDriverRunHookContext hookContext = new HiveDriverRunHookContextImpl(conf, command); // Get all the driver run hooks and pre-execute them. List driverRunHooks; try {