private Optional<Table> loadTable(HiveTableName hiveTableName) throws Exception { try { return retry() .stopOn(NoSuchObjectException.class, HiveViewNotSupportedException.class) .stopOnIllegalExceptions() .run( "getTable", stats .getGetTable() .wrap( () -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { Table table = client.getTable( hiveTableName.getDatabaseName(), hiveTableName.getTableName()); if (table.getTableType().equals(TableType.VIRTUAL_VIEW.name()) && (!isPrestoView(table))) { throw new HiveViewNotSupportedException( new SchemaTableName( hiveTableName.getDatabaseName(), hiveTableName.getTableName())); } return Optional.of(table); } })); } catch (NoSuchObjectException e) { return Optional.empty(); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } }
private Map<HivePartitionName, Optional<Partition>> loadPartitionsByNames( Iterable<? extends HivePartitionName> partitionNames) throws Exception { requireNonNull(partitionNames, "partitionNames is null"); checkArgument(!Iterables.isEmpty(partitionNames), "partitionNames is empty"); HivePartitionName firstPartition = Iterables.get(partitionNames, 0); HiveTableName hiveTableName = firstPartition.getHiveTableName(); String databaseName = hiveTableName.getDatabaseName(); String tableName = hiveTableName.getTableName(); List<String> partitionsToFetch = new ArrayList<>(); for (HivePartitionName partitionName : partitionNames) { checkArgument( partitionName.getHiveTableName().equals(hiveTableName), "Expected table name %s but got %s", hiveTableName, partitionName.getHiveTableName()); partitionsToFetch.add(partitionName.getPartitionName()); } List<String> partitionColumnNames = ImmutableList.copyOf( Warehouse.makeSpecFromName(firstPartition.getPartitionName()).keySet()); try { return retry() .stopOn(NoSuchObjectException.class) .stopOnIllegalExceptions() .run( "getPartitionsByNames", stats .getGetPartitionsByNames() .wrap( () -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { ImmutableMap.Builder<HivePartitionName, Optional<Partition>> partitions = ImmutableMap.builder(); for (Partition partition : client.getPartitionsByNames( databaseName, tableName, partitionsToFetch)) { String partitionId = FileUtils.makePartName( partitionColumnNames, partition.getValues(), null); partitions.put( HivePartitionName.partition(databaseName, tableName, partitionId), Optional.of(partition)); } return partitions.build(); } })); } catch (NoSuchObjectException e) { // assume none of the partitions in the batch are available return stream(partitionNames.spliterator(), false) .collect(toMap(identity(), (name) -> Optional.empty())); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } }
private Optional<List<String>> loadPartitionNames(HiveTableName hiveTableName) throws Exception { try { return retry() .stopOn(NoSuchObjectException.class) .stopOnIllegalExceptions() .run( "getPartitionNames", stats .getGetPartitionNames() .wrap( () -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { return Optional.of( client.getPartitionNames( hiveTableName.getDatabaseName(), hiveTableName.getTableName())); } })); } catch (NoSuchObjectException e) { return Optional.empty(); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } }
private void invalidatePartitionCache(String databaseName, String tableName) { HiveTableName hiveTableName = HiveTableName.table(databaseName, tableName); partitionNamesCache.invalidate(hiveTableName); partitionCache .asMap() .keySet() .stream() .filter(partitionName -> partitionName.getHiveTableName().equals(hiveTableName)) .forEach(partitionCache::invalidate); partitionFilterCache .asMap() .keySet() .stream() .filter(partitionFilter -> partitionFilter.getHiveTableName().equals(hiveTableName)) .forEach(partitionFilterCache::invalidate); }
@Override public Optional<List<String>> getPartitionNames(String databaseName, String tableName) { return get(partitionNamesCache, HiveTableName.table(databaseName, tableName)); }
@Override public Optional<Table> getTable(String databaseName, String tableName) { return get(tableCache, HiveTableName.table(databaseName, tableName)); }
public static PartitionFilter partitionFilter( String databaseName, String tableName, List<String> parts) { return new PartitionFilter(HiveTableName.table(databaseName, tableName), parts); }
public static HivePartitionName partition( String databaseName, String tableName, String partitionName) { return new HivePartitionName(HiveTableName.table(databaseName, tableName), partitionName); }