private static List<String> listAllDataPaths(
      HiveMetastore metastore, String schemaName, String tableName) {
    ImmutableList.Builder<String> locations = ImmutableList.builder();
    Table table = metastore.getTable(schemaName, tableName).get();
    if (table.getSd().getLocation() != null) {
      // For unpartitioned table, there should be nothing directly under this directory.
      // But including this location in the set makes the directory content assert more
      // extensive, which is desirable.
      locations.add(table.getSd().getLocation());
    }

    Optional<List<String>> partitionNames = metastore.getPartitionNames(schemaName, tableName);
    if (partitionNames.isPresent()) {
      metastore
          .getPartitionsByNames(schemaName, tableName, partitionNames.get())
          .stream()
          .map(partition -> partition.getSd().getLocation())
          .filter(location -> !location.startsWith(table.getSd().getLocation()))
          .forEach(locations::add);
    }

    return locations.build();
  }