luoluoyuyu commented on code in PR #15276:
URL: https://github.com/apache/iotdb/pull/15276#discussion_r2030844984
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/util/builder/PipeTreeModelTsFileBuilder.java:
##########
@@ -91,178 +105,201 @@ public synchronized void close() {
isTabletAlignedList.clear();
}
- private List<Pair<String, File>> writeTabletsToTsFiles()
- throws IOException, WriteProcessException {
- final Map<String, List<Tablet>> device2Tablets = new HashMap<>();
- final Map<String, Boolean> device2Aligned = new HashMap<>();
+ private List<Pair<String, File>> writeTabletsToTsFiles() throws
WriteProcessException {
+ final List<Pair<String, File>> sealedFiles = new ArrayList<>();
+ try (final RestorableTsFileIOWriter writer = new
RestorableTsFileIOWriter(createFile())) {
+ writeTabletsIntoOneFile(writer);
+ sealedFiles.add(new Pair<>(null, writer.getFile()));
+ } catch (final Exception e) {
+ LOGGER.warn(
+ "Batch id = {}: Failed to write tablets into tsfile, because {}",
+ currentBatchId.get(),
+ e.getMessage(),
+ e);
+ // TODO: handle ex
+ throw new WriteProcessException(e);
+ }
+
+ return sealedFiles;
+ }
+
+ private void writeTabletsIntoOneFile(final RestorableTsFileIOWriter writer)
throws Exception {
+ // TODO: database & region
+ final String database = "test_db";
+ final String dataRegionId = "test_dr";
+ final IMemTable memTable = new PrimitiveMemTable(database, dataRegionId);
- // Sort the tablets by device id
for (int i = 0, size = tabletList.size(); i < size; ++i) {
final Tablet tablet = tabletList.get(i);
- final String deviceId = tablet.getDeviceId();
- device2Tablets.computeIfAbsent(deviceId, k -> new
ArrayList<>()).add(tablet);
- device2Aligned.put(deviceId, isTabletAlignedList.get(i));
- }
- // Sort the tablets by start time in each device
- for (final List<Tablet> tablets : device2Tablets.values()) {
- tablets.sort(
- // Each tablet has at least one timestamp
- Comparator.comparingLong(tablet -> tablet.getTimestamp(0)));
- }
+ // convert date value to int
+ // refer to
+ //
org.apache.iotdb.db.storageengine.dataregion.memtable.WritableMemChunk.writeNonAlignedTablet
+ final Object[] values = tablet.getValues();
+ for (int j = 0; j < tablet.getSchemas().size(); ++j) {
+ if (Objects.equals(TSDataType.DATE,
tablet.getSchemas().get(j).getType())) {
+ final LocalDate[] dates = ((LocalDate[]) values[j]);
+ final int[] dateValues = new int[dates.length];
+ for (int k = 0; k < Math.min(dates.length, tablet.getRowSize());
k++) {
+ dateValues[k] = DateUtils.parseDateExpressionToInt(dates[k]);
+ }
Review Comment:
```tablet.getSchemas().get(j)``` may be a null value, so you need to be
careful with Null value issues here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]