presto-rcfile/src/main/java/io/prestosql/rcfile/RcFileWriter.java/RcFileWriter/writeRowGroup
class RcFileWriter:    private void writeRowGroup()
            throws IOException
    {
        if (bufferedRows == 0) {
            return;
        }

        // write sync sequence for every row group except for the first row group
        if (totalRowCount != 0) {
            output.writeInt(-1);
            output.writeLong(syncFirst);
            output.writeLong(syncSecond);
        }

        // flush and compress each column
        for (ColumnEncoder columnEncoder : columnEncoders) {
            columnEncoder.closeColumn();
        }

        // build key section
        int valueLength = 0;
        keySectionOutput = keySectionOutput.createRecycledCompressedSliceOutput();
        try {
            writeVInt(keySectionOutput, bufferedRows);
            recordValidation(validation -> validation.addRowGroup(bufferedRows));
            for (ColumnEncoder columnEncoder : columnEncoders) {
                valueLength += columnEncoder.getCompressedSize();
                writeVInt(keySectionOutput, columnEncoder.getCompressedSize());
                writeVInt(keySectionOutput, columnEncoder.getUncompressedSize());

                Slice lengthData = columnEncoder.getLengthData();
                writeVInt(keySectionOutput, lengthData.length());
                keySectionOutput.writeBytes(lengthData);
            }
        }
        finally {
            keySectionOutput.close();
        }

        // write the sum of the uncompressed key length and compressed value length
        // this number is useless to the reader
        output.writeInt(Integer.reverseBytes(keySectionOutput.size() + valueLength));

        // write key section
        output.writeInt(Integer.reverseBytes(keySectionOutput.size()));
        output.writeInt(Integer.reverseBytes(keySectionOutput.getCompressedSize()));
        for (Slice slice : keySectionOutput.getCompressedSlices()) {
            output.writeBytes(slice);
        }

        // write value section
        for (ColumnEncoder columnEncoder : columnEncoders) {
            List<Slice> slices = columnEncoder.getCompressedData();
            for (Slice slice : slices) {
                output.writeBytes(slice);
            }
            columnEncoder.reset();
        }

        totalRowCount += bufferedRows;
        bufferedSize = 0;
        bufferedRows = 0;
    }