.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,
return client.getAllTables(databaseName); client.getDatabase(databaseName); return null;
@Override public void dropTable(String databaseName, String tableName) { try { Optional<Table> table = getTable(databaseName, tableName); if (!table.isPresent()) { throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); } // hack to work around the metastore not being configured for S3 List<String> locations = listAllDataPaths(this, databaseName, tableName); table.get().getSd().setLocation("/"); // drop table try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { client.alterTable(databaseName, tableName, table.get()); client.dropTable(databaseName, tableName, false); } // drop data for (String location : locations) { Path path = new Path(location); hdfsEnvironment.getFileSystem(path).delete(path, true); } } catch (Exception e) { throw Throwables.propagate(e); } finally { invalidateTable(databaseName, tableName); } }
public void updateTableLocation(String databaseName, String tableName, String location) { try { Optional<Table> table = getTable(databaseName, tableName); if (!table.isPresent()) { throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); } table.get().getSd().setLocation(location); try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { client.alterTable(databaseName, tableName, table.get()); } } catch (TException e) { throw Throwables.propagate(e); } } }
@Override public void dropTable(String databaseName, String tableName) { try { retry() .stopOn(NoSuchObjectException.class) .stopOnIllegalExceptions() .run("dropTable", stats.getDropTable().wrap(() -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { client.dropTable(databaseName, tableName, true); } return null; })); } 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 { invalidateTable(databaseName, tableName); } }
private Optional<Database> loadDatabase(String databaseName) throws Exception { try { return retry() .stopOn(NoSuchObjectException.class) .stopOnIllegalExceptions() .run("getDatabase", stats.getGetDatabase().wrap(() -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { return Optional.of(client.getDatabase(databaseName)); } })); } catch (NoSuchObjectException e) { return Optional.empty(); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } }
private List<String> loadAllDatabases() throws Exception { try { return retry() .stopOnIllegalExceptions() .run("getAllDatabases", stats.getGetAllDatabases().wrap(() -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { return client.getAllDatabases(); } })); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } }
private Optional<Partition> loadPartitionByName(HivePartitionName partitionName) throws Exception { requireNonNull(partitionName, "partitionName is null"); try { return retry() .stopOn(NoSuchObjectException.class) .stopOnIllegalExceptions() .run("getPartitionsByNames", stats.getGetPartitionByName().wrap(() -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { return Optional.of(client.getPartitionByName( partitionName.getHiveTableName().getDatabaseName(), partitionName.getHiveTableName().getTableName(), partitionName.getPartitionName())); } })); } catch (NoSuchObjectException e) { return Optional.empty(); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } }
@Override public void dropPartition(String databaseName, String tableName, List<String> parts) { try { retry() .stopOn(NoSuchObjectException.class, MetaException.class) .stopOnIllegalExceptions() .run("dropPartition", stats.getDropPartition().wrap(() -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { client.dropPartition(databaseName, tableName, parts, true); } return null; })); } 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 { invalidatePartitionCache(databaseName, tableName); } }
client.dropPartitionByName(databaseName, tableName, partitionName, true);
.run("createTable", stats.getCreateTable().wrap(() -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { client.createTable(table);
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); client.alterTable(databaseName, tableName, table);