Return-Path: X-Original-To: apmail-hive-commits-archive@www.apache.org Delivered-To: apmail-hive-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5EC5C17C5F for ; Fri, 9 Jan 2015 07:07:28 +0000 (UTC) Received: (qmail 89334 invoked by uid 500); 9 Jan 2015 07:07:29 -0000 Delivered-To: apmail-hive-commits-archive@hive.apache.org Received: (qmail 89288 invoked by uid 500); 9 Jan 2015 07:07:29 -0000 Mailing-List: contact commits-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hive-dev@hive.apache.org Delivered-To: mailing list commits@hive.apache.org Received: (qmail 89275 invoked by uid 99); 9 Jan 2015 07:07:29 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Jan 2015 07:07:29 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 2C0D6AC0143; Fri, 9 Jan 2015 07:07:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1650451 - /hive/branches/HIVE-8065/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java Date: Fri, 09 Jan 2015 07:07:25 -0000 To: commits@hive.apache.org From: brock@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150109070728.2C0D6AC0143@hades.apache.org> Author: brock Date: Fri Jan 9 07:07:24 2015 New Revision: 1650451 URL: http://svn.apache.org/r1650451 Log: HIVE-9325 - Handle the case of insert overwrite statement with a qualified path that the destination path does not have a schema (Ferdinand Xu via Brock) Modified: hive/branches/HIVE-8065/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java Modified: hive/branches/HIVE-8065/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java URL: http://svn.apache.org/viewvc/hive/branches/HIVE-8065/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java?rev=1650451&r1=1650450&r2=1650451&view=diff ============================================================================== --- hive/branches/HIVE-8065/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java (original) +++ hive/branches/HIVE-8065/ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java Fri Jan 9 07:07:24 2015 @@ -2359,17 +2359,47 @@ private void constructOneLBLocationMap(F return false; } - private static boolean isSubDir(Path srcf, Path destf, FileSystem fs){ + private static boolean isSubDir(Path srcf, Path destf, FileSystem fs, boolean isSrcLocal){ if (srcf == null) { return false; } - Path currentWorkingDir = fs.getWorkingDirectory(); - String fullF1 = srcf.makeQualified(srcf.toUri(), currentWorkingDir).toString(); - String fullF2 = destf.makeQualified(destf.toUri(), currentWorkingDir).toString(); - LOG.debug("The source path is " + fullF1 + " and destination path is " + fullF2); + + // schema is diff, return false + String schemaSrcf = srcf.toUri().getScheme(); + String schemaDestf = destf.toUri().getScheme(); + + String fullF1 = getQualifiedPathWithoutSchemeAndAuthority(srcf, fs); + String fullF2 = getQualifiedPathWithoutSchemeAndAuthority(srcf, fs); + + boolean isInTest = Boolean.valueOf(HiveConf.getBoolVar(fs.getConf(), ConfVars.HIVE_IN_TEST)); + // In the automation, the data warehouse is the local file system based. + if (isInTest) { + return fullF1.startsWith(fullF2); + } + + // if the schemaDestf is null, it means the destination is not in the local file system + if (schemaDestf == null && isSrcLocal) { + LOG.debug("The source file is in the local while the dest not."); + return false; + } + + // If both schema information are provided, they should be the same. + if (schemaSrcf != null && schemaDestf != null && !schemaSrcf.equals(schemaDestf)) { + LOG.debug("The source path's schema is " + schemaSrcf + + " and the destination path's schema is " + schemaDestf + "."); + return false; + } + + LOG.debug("The source path is " + fullF1 + " and the destination path is " + fullF2); return fullF1.startsWith(fullF2); } + private static String getQualifiedPathWithoutSchemeAndAuthority(Path srcf, FileSystem fs) { + Path currentWorkingDir = fs.getWorkingDirectory(); + Path path = Path.getPathWithoutSchemeAndAuthority(srcf); + return path.makeQualified(path.toUri(), currentWorkingDir).toString(); + } + //it is assumed that parent directory of the destf should already exist when this //method is called. when the replace value is true, this method works a little different //from mv command if the destf is a directory, it replaces the destf instead of moving under @@ -2391,7 +2421,7 @@ private void constructOneLBLocationMap(F // (1) Do not delete the dest dir before doing the move operation. // (2) It is assumed that subdir and dir are in same encryption zone. // (3) Move individual files from scr dir to dest dir. - boolean destIsSubDir = isSubDir(srcf, destf, fs); + boolean destIsSubDir = isSubDir(srcf, destf, fs, isSrcLocal); try { if (inheritPerms || replace) { try{ @@ -2402,6 +2432,7 @@ private void constructOneLBLocationMap(F //if destf is an existing file, rename is actually a replace, and do not need // to delete the file first if (replace && !destIsSubDir) { + LOG.debug("===== xc ===== The path " + destf.toString() + " is deleted"); fs.delete(destf, true); } } catch (FileNotFoundException ignore) {