@Override public void addPartitions(String databaseName, String tableName, List<Partition> partitions) { if (partitions.isEmpty()) { return; } try { retry() .stopOn( AlreadyExistsException.class, InvalidObjectException.class, MetaException.class, NoSuchObjectException.class, PrestoException.class) .stopOnIllegalExceptions() .run( "addPartitions", stats .getAddPartitions() .wrap( () -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { int partitionsAdded = client.addPartitions(partitions); if (partitionsAdded != partitions.size()) { throw new PrestoException( HIVE_METASTORE_ERROR, format( "Hive metastore only added %s of %s partitions", partitionsAdded, partitions.size())); } return null; } })); } catch (AlreadyExistsException e) { // todo partition already exists exception throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); } catch (NoSuchObjectException e) { throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } catch (Exception e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } throw Throwables.propagate(e); } finally { // todo do we need to invalidate all partitions? invalidatePartitionCache(databaseName, tableName); } }