private static ColumnarRow toColumnarRow(DictionaryBlock dictionaryBlock) { // build a mapping from the old dictionary to a new dictionary with nulls removed Block dictionary = dictionaryBlock.getDictionary(); int[] newDictionaryIndex = new int[dictionary.getPositionCount()]; int nextNewDictionaryIndex = 0; for (int position = 0; position < dictionary.getPositionCount(); position++) { if (!dictionary.isNull(position)) { newDictionaryIndex[position] = nextNewDictionaryIndex; nextNewDictionaryIndex++; } } // reindex the dictionary int[] dictionaryIds = new int[dictionaryBlock.getPositionCount()]; int nonNullPositionCount = 0; for (int position = 0; position < dictionaryBlock.getPositionCount(); position++) { if (!dictionaryBlock.isNull(position)) { int oldDictionaryId = dictionaryBlock.getId(position); dictionaryIds[nonNullPositionCount] = newDictionaryIndex[oldDictionaryId]; nonNullPositionCount++; } } ColumnarRow columnarRow = toColumnarRow(dictionaryBlock.getDictionary()); Block[] fields = new Block[columnarRow.getFieldCount()]; for (int i = 0; i < columnarRow.getFieldCount(); i++) { fields[i] = new DictionaryBlock(nonNullPositionCount, columnarRow.getField(i), dictionaryIds); } return new ColumnarRow(dictionaryBlock, fields); }
private static ColumnarRow toColumnarRow(DictionaryBlock dictionaryBlock) { // build a mapping from the old dictionary to a new dictionary with nulls removed Block dictionary = dictionaryBlock.getDictionary(); int[] newDictionaryIndex = new int[dictionary.getPositionCount()]; int nextNewDictionaryIndex = 0; for (int position = 0; position < dictionary.getPositionCount(); position++) { if (!dictionary.isNull(position)) { newDictionaryIndex[position] = nextNewDictionaryIndex; nextNewDictionaryIndex++; } } // reindex the dictionary int[] dictionaryIds = new int[dictionaryBlock.getPositionCount()]; int nonNullPositionCount = 0; for (int position = 0; position < dictionaryBlock.getPositionCount(); position++) { if (!dictionaryBlock.isNull(position)) { int oldDictionaryId = dictionaryBlock.getId(position); dictionaryIds[nonNullPositionCount] = newDictionaryIndex[oldDictionaryId]; nonNullPositionCount++; } } ColumnarRow columnarRow = toColumnarRow(dictionaryBlock.getDictionary()); Block[] fields = new Block[columnarRow.getFieldCount()]; for (int i = 0; i < columnarRow.getFieldCount(); i++) { fields[i] = new DictionaryBlock(nonNullPositionCount, columnarRow.getField(i), dictionaryIds); } return new ColumnarRow(dictionaryBlock, fields); }