Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
This is a follow-up Jira of the HIVE-18696 review.
The biggest part of these methods use the same code. It would make sense to move this code part to a common method.
This code is almost the same in the two methods:
List<Future<Partition>> partFutures = Lists.newArrayList(); final Table table = tbl; for (final Partition part : parts) { if (!part.getTableName().equals(tblName) || !part.getDbName().equals(dbName)) { throw new MetaException("Partition does not belong to target table " + dbName + "." + tblName + ": " + part); } boolean shouldAdd = startAddPartition(ms, part, ifNotExists); if (!shouldAdd) { existingParts.add(part); LOG.info("Not adding partition " + part + " as it already exists"); continue; } final UserGroupInformation ugi; try { ugi = UserGroupInformation.getCurrentUser(); } catch (IOException e) { throw new RuntimeException(e); } partFutures.add(threadPool.submit(new Callable<Partition>() { @Override public Partition call() throws Exception { ugi.doAs(new PrivilegedExceptionAction<Object>() { @Override public Object run() throws Exception { try { boolean madeDir = createLocationForAddedPartition(table, part); if (addedPartitions.put(new PartValEqWrapper(part), madeDir) != null) { // Technically, for ifNotExists case, we could insert one and discard the other // because the first one now "exists", but it seems better to report the problem // upstream as such a command doesn't make sense. throw new MetaException("Duplicate partitions in the list: " + part); } initializeAddedPartition(table, part, madeDir); } catch (MetaException e) { throw new IOException(e.getMessage(), e); } return null; } }); return part; } })); } try { for (Future<Partition> partFuture : partFutures) { Partition part = partFuture.get(); if (part != null) { newParts.add(part); } } } catch (InterruptedException | ExecutionException e) { // cancel other tasks for (Future<Partition> partFuture : partFutures) { partFuture.cancel(true); } throw new MetaException(e.getMessage()); }