Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B1CCB200C63 for ; Wed, 26 Apr 2017 21:37:41 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AEB04160BA8; Wed, 26 Apr 2017 19:37:41 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0AA65160BB4 for ; Wed, 26 Apr 2017 21:37:40 +0200 (CEST) Received: (qmail 87694 invoked by uid 500); 26 Apr 2017 19:37:40 -0000 Mailing-List: contact commits-help@beam.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@beam.apache.org Delivered-To: mailing list commits@beam.apache.org Received: (qmail 87547 invoked by uid 99); 26 Apr 2017 19:37:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Apr 2017 19:37:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 773DFE110B; Wed, 26 Apr 2017 19:37:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dhalperi@apache.org To: commits@beam.apache.org Date: Wed, 26 Apr 2017 19:37:40 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/4] beam git commit: FileSystems: make tolerant of and more efficient for empty lists archived-at: Wed, 26 Apr 2017 19:37:41 -0000 FileSystems: make tolerant of and more efficient for empty lists Project: http://git-wip-us.apache.org/repos/asf/beam/repo Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/bdee44f1 Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/bdee44f1 Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/bdee44f1 Branch: refs/heads/master Commit: bdee44f1a675591b6a67883217e6669c5bb7b3b7 Parents: e07ba68 Author: Dan Halperin Authored: Tue Apr 25 20:48:23 2017 -0700 Committer: Dan Halperin Committed: Wed Apr 26 12:27:42 2017 -0700 ---------------------------------------------------------------------- .../org/apache/beam/sdk/io/FileSystems.java | 55 +++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/beam/blob/bdee44f1/sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java index aa247c3..0b50070 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java @@ -214,22 +214,22 @@ public class FileSystems { * @param destResourceIds the references of the destination resources */ public static void copy( - List srcResourceIds, - List destResourceIds, - MoveOptions... moveOptions) throws IOException { - validateOnlyScheme(srcResourceIds, destResourceIds); + List srcResourceIds, List destResourceIds, MoveOptions... moveOptions) + throws IOException { + validateSrcDestLists(srcResourceIds, destResourceIds); + if (srcResourceIds.isEmpty()) { + // Short-circuit. + return; + } - List srcToCopy; - List destToCopy; + List srcToCopy = srcResourceIds; + List destToCopy = destResourceIds; if (Sets.newHashSet(moveOptions).contains( MoveOptions.StandardMoveOptions.IGNORE_MISSING_FILES)) { KV, List> existings = filterMissingFiles(srcResourceIds, destResourceIds); srcToCopy = existings.getKey(); destToCopy = existings.getValue(); - } else { - srcToCopy = srcResourceIds; - destToCopy = destResourceIds; } if (srcToCopy.isEmpty()) { return; @@ -252,22 +252,22 @@ public class FileSystems { * @param destResourceIds the references of the destination resources */ public static void rename( - List srcResourceIds, - List destResourceIds, - MoveOptions... moveOptions) throws IOException { - validateOnlyScheme(srcResourceIds, destResourceIds); - List srcToRename; - List destToRename; + List srcResourceIds, List destResourceIds, MoveOptions... moveOptions) + throws IOException { + validateSrcDestLists(srcResourceIds, destResourceIds); + if (srcResourceIds.isEmpty()) { + // Short-circuit. + return; + } + List srcToRename = srcResourceIds; + List destToRename = destResourceIds; if (Sets.newHashSet(moveOptions).contains( MoveOptions.StandardMoveOptions.IGNORE_MISSING_FILES)) { KV, List> existings = filterMissingFiles(srcResourceIds, destResourceIds); srcToRename = existings.getKey(); destToRename = existings.getValue(); - } else { - srcToRename = srcResourceIds; - destToRename = destResourceIds; } if (srcToRename.isEmpty()) { return; @@ -288,6 +288,11 @@ public class FileSystems { */ public static void delete( Collection resourceIds, MoveOptions... moveOptions) throws IOException { + if (resourceIds.isEmpty()) { + // Short-circuit. + return; + } + Collection resourceIdsToDelete; if (Sets.newHashSet(moveOptions).contains( MoveOptions.StandardMoveOptions.IGNORE_MISSING_FILES)) { @@ -329,6 +334,12 @@ public class FileSystems { private static KV, List> filterMissingFiles( List srcResourceIds, List destResourceIds) throws IOException { + validateSrcDestLists(srcResourceIds, destResourceIds); + if (srcResourceIds.isEmpty()) { + // Short-circuit. + return KV.of(Collections.emptyList(), Collections.emptyList()); + } + List srcToHandle = new ArrayList<>(); List destToHandle = new ArrayList<>(); @@ -342,13 +353,19 @@ public class FileSystems { return KV.of(srcToHandle, destToHandle); } - private static void validateOnlyScheme( + private static void validateSrcDestLists( List srcResourceIds, List destResourceIds) { checkArgument( srcResourceIds.size() == destResourceIds.size(), "Number of source resource ids %s must equal number of destination resource ids %s", srcResourceIds.size(), destResourceIds.size()); + + if (srcResourceIds.isEmpty()) { + // nothing more to validate. + return; + } + Set schemes = FluentIterable.from(srcResourceIds) .append(destResourceIds) .transform(new Function() {