zerolbsony commented on code in PR #16936:
URL: https://github.com/apache/iotdb/pull/16936#discussion_r2677945438


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java:
##########
@@ -516,10 +415,120 @@ public static AbstractAlignedChunkMetadata 
rewriteAlignedChunkMetadataStatistics
         alignedChunkMetadata.getTimeChunkMetadata(), 
newValueChunkMetadataList);
   }
 
+  public static void rewriteNonAlignedChunkMetadataStatistics(
+      ChunkMetadata chunkMetadata, TSDataType targetDataType) {
+    Statistics<?> statistics = Statistics.getStatsByType(targetDataType);
+    statistics = getNewStatistics(chunkMetadata, targetDataType, statistics);
+
+    chunkMetadata.setTsDataType(targetDataType);
+    chunkMetadata.setStatistics(statistics);
+  }
+
   public static TSEncoding getDataTypeCompatibleEncoding(TSDataType dataType, 
TSEncoding encoding) {
     if (!encoding.isSupported(dataType)) {
       return EncodingInferenceUtils.getDefaultEncoding(dataType);
     }
     return encoding;
   }
+
+  public static Statistics<?> getNewStatistics(
+      IChunkMetadata chunkMetadata, TSDataType targetDataType, Statistics<?> 
statistics) {
+    switch (chunkMetadata.getDataType()) {
+      case INT32:
+      case DATE:
+      case INT64:
+      case TIMESTAMP:
+      case FLOAT:
+      case DOUBLE:
+      case BOOLEAN:
+        if (targetDataType == TSDataType.STRING) {
+          Binary[] binaryValues = new Binary[4];
+          binaryValues[0] =
+              new Binary(
+                  chunkMetadata.getStatistics().getFirstValue().toString(), 
StandardCharsets.UTF_8);
+          binaryValues[1] =
+              new Binary(
+                  chunkMetadata.getStatistics().getLastValue().toString(), 
StandardCharsets.UTF_8);
+          if (chunkMetadata.getDataType() == TSDataType.BOOLEAN) {
+            binaryValues[2] = new Binary(Boolean.FALSE.toString(), 
StandardCharsets.UTF_8);
+            binaryValues[3] = new Binary(Boolean.TRUE.toString(), 
StandardCharsets.UTF_8);
+          } else {
+            binaryValues[2] =
+                new Binary(
+                    chunkMetadata.getStatistics().getMinValue().toString(), 
StandardCharsets.UTF_8);
+            binaryValues[3] =
+                new Binary(
+                    chunkMetadata.getStatistics().getMaxValue().toString(), 
StandardCharsets.UTF_8);
+          }

Review Comment:
   > No need to process DATE especially?
   
   Yeah, DateStatistics extend IntegerStatistics, retains these statistics : 
first, last, min, and max.



-- 
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]

Reply via email to