public static List<DwrfProto.ColumnEncoding> toColumnEncodings(Map<Integer, ColumnEncoding> columnEncodingsByNodeId)
    {
        ImmutableList.Builder<DwrfProto.ColumnEncoding> columnEncodings = ImmutableList.builder();
        for (Entry<Integer, ColumnEncoding> entry : columnEncodingsByNodeId.entrySet()) {
            int nodeId = entry.getKey();
            ColumnEncoding columnEncoding = entry.getValue();

            if (columnEncoding.getAdditionalSequenceEncodings().isPresent()) {
                Map<Integer, DwrfSequenceEncoding> sequences = columnEncoding.getAdditionalSequenceEncodings().get();
                for (Entry<Integer, DwrfSequenceEncoding> sequenceEntry : sequences.entrySet()) {
                    int sequence = sequenceEntry.getKey();
                    DwrfSequenceEncoding sequenceEncoding = sequenceEntry.getValue();
                    columnEncodings.add(toColumnEncoding(nodeId, sequence, sequenceEncoding));
                }
            }
            else {
                columnEncodings.add(toColumnEncoding(nodeId, columnEncoding));
            }
        }
        return columnEncodings.build();
    }
@Test
    public void testToColumnEncodingsWithInvalidDeeplyNestedAdditionalSequence()
    {
        DwrfProto.KeyInfo key1 = DwrfProto.KeyInfo.newBuilder().setIntKey(1).build();
        DwrfProto.KeyInfo key2 = DwrfProto.KeyInfo.newBuilder().setIntKey(2).build();

        // level 2
        ColumnEncoding deeplyNestedValueEncoding = new ColumnEncoding(DIRECT, 0);
        DwrfSequenceEncoding deeplyNestedSequenceEncoding = new DwrfSequenceEncoding(key1, deeplyNestedValueEncoding);
        ImmutableSortedMap<Integer, DwrfSequenceEncoding> deeplyNestedSequenceEncodings = ImmutableSortedMap.of(0, deeplyNestedSequenceEncoding);

        // level 1
        ColumnEncoding nestedColumnEncoding = new ColumnEncoding(DIRECT, 0, Optional.of(deeplyNestedSequenceEncodings));
        DwrfSequenceEncoding nestedSequenceEncoding = new DwrfSequenceEncoding(key2, nestedColumnEncoding);
        ImmutableSortedMap<Integer, DwrfSequenceEncoding> nestedSequenceEncodings = ImmutableSortedMap.of(0, nestedSequenceEncoding);

        // root
        ColumnEncoding columnEncoding = new ColumnEncoding(DIRECT, 0, Optional.of(nestedSequenceEncodings));

        expectThrows(IllegalArgumentException.class, () -> toColumnEncodings(ImmutableMap.of(COLUMN_ID, columnEncoding)));
    }