public static Row decorateRowWithNeededHeadFields(
            @Nullable String timeFieldName,
            @Nullable String attributesFieldName,
            Timestamp time,
            Map<String, String> attributes,
            Row dataRow) {
        List<Object> headFields = new ArrayList<>(2);
        if (timeFieldName != null) {
            headFields.add(time);
        }

        if (attributesFieldName != null) {
            headFields.add(attributes);
        }

        Row row = new Row(headFields.size() + dataRow.getArity());
        for (int i = 0; i < headFields.size(); ++i) {
            row.setField(i, headFields.get(i));
        }

        for (int i = 0; i < dataRow.getArity(); ++i) {
            row.setField(i + headFields.size(), dataRow.getField(i));
        }

        return row;
    }
Creates the row with the given head fields and data row.

@param timeFieldName The name of the time field. Null if the time field is not required.
@param attributesFieldName The name of the attributes field. Null if the attributes field is
                           not required.
@param time The time of the InLongMsg.
@param attributes The attributes of the InLongMsg.
@param dataRow The data row.
@return The row decorated with head fields.
inlong-sort/sort-formats/format-row/format-inlongmsg-base/src/main/java/org/apache/inlong/sort/formats/inlongmsg/row/InLongMsgUtils.java