Program: 112044
Project: 112044
Buggy source:
@Test public void testBinaryDictionaryInefficiency() throws IOException {
  int COUNT=40000;
  ValuesWriter cw=new PlainBinaryDictionaryValuesWriter(2000000,10000);
  for (int i=0; i < COUNT; i++) {
    cw.writeBytes(Binary.fromString("String_Node_Str" + i));
  }
  final BytesInput bytes1=BytesInput.copy(cw.getBytes());
  final Encoding encoding1=cw.getEncoding();
  System.out.println(PrimitiveTypeName.BINARY.name() + "String_Node_Str" + encoding1+ "String_Node_Str"+ bytes1.size());
  cw.reset();
  for (int i=0; i < COUNT; i++) {
    cw.writeBytes(Binary.fromString("String_Node_Str" + i));
  }
  final BytesInput bytes2=BytesInput.copy(cw.getBytes());
  final Encoding encoding2=cw.getEncoding();
  System.out.println(PrimitiveTypeName.BINARY.name() + "String_Node_Str" + encoding2+ "String_Node_Str"+ bytes2.size());
  cw.reset();
  final DictionaryPage dictionaryPage=cw.createDictionaryPage();
  Dictionary dictionary=null;
  long dictPageSize=0;
  ValuesReader cr;
  if (dictionaryPage != null) {
    dictPageSize=dictionaryPage.getBytes().size();
    System.out.println(PrimitiveTypeName.BINARY.name() + "String_Node_Str" + dictPageSize);
    final ColumnDescriptor descriptor=new ColumnDescriptor(new String[]{"String_Node_Str"},PrimitiveTypeName.BINARY,0,0);
    dictionary=Encoding.PLAIN_DICTIONARY.initDictionary(descriptor,dictionaryPage);
    cr=new DictionaryValuesReader(dictionary);
  }
 else {
    cr=new BinaryPlainValuesReader();
  }
  cr.initFromPage(COUNT,bytes1.toByteArray(),0);
  for (int i=0; i < COUNT; i++) {
    final String str=cr.readBytes().toStringUsingUTF8();
    Assert.assertEquals("String_Node_Str" + i,str);
  }
  if (dictionary != null && encoding2 == Encoding.PLAIN_DICTIONARY) {
    cr=new DictionaryValuesReader(dictionary);
  }
 else {
    cr=new BinaryPlainValuesReader();
  }
  cr.initFromPage(COUNT,bytes2.toByteArray(),0);
  for (int i=0; i < COUNT; i++) {
    final String str=cr.readBytes().toStringUsingUTF8();
    Assert.assertEquals("String_Node_Str" + i,str);
  }
  assertTrue("String_Node_Str",bytes1.size() < bytes2.size());
  assertEquals("String_Node_Str",dictPageSize,bytes2.size());
}

Fixed version (ground truth):
@Test public void testBinaryDictionaryInefficiency() throws IOException {
  int COUNT=40000;
  ValuesWriter cw=new PlainBinaryDictionaryValuesWriter(500000,10000);
  for (int i=0; i < COUNT; i++) {
    cw.writeBytes(Binary.fromString("String_Node_Str" + i));
  }
  final BytesInput bytes1=BytesInput.copy(cw.getBytes());
  final Encoding encoding1=cw.getEncoding();
  System.out.println(PrimitiveTypeName.BINARY.name() + "String_Node_Str" + encoding1+ "String_Node_Str"+ bytes1.size());
  cw.reset();
  for (int i=0; i < COUNT; i++) {
    cw.writeBytes(Binary.fromString("String_Node_Str" + i));
  }
  final BytesInput bytes2=BytesInput.copy(cw.getBytes());
  final Encoding encoding2=cw.getEncoding();
  System.out.println(PrimitiveTypeName.BINARY.name() + "String_Node_Str" + encoding2+ "String_Node_Str"+ bytes2.size());
  cw.reset();
  final DictionaryPage dictionaryPage=cw.createDictionaryPage();
  Dictionary dictionary=null;
  long dictPageSize=0;
  ValuesReader cr;
  if (dictionaryPage != null) {
    dictPageSize=dictionaryPage.getBytes().size();
    System.out.println(PrimitiveTypeName.BINARY.name() + "String_Node_Str" + dictPageSize);
    final ColumnDescriptor descriptor=new ColumnDescriptor(new String[]{"String_Node_Str"},PrimitiveTypeName.BINARY,0,0);
    dictionary=Encoding.PLAIN_DICTIONARY.initDictionary(descriptor,dictionaryPage);
    cr=new DictionaryValuesReader(dictionary);
  }
 else {
    cr=new BinaryPlainValuesReader();
  }
  cr.initFromPage(COUNT,bytes1.toByteArray(),0);
  for (int i=0; i < COUNT; i++) {
    final String str=cr.readBytes().toStringUsingUTF8();
    Assert.assertEquals("String_Node_Str" + i,str);
  }
  if (dictionary != null && encoding2 == Encoding.PLAIN_DICTIONARY) {
    cr=new DictionaryValuesReader(dictionary);
  }
 else {
    cr=new BinaryPlainValuesReader();
  }
  cr.initFromPage(COUNT,bytes2.toByteArray(),0);
  for (int i=0; i < COUNT; i++) {
    final String str=cr.readBytes().toStringUsingUTF8();
    Assert.assertEquals("String_Node_Str" + i,str);
  }
  assertTrue("String_Node_Str",bytes1.size() < bytes2.size());
  assertEquals("String_Node_Str",dictPageSize,bytes2.size());
}