Index: common/src/java/org/apache/hadoop/hive/conf/HiveConf.java =================================================================== --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (revision 1055171) +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (working copy) @@ -157,15 +157,20 @@ METASTORE_KERBEROS_KEYTAB_FILE("hive.metastore.kerberos.keytab.file", ""), METASTORE_KERBEROS_PRINCIPAL("hive.metastore.kerberos.principal", ""), METASTORE_USE_THRIFT_SASL("hive.metastore.sasl.enabled", false), - + // Default parameters for creating tables NEWTABLEDEFAULTPARA("hive.table.parameters.default",""), // CLI CLIIGNOREERRORS("hive.cli.errors.ignore", false), + + //which api should be used to do the delete, FileSystem.delete or FsShell.delete? + HIVE_WAREHOUSE_DELETE_USING_FSSHELL("hive.warehouse.delete.using.fsshell", false), + //extra args after the "FsShell -rmr" + HIVE_WAREHOUSE_DELETE_FSSHELL_ARGS("hive.warehouse.delete.fsshell.args", ""), // Things we log in the jobconf - + // session identifier HIVESESSIONID("hive.session.id", ""), // whether session is running in silent mode or not Index: common/src/java/org/apache/hadoop/hive/conf/SessionConfStore.java =================================================================== --- common/src/java/org/apache/hadoop/hive/conf/SessionConfStore.java (revision 0) +++ common/src/java/org/apache/hadoop/hive/conf/SessionConfStore.java (revision 0) @@ -0,0 +1,38 @@ +/** + * 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.conf; + +import org.apache.hadoop.conf.Configuration; + +public class SessionConfStore { + + private static ThreadLocal threadLocalConf = new ThreadLocal(); + + private SessionConfStore() { + } + + public static Configuration getConf() { + return threadLocalConf.get(); + } + + public static void setConf(Configuration conf) { + threadLocalConf.set(conf); + } + +} Index: conf/hive-default.xml =================================================================== --- conf/hive-default.xml (revision 1055171) +++ conf/hive-default.xml (working copy) @@ -217,6 +217,19 @@ + hive.warehouse.delete.using.fsshell + false + which api should be used to do the delete. + If false, then use FileSystem.delete, and if true then use FsShell.delete + + + + hive.warehouse.delete.fsshell.args + + The extra args that need to pass to FsShell -rmr + + + hive.default.fileformat TextFile Default file format for CREATE TABLE statement. Options are TextFile and SequenceFile. Users can explicitly say CREATE TABLE ... STORED AS <TEXTFILE|SEQUENCEFILE> to override Index: metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java (revision 1055171) +++ metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java (working copy) @@ -36,10 +36,12 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Trash; import org.apache.hadoop.hive.common.FileUtils; import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.conf.SessionConfStore; import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.MetaException; @@ -165,16 +167,39 @@ LOG.info("Moved to trash: " + f); return true; } - if (fs.delete(f, true)) { - LOG.info("Deleted the diretory " + f); - return true; + + Configuration newConf = conf; + if (SessionConfStore.getConf() != null) { + newConf = SessionConfStore.getConf(); } + if (HiveConf.getBoolVar(newConf, HiveConf.ConfVars.HIVE_WAREHOUSE_DELETE_USING_FSSHELL)) { + FsShell fshell = new FsShell (newConf); + String argStr = HiveConf.getVar(newConf, HiveConf.ConfVars.HIVE_WAREHOUSE_DELETE_FSSHELL_ARGS); + List args = new ArrayList(); + args.add("-rmr"); + if (argStr != null && !argStr.trim().equals("")) { + String[] argArray = argStr.split(" "); + for (String arg : argArray) { + if (arg != null && !arg.trim().equals("")) { + args.add(arg); + } + } + } + args.add(f.toUri().toString()); + fshell.run(args.toArray(new String[args.size()])); + } else { + if (fs.delete(f, true)) { + LOG.info("Deleted the diretory " + f); + return true; + } + } + if (fs.exists(f)) { throw new MetaException("Unable to delete directory: " + f); } } catch (FileNotFoundException e) { return true; // ok even if there is not data - } catch (IOException e) { + } catch (Exception e) { closeFs(fs); MetaStoreUtils.logAndThrowMetaException(e); } Index: ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java (revision 1055171) +++ ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java (working copy) @@ -38,6 +38,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.conf.SessionConfStore; import org.apache.hadoop.hive.ql.exec.Utilities; import org.apache.hadoop.hive.ql.history.HiveHistory; import org.apache.hadoop.hive.ql.util.DosToUnix; @@ -155,6 +156,7 @@ SessionState ss = new SessionState(conf); ss.getConf().setVar(HiveConf.ConfVars.HIVESESSIONID, makeSessionId()); ss.hiveHist = new HiveHistory(ss); + SessionConfStore.setConf(ss.getConf()); tss.set(ss); return (ss); } @@ -165,14 +167,15 @@ * when switching from one session to another. */ public static SessionState start(SessionState startSs) { - + + SessionConfStore.setConf(startSs.getConf()); tss.set(startSs); if (StringUtils.isEmpty(startSs.getConf().getVar( HiveConf.ConfVars.HIVESESSIONID))) { startSs.getConf() .setVar(HiveConf.ConfVars.HIVESESSIONID, makeSessionId()); } - + if (startSs.hiveHist == null) { startSs.hiveHist = new HiveHistory(startSs); }