public void validate(List<Path> parts,PartitionerType partitionerType,int numShards) throws IOException {
  boolean hasNonEmptyPartition=false;
  HColumnDescriptor columnDescriptor=new HColumnDescriptor();
  columnDescriptor.setBlockCacheEnabled(false);
  for (int shardIndex=0; shardIndex < parts.size(); shardIndex++) {
    Path fileToBeValidated=parts.get(shardIndex);
    HFile.Reader reader=null;
    try {
      FileSystem fs=FileSystem.newInstance(fileToBeValidated.toUri(),conf);
      CacheConfig cc=new CacheConfig(conf,columnDescriptor);
      reader=HFile.createReader(fs,fileToBeValidated,cc);
      Partitioner partitioner=PartitionerFactory.getPartitioner(partitionerType);
      byte[] rowKey=reader.getFirstRowKey();
      if (rowKey == null) {
        LOG.warn(String.format("empty partition %s",fileToBeValidated.toString()));
        reader.close();
        continue;
      }
      hasNonEmptyPartition=true;
      BytesWritable key=new BytesWritable(rowKey);
      int partition=partitioner.getPartition(key,null,numShards);
      if (partition != shardIndex) {
        throw new IllegalArgumentException(String.format("wrong partition type %s for key %s in partition %d, expected %d",partitionerType.toString(),new String(key.getBytes()),shardIndex,partition));
      }
    }
  finally {
      if (reader != null) {
        reader.close();
      }
    }
  }
  if (!hasNonEmptyPartition) {
    throw new IllegalArgumentException("all partitions are empty");
  }
}

public void validate ( List < Path > parts , PartitionerType partitionerType , int numShards ) throws IOException { boolean hasNonEmptyPartition = false ; HColumnDescriptor columnDescriptor = new HColumnDescriptor ( ) ; columnDescriptor . setBlockCacheEnabled ( false ) ; for ( int shardIndex = 0 ; shardIndex < parts . size ( ) ; shardIndex ++ ) { Path fileToBeValidated = parts . get ( shardIndex ) ; HFile . Reader reader = null ; try { FileSystem fs = FileSystem . newInstance ( fileToBeValidated . toUri ( ) , conf ) ; CacheConfig cc = new CacheConfig ( conf , columnDescriptor ) ; reader = HFile . createReader ( fs , fileToBeValidated , cc ) ; Partitioner partitioner = PartitionerFactory . getPartitioner ( partitionerType ) ; byte [ ] rowKey = reader . getFirstRowKey ( ) ; if ( rowKey == null ) { LOG . warn ( String . format ( "empty partition %s" , fileToBeValidated . toString ( ) ) ) ; reader . close ( ) ; continue ; } hasNonEmptyPartition = true ; BytesWritable key = new BytesWritable ( rowKey ) ; int partition = partitioner . getPartition ( key , null , numShards ) ; if ( partition != shardIndex ) { throw new IllegalArgumentException ( String . format ( "wrong partition type %s for key %s in partition %d, expected %d" , partitionerType . toString ( ) , new String ( key . getBytes ( ) ) , shardIndex , partition ) ) ; } } finally { if ( reader != null ) { reader . close ( ) ; } } } if ( ! hasNonEmptyPartition ) { throw new IllegalArgumentException ( "all partitions are empty" ) ; } }
validates the first non - empty partition hfile has right partitioning function . it reads several keys , then calculates the partition according to the partitioning function client offering . if the calculated partition number is different with actual partition number an exception is thrown . if all partition hfiles are empty , an exception is thrown .
