public int write()

in java/tsfile/src/main/java/org/apache/tsfile/write/chunk/AlignedChunkGroupWriterImpl.java [214:304]


  public int write(Tablet tablet, int startRowIndex, int endRowIndex)
      throws WriteProcessException, IOException {
    int pointCount = 0;
    List<IMeasurementSchema> measurementSchemas = tablet.getSchemas();
    List<ValueChunkWriter> emptyValueChunkWriters = new ArrayList<>();
    // TODO: should we allow duplicated measurements in a Tablet?
    Set<String> existingMeasurements =
        measurementSchemas.stream()
            .map(
                schema ->
                    convertColumnNameToLowerCase
                        ? schema.getMeasurementName().toLowerCase()
                        : schema.getMeasurementName())
            .collect(Collectors.toSet());
    for (Map.Entry<String, ValueChunkWriter> entry : valueChunkWriterMap.entrySet()) {
      if (!existingMeasurements.contains(entry.getKey())) {
        emptyValueChunkWriters.add(entry.getValue());
      }
    }
    // TODO: changing to a column-first style by calculating the remaining page space of each
    // column firsts
    for (int row = startRowIndex; row < endRowIndex; row++) {
      long time = tablet.getTimestamps()[row];
      checkIsHistoryData(time);
      for (int columnIndex = 0; columnIndex < tablet.getSchemas().size(); columnIndex++) {
        if (tablet.getColumnTypes() != null
            && tablet.getColumnTypes().get(columnIndex) != ColumnCategory.FIELD) {
          continue;
        }

        boolean isNull =
            tablet.getBitMaps() != null
                && tablet.getBitMaps()[columnIndex] != null
                && tablet.getBitMaps()[columnIndex].isMarked(row);
        // check isNull by bitMap in tablet
        ValueChunkWriter valueChunkWriter =
            tryToAddSeriesWriterInternal(measurementSchemas.get(columnIndex));
        switch (measurementSchemas.get(columnIndex).getType()) {
          case BOOLEAN:
            valueChunkWriter.write(
                time, ((boolean[]) tablet.getValues()[columnIndex])[row], isNull);
            break;
          case INT32:
            valueChunkWriter.write(time, ((int[]) tablet.getValues()[columnIndex])[row], isNull);
            break;
          case DATE:
            valueChunkWriter.write(
                time,
                isNull
                    ? 0
                    : DateUtils.parseDateExpressionToInt(
                        ((LocalDate[]) tablet.getValues()[columnIndex])[row]),
                isNull);
            break;
          case INT64:
          case TIMESTAMP:
            valueChunkWriter.write(time, ((long[]) tablet.getValues()[columnIndex])[row], isNull);
            break;
          case FLOAT:
            valueChunkWriter.write(time, ((float[]) tablet.getValues()[columnIndex])[row], isNull);
            break;
          case DOUBLE:
            valueChunkWriter.write(time, ((double[]) tablet.getValues()[columnIndex])[row], isNull);
            break;
          case TEXT:
          case BLOB:
          case STRING:
            valueChunkWriter.write(time, ((Binary[]) tablet.getValues()[columnIndex])[row], isNull);
            break;
          default:
            throw new UnSupportedDataTypeException(
                String.format(
                    "Data type %s is not supported.",
                    measurementSchemas.get(columnIndex).getType()));
        }
      }
      // TODO: we can write the null columns after whole insertion, according to the point number
      //  in the time chunk before and after, no need to do it in a row-by-row manner
      if (!emptyValueChunkWriters.isEmpty()) {
        writeEmptyDataInOneRow(emptyValueChunkWriters);
      }
      timeChunkWriter.write(time);
      lastTime = time;
      isInitLastTime = true;
      if (checkPageSizeAndMayOpenANewPage()) {
        writePageToPageBuffer();
      }
      pointCount++;
    }
    return pointCount;
  }