private void writeIntermediate(
      int groupId, boolean isX, TSDataType dataType, byte[] bytes, int offset) {
    switch (dataType) {
      case INT32:
      case DATE:
        if (isX) {
          intToBytes(xIntValues.get(groupId), bytes, offset);
        } else {
          intToBytes(yIntValues.get(groupId), bytes, offset);
        }
        break;
      case INT64:
      case TIMESTAMP:
        if (isX) {
          longToBytes(xLongValues.get(groupId), bytes, offset);
        } else {
          longToBytes(yLongValues.get(groupId), bytes, offset);
        }
        break;
      case FLOAT:
        if (isX) {
          floatToBytes(xFloatValues.get(groupId), bytes, offset);
        } else {
          floatToBytes(yFloatValues.get(groupId), bytes, offset);
        }
        break;
      case DOUBLE:
        if (isX) {
          doubleToBytes(xDoubleValues.get(groupId), bytes, offset);
        } else {
          doubleToBytes(yDoubleValues.get(groupId), bytes, offset);
        }
        break;
      case TEXT:
      case STRING:
      case BLOB:
        byte[] values =
            isX ? xBinaryValues.get(groupId).getValues() : yBinaryValues.get(groupId).getValues();
        intToBytes(values.length, bytes, offset);
        System.arraycopy(values, 0, bytes, offset + Integer.BYTES, values.length);
        break;
      case BOOLEAN:
        if (isX) {
          boolToBytes(yBooleanValues.get(groupId), bytes, offset);
        } else {
          boolToBytes(yBooleanValues.get(groupId), bytes, offset);
        }
        break;

      default:
        throw new UnSupportedDataTypeException(
            String.format("Unsupported data type in MAX_BY/MIN_BY Aggregation: %s", dataType));
    }
  }
max(x,y) returns the value of x associated with the maximum value of y over all input values.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/GroupedMaxMinByBaseAccumulator.java