You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/05/02 13:51:11 UTC

[GitHub] [iotdb] HTHou opened a new pull request, #5772: [Draft] Use tsblock for query data of TVList

HTHou opened a new pull request, #5772:
URL: https://github.com/apache/iotdb/pull/5772

   ## Description
   
   
   ### Content1 ...
   
   ### Content2 ...
   
   ### Content3 ...
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error 
       conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, 
       design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design 
   (or naming) decision point and compare the alternatives with the designs that you've implemented 
   (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere 
   (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), 
   link to that discussion from this PR description and explain what have changed in your final design 
   compared to your original proposal or the consensus version in the end of the discussion. 
   If something hasn't changed since the original discussion, you can omit a detailed discussion of 
   those aspects of the design here, perhaps apart from brief mentioning for the sake of readability 
   of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <hr>
   
   This PR has:
   - [ ] been self-reviewed.
       - [ ] concurrent read
       - [ ] concurrent write
       - [ ] concurrent read and write 
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. 
   - [ ] added or updated version, __license__, or notice information
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious 
     for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold 
     for code coverage.
   - [ ] added integration tests.
   - [ ] been tested in a test IoTDB cluster.
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items 
   apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items 
   from the checklist above are strictly necessary, but it would be very helpful if you at least 
   self-review the PR. -->
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) in this PR
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865569732


##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java:
##########
@@ -513,107 +510,66 @@ void updateMinTimeAndSorted(long[] time, int start, int end) {
   protected abstract TimeValuePair getTimeValuePair(
       int index, long time, Integer floatPrecision, TSEncoding encoding);
 
-  public TimeValuePair getTimeValuePairForTimeDuplicatedRows(
-      List<Integer> timeDuplicatedVectorRowIndexList,
-      long time,
-      Integer floatPrecision,
-      TSEncoding encoding) {
-    throw new UnsupportedOperationException(ERR_DATATYPE_NOT_CONSISTENT);
-  }
-
   @TestOnly
-  public IPointReader getIterator() {
-    return new Ite();
+  public TsBlock getTsBlock() {
+    return getTsBlock(0, TSEncoding.PLAIN, null);
   }
 
-  public IPointReader getIterator(
-      int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-    return new Ite(floatPrecision, encoding, size, deletionList);
-  }
-
-  protected class Ite implements IPointReader {
-
-    protected TimeValuePair cachedTimeValuePair;
-    protected boolean hasCachedPair;
-    protected int cur;
-    protected Integer floatPrecision;
-    private TSEncoding encoding;
-    private int deleteCursor = 0;
-    /**
-     * because TV list may be share with different query, each iterator has to record it's own size
-     */
-    protected int iteSize = 0;
-    /** this field is effective only in the Tvlist in a RealOnlyMemChunk. */
-    private List<TimeRange> deletionList;
-
-    public Ite() {
-      this.iteSize = TVList.this.rowCount;
-    }
-
-    public Ite(int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-      this.floatPrecision = floatPrecision;
-      this.encoding = encoding;
-      this.iteSize = size;
-      this.deletionList = deletionList;
-    }
-
-    @Override
-    public boolean hasNextTimeValuePair() {
-      if (hasCachedPair) {
-        return true;
-      }
-
-      while (cur < iteSize) {
-        long time = getTime(cur);
-        if (isPointDeleted(time) || (cur + 1 < rowCount() && (time == getTime(cur + 1)))) {
-          cur++;
-          continue;
-        }
-        TimeValuePair tvPair;
-        tvPair = getTimeValuePair(cur, time, floatPrecision, encoding);
-        cur++;
-        if (tvPair.getValue() != null) {
-          cachedTimeValuePair = tvPair;
-          hasCachedPair = true;
-          return true;
-        }
+  public TsBlock getTsBlock(int floatPrecision, TSEncoding encoding, List<TimeRange> deletionList) {
+    TsBlockBuilder builder = new TsBlockBuilder(Collections.singletonList(this.getDataType()));
+    // Time column
+    TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
+    int validRowCount = 0;
+    Integer deleteCursor = 0;

Review Comment:
   This cursor will be used for a whole column, primitive int cannot be changed and set back in `isPointDeleted` method.



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865572899


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {
+        Statistics valueStatistics = Statistics.getStatsByType(dataTypes.get(column));
         valueStatistics.setEmpty(true);
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
         continue;
       }
-      for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-        long time = alignedChunkData.getTime(row);
-        int originRowIndex = alignedChunkData.getValueIndex(row);
-        boolean isNull = alignedChunkData.isValueMarked(originRowIndex, column);
-        if (isNull) {
+      Statistics valueStatistics =
+          Statistics.getStatsByType(tsBlock.getColumn(column).getDataType());
+      IChunkMetadata valueChunkMetadata =
+          new ChunkMetadata(
+              valueChunkNames.get(column),
+              tsBlock.getColumn(column).getDataType(),

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] sonarcloud[bot] commented on pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#issuecomment-1116998144

   SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=apache_incubator-iotdb&pullRequest=5772)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL) [17 Code Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL)
   
   [![70.5%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '70.5%')](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_coverage&view=list) [70.5% Coverage](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865572615


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {
+        Statistics valueStatistics = Statistics.getStatsByType(dataTypes.get(column));
         valueStatistics.setEmpty(true);
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
         continue;
       }
-      for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-        long time = alignedChunkData.getTime(row);
-        int originRowIndex = alignedChunkData.getValueIndex(row);
-        boolean isNull = alignedChunkData.isValueMarked(originRowIndex, column);
-        if (isNull) {
+      Statistics valueStatistics =
+          Statistics.getStatsByType(tsBlock.getColumn(column).getDataType());
+      IChunkMetadata valueChunkMetadata =
+          new ChunkMetadata(
+              valueChunkNames.get(column),
+              tsBlock.getColumn(column).getDataType(),
+              0,
+              valueStatistics);
+      valueChunkMetadataList.add(valueChunkMetadata);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        long time = tsBlock.getTimeColumn().getLong(row);
+        if (tsBlock.getColumn(column).isNull(row)) {
           continue;
         }
-        switch (dataTypeList.get(column)) {
+        switch (tsBlock.getColumn(column).getDataType()) {

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] JackieTien97 merged pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
JackieTien97 merged PR #5772:
URL: https://github.com/apache/iotdb/pull/5772


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] sonarcloud[bot] commented on pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#issuecomment-1118504278

   SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=apache_incubator-iotdb&pullRequest=5772)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL) [13 Code Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL)
   
   [![71.3%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '71.3%')](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_coverage&view=list) [71.3% Coverage](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865620639


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -145,23 +123,22 @@ private void initChunkMeta() throws IOException, QueryProcessException {
   }
 
   public TSDataType getDataType() {
-    return dataType;
+    return tsBlock.getColumn(0).getDataType();

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865670392


##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java:
##########
@@ -903,45 +887,142 @@ public void clear() {
     clearSortedValue();
   }
 
-  @Override
-  @TestOnly
-  public IPointReader getIterator() {
-    return new AlignedIte();
-  }
+  /** Build TsBlock by column. */
+  public TsBlock buildTsBlock(
+      int floatPrecision, List<TSEncoding> encodingList, List<List<TimeRange>> deletionList) {
+    TsBlockBuilder builder = new TsBlockBuilder(dataTypes);
+    // Time column
+    TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
+    int validRowCount = 0;
+    boolean[] timeDuplicateInfo = null;
+    // time column
+    for (int sortedRowIndex = 0; sortedRowIndex < rowCount; sortedRowIndex++) {
+      if (sortedRowIndex == rowCount - 1
+          || getTime(sortedRowIndex) != getTime(sortedRowIndex + 1)) {
+        timeBuilder.writeLong(getTime(sortedRowIndex));
+        validRowCount++;
+      } else {
+        if (Objects.isNull(timeDuplicateInfo)) {
+          timeDuplicateInfo = new boolean[rowCount];
+        }
+        timeDuplicateInfo[sortedRowIndex] = true;
+      }
+    }
 
-  @Override
-  public IPointReader getIterator(
-      int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-    throw new UnsupportedOperationException(ERR_DATATYPE_NOT_CONSISTENT);
+    // value columns
+    for (int columnIndex = 0; columnIndex < dataTypes.size(); columnIndex++) {
+      // skip non-exist column
+      // when there is a non-exist column, the Column in TsBlock is null
+      if (Objects.isNull(dataTypes.get(columnIndex))) {

Review Comment:
   fixed



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java:
##########
@@ -75,44 +70,59 @@ public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
       // accept AlignedPath with only one sub sensor
       if (firstNotNullObject != null
           && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        batchData.putVector(timeValuePair.getTimestamp(), values);
+              || valueFilter.satisfy(tsBlock.getTimeByIndex(row), firstNotNullObject))) {
+        TsPrimitiveType[] values = new TsPrimitiveType[tsBlock.getValueColumnCount()];
+        for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+          if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {
+            values[column] = tsBlock.getColumn(column).getTsPrimitiveType(row);
+          }
+        }
+        batchData.putVector(tsBlock.getTimeByIndex(row), values);
       }
     }
     return batchData.flip();
   }
 
   @Override
-  public TsBlock getAllSatisfiedData() throws IOException {
-    // TODO change from the row-based style to column-based style
+  public TsBlock getAllSatisfiedData() {
     TsBlockBuilder builder =
         new TsBlockBuilder(
             chunkMetadata.getValueChunkMetadataList().stream()
                 .map(IChunkMetadata::getDataType)
                 .collect(Collectors.toList()));
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      TsPrimitiveType[] values = timeValuePair.getValue().getVector();
-      // save the first not null value of each row
-      Object firstNotNullObject = null;
-      for (TsPrimitiveType value : values) {
-        if (value != null) {
-          firstNotNullObject = value.getValue();
-          break;
-        }
-      }
+
+    boolean[] valueSatisfyInfo = new boolean[tsBlock.getPositionCount()];
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+
       // if all the sub sensors' value are null in current time
       // or current row is not satisfied with the filter, just discard it
-      // TODO fix value filter firstNotNullObject, currently, if it's a value filter, it will only
+      // currently, if it's a value filter, it will only
       // accept AlignedPath with only one sub sensor
-      if (firstNotNullObject != null
-          && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        builder.getTimeColumnBuilder().writeLong(timeValuePair.getTimestamp());
-        for (int i = 0; i < values.length; i++) {
-          builder.getColumnBuilder(i).writeTsPrimitiveType(values[i]);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        if (column == 0) {
+          Object value = tsBlock.getColumn(column).getObject(row);
+          if (value != null && (valueFilter == null || valueFilter.satisfy(0, value))) {
+            builder.getColumnBuilder(column).writeObject(tsBlock.getColumn(column).getObject(row));

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865577688


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {
+        Statistics valueStatistics = Statistics.getStatsByType(dataTypes.get(column));
         valueStatistics.setEmpty(true);
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
         continue;
       }
-      for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-        long time = alignedChunkData.getTime(row);
-        int originRowIndex = alignedChunkData.getValueIndex(row);
-        boolean isNull = alignedChunkData.isValueMarked(originRowIndex, column);
-        if (isNull) {
+      Statistics valueStatistics =
+          Statistics.getStatsByType(tsBlock.getColumn(column).getDataType());
+      IChunkMetadata valueChunkMetadata =
+          new ChunkMetadata(
+              valueChunkNames.get(column),
+              tsBlock.getColumn(column).getDataType(),
+              0,
+              valueStatistics);
+      valueChunkMetadataList.add(valueChunkMetadata);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        long time = tsBlock.getTimeColumn().getLong(row);
+        if (tsBlock.getColumn(column).isNull(row)) {
           continue;
         }
-        switch (dataTypeList.get(column)) {
+        switch (tsBlock.getColumn(column).getDataType()) {
           case BOOLEAN:
-            valueStatistics.update(
-                time, alignedChunkData.getBooleanByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getBoolean(row));
             break;
           case TEXT:
-            valueStatistics.update(
-                time, alignedChunkData.getBinaryByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getBinary(row));
             break;
           case FLOAT:
-            valueStatistics.update(
-                time, alignedChunkData.getFloatByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getFloat(row));
             break;
           case INT32:
-            valueStatistics.update(
-                time, alignedChunkData.getIntByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getInt(row));
             break;
           case INT64:
-            valueStatistics.update(
-                time, alignedChunkData.getLongByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getLong(row));
             break;
           case DOUBLE:
-            valueStatistics.update(
-                time, alignedChunkData.getDoubleByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getDouble(row));
             break;
           default:
-            throw new QueryProcessException("Unsupported data type:" + dataType);
+            throw new QueryProcessException(
+                "Unsupported data type:" + tsBlock.getColumn(column).getDataType());
         }
       }
       valueStatistics.setEmpty(false);

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865622395


##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java:
##########
@@ -58,14 +55,12 @@ public BatchData getAllSatisfiedPageData() throws IOException {
   @Override
   public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
     BatchData batchData = BatchDataFactory.createBatchData(TSDataType.VECTOR, ascending, false);
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      TsPrimitiveType[] values = timeValuePair.getValue().getVector();
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
       // save the first not null value of each row
       Object firstNotNullObject = null;
-      for (TsPrimitiveType value : values) {
-        if (value != null) {
-          firstNotNullObject = value.getValue();
+      for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+        if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {

Review Comment:
   fixed



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java:
##########
@@ -75,44 +70,59 @@ public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
       // accept AlignedPath with only one sub sensor
       if (firstNotNullObject != null
           && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        batchData.putVector(timeValuePair.getTimestamp(), values);
+              || valueFilter.satisfy(tsBlock.getTimeByIndex(row), firstNotNullObject))) {
+        TsPrimitiveType[] values = new TsPrimitiveType[tsBlock.getValueColumnCount()];
+        for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+          if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865640086


##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java:
##########
@@ -75,44 +70,59 @@ public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
       // accept AlignedPath with only one sub sensor
       if (firstNotNullObject != null
           && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        batchData.putVector(timeValuePair.getTimestamp(), values);
+              || valueFilter.satisfy(tsBlock.getTimeByIndex(row), firstNotNullObject))) {
+        TsPrimitiveType[] values = new TsPrimitiveType[tsBlock.getValueColumnCount()];
+        for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+          if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {
+            values[column] = tsBlock.getColumn(column).getTsPrimitiveType(row);
+          }
+        }
+        batchData.putVector(tsBlock.getTimeByIndex(row), values);
       }
     }
     return batchData.flip();
   }
 
   @Override
-  public TsBlock getAllSatisfiedData() throws IOException {
-    // TODO change from the row-based style to column-based style
+  public TsBlock getAllSatisfiedData() {
     TsBlockBuilder builder =
         new TsBlockBuilder(
             chunkMetadata.getValueChunkMetadataList().stream()
                 .map(IChunkMetadata::getDataType)
                 .collect(Collectors.toList()));
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      TsPrimitiveType[] values = timeValuePair.getValue().getVector();
-      // save the first not null value of each row
-      Object firstNotNullObject = null;
-      for (TsPrimitiveType value : values) {
-        if (value != null) {
-          firstNotNullObject = value.getValue();
-          break;
-        }
-      }
+
+    boolean[] valueSatisfyInfo = new boolean[tsBlock.getPositionCount()];
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+
       // if all the sub sensors' value are null in current time
       // or current row is not satisfied with the filter, just discard it
-      // TODO fix value filter firstNotNullObject, currently, if it's a value filter, it will only
+      // currently, if it's a value filter, it will only
       // accept AlignedPath with only one sub sensor
-      if (firstNotNullObject != null
-          && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        builder.getTimeColumnBuilder().writeLong(timeValuePair.getTimestamp());
-        for (int i = 0; i < values.length; i++) {
-          builder.getColumnBuilder(i).writeTsPrimitiveType(values[i]);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        if (column == 0) {
+          Object value = tsBlock.getColumn(column).getObject(row);
+          if (value != null && (valueFilter == null || valueFilter.satisfy(0, value))) {
+            builder.getColumnBuilder(column).writeObject(tsBlock.getColumn(column).getObject(row));
+            valueSatisfyInfo[row] = true;
+            builder.declarePosition();
+          }
+        } else {
+          if (valueSatisfyInfo[row]) {
+            if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {
+              builder
+                  .getColumnBuilder(column)
+                  .writeObject(tsBlock.getColumn(column).getObject(row));

Review Comment:
   Fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] sonarcloud[bot] commented on pull request #5772: [Draft] Use TsBlock for query data of TVList

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#issuecomment-1116043258

   SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=apache_incubator-iotdb&pullRequest=5772)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL) [21 Code Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL)
   
   [![72.4%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '72.4%')](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_coverage&view=list) [72.4% Coverage](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865578811


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {
+        Statistics valueStatistics = Statistics.getStatsByType(dataTypes.get(column));
         valueStatistics.setEmpty(true);
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
         continue;
       }
-      for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-        long time = alignedChunkData.getTime(row);
-        int originRowIndex = alignedChunkData.getValueIndex(row);
-        boolean isNull = alignedChunkData.isValueMarked(originRowIndex, column);
-        if (isNull) {
+      Statistics valueStatistics =
+          Statistics.getStatsByType(tsBlock.getColumn(column).getDataType());
+      IChunkMetadata valueChunkMetadata =
+          new ChunkMetadata(
+              valueChunkNames.get(column),
+              tsBlock.getColumn(column).getDataType(),
+              0,
+              valueStatistics);
+      valueChunkMetadataList.add(valueChunkMetadata);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        long time = tsBlock.getTimeColumn().getLong(row);
+        if (tsBlock.getColumn(column).isNull(row)) {
           continue;
         }
-        switch (dataTypeList.get(column)) {
+        switch (tsBlock.getColumn(column).getDataType()) {
           case BOOLEAN:
-            valueStatistics.update(
-                time, alignedChunkData.getBooleanByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getBoolean(row));
             break;
           case TEXT:
-            valueStatistics.update(
-                time, alignedChunkData.getBinaryByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getBinary(row));
             break;
           case FLOAT:
-            valueStatistics.update(
-                time, alignedChunkData.getFloatByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getFloat(row));
             break;
           case INT32:
-            valueStatistics.update(
-                time, alignedChunkData.getIntByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getInt(row));
             break;
           case INT64:
-            valueStatistics.update(
-                time, alignedChunkData.getLongByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getLong(row));
             break;
           case DOUBLE:
-            valueStatistics.update(
-                time, alignedChunkData.getDoubleByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getDouble(row));
             break;
           default:
-            throw new QueryProcessException("Unsupported data type:" + dataType);
+            throw new QueryProcessException(
+                "Unsupported data type:" + tsBlock.getColumn(column).getDataType());
         }
       }
       valueStatistics.setEmpty(false);
     }
-    IChunkMetadata vectorChunkMetadata =
+    IChunkMetadata alignedChunkMetadata =
         new AlignedChunkMetadata(timeChunkMetadata, valueChunkMetadataList);
-    vectorChunkMetadata.setChunkLoader(new MemAlignedChunkLoader(this));
-    vectorChunkMetadata.setVersion(Long.MAX_VALUE);
-    cachedMetaData = vectorChunkMetadata;
+    alignedChunkMetadata.setChunkLoader(new MemAlignedChunkLoader(this));
+    alignedChunkMetadata.setVersion(Long.MAX_VALUE);
+    cachedMetaData = alignedChunkMetadata;
+  }
+
+  @Override
+  public boolean isEmpty() throws IOException {
+    return tsBlock.isEmpty();
   }
 
+  @TestOnly
   @Override
   public IPointReader getPointReader() {
-    chunkPointReader =
-        chunkData.getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    return chunkPointReader;
+    return chunkData.getAlignedIterator(null, null, deletionList);

Review Comment:
   Fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865791912


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;

Review Comment:
   Fixed



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {

Review Comment:
   Fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] coveralls commented on pull request #5772: [Draft] Use TsBlock for query data of TVList

Posted by GitBox <gi...@apache.org>.
coveralls commented on PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#issuecomment-1116048827

   
   [![Coverage Status](https://coveralls.io/builds/48788344/badge)](https://coveralls.io/builds/48788344)
   
   Coverage decreased (-0.02%) to 53.633% when pulling **aa8c854b264d3d972ce77ba022697918fdd045ca on memtsblock** into **38ca619b69b071ab05f79b123e4c58f19c6fe14b on master**.
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865583747


##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemPageReader.java:
##########
@@ -54,92 +51,71 @@ public MemPageReader(
   public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
     TSDataType dataType = chunkMetadata.getDataType();
     BatchData batchData = BatchDataFactory.createBatchData(dataType, ascending, false);
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
       if (valueFilter == null
           || valueFilter.satisfy(
-              timeValuePair.getTimestamp(), timeValuePair.getValue().getValue())) {
-        batchData.putAnObject(timeValuePair.getTimestamp(), timeValuePair.getValue().getValue());
+              tsBlock.getTimeColumn().getLong(i), tsBlock.getColumn(0).getObject(i))) {
+        batchData.putAnObject(
+            tsBlock.getTimeColumn().getLong(i), tsBlock.getColumn(0).getObject(i));
       }
     }

Review Comment:
   Fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] JackieTien97 commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
JackieTien97 commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865509392


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -45,44 +45,29 @@
  */
 public class ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<TimeRange> deletionList;
-
   private String measurementUid;
-  private TSDataType dataType;

Review Comment:
   don't delete this field, you should use it instead of getting data type from tsBlock.



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;

Review Comment:
   We don't need this field anymore.



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {
+        Statistics valueStatistics = Statistics.getStatsByType(dataTypes.get(column));
         valueStatistics.setEmpty(true);
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
         continue;
       }
-      for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-        long time = alignedChunkData.getTime(row);
-        int originRowIndex = alignedChunkData.getValueIndex(row);
-        boolean isNull = alignedChunkData.isValueMarked(originRowIndex, column);
-        if (isNull) {
+      Statistics valueStatistics =
+          Statistics.getStatsByType(tsBlock.getColumn(column).getDataType());

Review Comment:
   Don't use DataType info in TsBlock, you can use `dataTypes` of this class.



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java:
##########
@@ -513,107 +510,66 @@ void updateMinTimeAndSorted(long[] time, int start, int end) {
   protected abstract TimeValuePair getTimeValuePair(
       int index, long time, Integer floatPrecision, TSEncoding encoding);
 
-  public TimeValuePair getTimeValuePairForTimeDuplicatedRows(
-      List<Integer> timeDuplicatedVectorRowIndexList,
-      long time,
-      Integer floatPrecision,
-      TSEncoding encoding) {
-    throw new UnsupportedOperationException(ERR_DATATYPE_NOT_CONSISTENT);
-  }
-
   @TestOnly
-  public IPointReader getIterator() {
-    return new Ite();
+  public TsBlock getTsBlock() {
+    return getTsBlock(0, TSEncoding.PLAIN, null);
   }
 
-  public IPointReader getIterator(
-      int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-    return new Ite(floatPrecision, encoding, size, deletionList);
-  }
-
-  protected class Ite implements IPointReader {
-
-    protected TimeValuePair cachedTimeValuePair;
-    protected boolean hasCachedPair;
-    protected int cur;
-    protected Integer floatPrecision;
-    private TSEncoding encoding;
-    private int deleteCursor = 0;
-    /**
-     * because TV list may be share with different query, each iterator has to record it's own size
-     */
-    protected int iteSize = 0;
-    /** this field is effective only in the Tvlist in a RealOnlyMemChunk. */
-    private List<TimeRange> deletionList;
-
-    public Ite() {
-      this.iteSize = TVList.this.rowCount;
-    }
-
-    public Ite(int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-      this.floatPrecision = floatPrecision;
-      this.encoding = encoding;
-      this.iteSize = size;
-      this.deletionList = deletionList;
-    }
-
-    @Override
-    public boolean hasNextTimeValuePair() {
-      if (hasCachedPair) {
-        return true;
-      }
-
-      while (cur < iteSize) {
-        long time = getTime(cur);
-        if (isPointDeleted(time) || (cur + 1 < rowCount() && (time == getTime(cur + 1)))) {
-          cur++;
-          continue;
-        }
-        TimeValuePair tvPair;
-        tvPair = getTimeValuePair(cur, time, floatPrecision, encoding);
-        cur++;
-        if (tvPair.getValue() != null) {
-          cachedTimeValuePair = tvPair;
-          hasCachedPair = true;
-          return true;
-        }
+  public TsBlock getTsBlock(int floatPrecision, TSEncoding encoding, List<TimeRange> deletionList) {
+    TsBlockBuilder builder = new TsBlockBuilder(Collections.singletonList(this.getDataType()));
+    // Time column
+    TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
+    int validRowCount = 0;
+    Integer deleteCursor = 0;
+    for (int i = 0; i < rowCount; i++) {
+      if (!isPointDeleted(getTime(i), deletionList, deleteCursor)
+          && (i == rowCount - 1 || getTime(i) != getTime(i + 1))) {
+        timeBuilder.writeLong(this.getTime(i));

Review Comment:
   put this loop into each sub class to avoid do this deletion judgement twice.



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/BinaryTVList.java:
##########
@@ -196,6 +198,21 @@ protected TimeValuePair getTimeValuePair(
     return new TimeValuePair(time, TsPrimitiveType.getByType(TSDataType.TEXT, getBinary(index)));
   }
 
+  @Override
+  protected void writeValidValuesIntoTsBlock(
+      ColumnBuilder valueBuilder,
+      int floatPrecision,
+      TSEncoding encoding,
+      List<TimeRange> deletionList) {
+    Integer deleteCursor = 0;

Review Comment:
   ```suggestion
       int deleteCursor = 0;
   ```



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedChunkReader.java:
##########
@@ -20,82 +20,39 @@
 
 import org.apache.iotdb.db.engine.querycontext.AlignedReadOnlyMemChunk;
 import org.apache.iotdb.tsfile.file.metadata.AlignedChunkMetadata;
-import org.apache.iotdb.tsfile.read.TimeValuePair;
 import org.apache.iotdb.tsfile.read.common.BatchData;
 import org.apache.iotdb.tsfile.read.filter.basic.Filter;
 import org.apache.iotdb.tsfile.read.reader.IChunkReader;
 import org.apache.iotdb.tsfile.read.reader.IPageReader;
-import org.apache.iotdb.tsfile.read.reader.IPointReader;
 
-import java.io.IOException;
 import java.util.Collections;
 import java.util.List;
 
 /** To read aligned chunk data in memory */
-public class MemAlignedChunkReader implements IChunkReader, IPointReader {
+public class MemAlignedChunkReader implements IChunkReader {
 
-  private IPointReader timeValuePairIterator;
-  private Filter filter;
-  private boolean hasCachedTimeValuePair;
-  private TimeValuePair cachedTimeValuePair;
   private List<IPageReader> pageReaderList;
 
   public MemAlignedChunkReader(AlignedReadOnlyMemChunk readableChunk, Filter filter) {
-    timeValuePairIterator = readableChunk.getPointReader();
-    this.filter = filter;
     // we treat one ReadOnlyMemChunk as one Page
     this.pageReaderList =
         Collections.singletonList(
             new MemAlignedPageReader(
-                timeValuePairIterator,
+                readableChunk.getTsBlock(),
                 (AlignedChunkMetadata) readableChunk.getChunkMetaData(),
                 filter));
   }
 
   @Override
-  public boolean hasNextTimeValuePair() throws IOException {
-    if (hasCachedTimeValuePair) {
-      return true;
-    }
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      if (filter == null
-          || filter.satisfy(timeValuePair.getTimestamp(), timeValuePair.getValue().getValue())) {
-        hasCachedTimeValuePair = true;
-        cachedTimeValuePair = timeValuePair;
-        break;
-      }
-    }
-    return hasCachedTimeValuePair;
+  public boolean hasNextSatisfiedPage() {
+    // mem chunk reader should not reach here
+    return false;
   }
 
   @Override
-  public TimeValuePair nextTimeValuePair() throws IOException {
-    if (hasCachedTimeValuePair) {
-      hasCachedTimeValuePair = false;
-      return cachedTimeValuePair;
-    } else {
-      return timeValuePairIterator.nextTimeValuePair();
-    }
-  }
-
-  @Override
-  public TimeValuePair currentTimeValuePair() throws IOException {
-    if (!hasCachedTimeValuePair) {
-      cachedTimeValuePair = timeValuePairIterator.nextTimeValuePair();
-      hasCachedTimeValuePair = true;
-    }
-    return cachedTimeValuePair;
-  }
-
-  @Override
-  public boolean hasNextSatisfiedPage() throws IOException {
-    return hasNextTimeValuePair();
-  }
-
-  @Override
-  public BatchData nextPageData() throws IOException {
-    return pageReaderList.remove(0).getAllSatisfiedPageData();
+  public BatchData nextPageData() {
+    // mem chunk reader should not reach here
+    return null;

Review Comment:
   throw exception.



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java:
##########
@@ -75,44 +70,59 @@ public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
       // accept AlignedPath with only one sub sensor
       if (firstNotNullObject != null
           && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        batchData.putVector(timeValuePair.getTimestamp(), values);
+              || valueFilter.satisfy(tsBlock.getTimeByIndex(row), firstNotNullObject))) {
+        TsPrimitiveType[] values = new TsPrimitiveType[tsBlock.getValueColumnCount()];
+        for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+          if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {

Review Comment:
   ```suggestion
             if (!tsBlock.getColumn(column).isNull(row)) {
   ```



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java:
##########
@@ -75,44 +70,59 @@ public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
       // accept AlignedPath with only one sub sensor
       if (firstNotNullObject != null
           && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        batchData.putVector(timeValuePair.getTimestamp(), values);
+              || valueFilter.satisfy(tsBlock.getTimeByIndex(row), firstNotNullObject))) {
+        TsPrimitiveType[] values = new TsPrimitiveType[tsBlock.getValueColumnCount()];
+        for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+          if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {
+            values[column] = tsBlock.getColumn(column).getTsPrimitiveType(row);
+          }
+        }
+        batchData.putVector(tsBlock.getTimeByIndex(row), values);
       }
     }
     return batchData.flip();
   }
 
   @Override
-  public TsBlock getAllSatisfiedData() throws IOException {
-    // TODO change from the row-based style to column-based style
+  public TsBlock getAllSatisfiedData() {
     TsBlockBuilder builder =
         new TsBlockBuilder(
             chunkMetadata.getValueChunkMetadataList().stream()
                 .map(IChunkMetadata::getDataType)
                 .collect(Collectors.toList()));
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      TsPrimitiveType[] values = timeValuePair.getValue().getVector();
-      // save the first not null value of each row
-      Object firstNotNullObject = null;
-      for (TsPrimitiveType value : values) {
-        if (value != null) {
-          firstNotNullObject = value.getValue();
-          break;
-        }
-      }
+
+    boolean[] valueSatisfyInfo = new boolean[tsBlock.getPositionCount()];
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+
       // if all the sub sensors' value are null in current time
       // or current row is not satisfied with the filter, just discard it
-      // TODO fix value filter firstNotNullObject, currently, if it's a value filter, it will only
+      // currently, if it's a value filter, it will only
       // accept AlignedPath with only one sub sensor
-      if (firstNotNullObject != null
-          && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        builder.getTimeColumnBuilder().writeLong(timeValuePair.getTimestamp());
-        for (int i = 0; i < values.length; i++) {
-          builder.getColumnBuilder(i).writeTsPrimitiveType(values[i]);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        if (column == 0) {
+          Object value = tsBlock.getColumn(column).getObject(row);
+          if (value != null && (valueFilter == null || valueFilter.satisfy(0, value))) {

Review Comment:
   use actual time instead of 0, because valueFilter may be time filter.



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);

Review Comment:
   It seems that you never use this logger.



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {
+        Statistics valueStatistics = Statistics.getStatsByType(dataTypes.get(column));
         valueStatistics.setEmpty(true);
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
         continue;
       }
-      for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-        long time = alignedChunkData.getTime(row);
-        int originRowIndex = alignedChunkData.getValueIndex(row);
-        boolean isNull = alignedChunkData.isValueMarked(originRowIndex, column);
-        if (isNull) {
+      Statistics valueStatistics =
+          Statistics.getStatsByType(tsBlock.getColumn(column).getDataType());
+      IChunkMetadata valueChunkMetadata =
+          new ChunkMetadata(
+              valueChunkNames.get(column),
+              tsBlock.getColumn(column).getDataType(),
+              0,
+              valueStatistics);
+      valueChunkMetadataList.add(valueChunkMetadata);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        long time = tsBlock.getTimeColumn().getLong(row);
+        if (tsBlock.getColumn(column).isNull(row)) {
           continue;
         }
-        switch (dataTypeList.get(column)) {
+        switch (tsBlock.getColumn(column).getDataType()) {
           case BOOLEAN:
-            valueStatistics.update(
-                time, alignedChunkData.getBooleanByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getBoolean(row));
             break;
           case TEXT:
-            valueStatistics.update(
-                time, alignedChunkData.getBinaryByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getBinary(row));
             break;
           case FLOAT:
-            valueStatistics.update(
-                time, alignedChunkData.getFloatByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getFloat(row));
             break;
           case INT32:
-            valueStatistics.update(
-                time, alignedChunkData.getIntByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getInt(row));
             break;
           case INT64:
-            valueStatistics.update(
-                time, alignedChunkData.getLongByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getLong(row));
             break;
           case DOUBLE:
-            valueStatistics.update(
-                time, alignedChunkData.getDoubleByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getDouble(row));
             break;
           default:
-            throw new QueryProcessException("Unsupported data type:" + dataType);
+            throw new QueryProcessException(
+                "Unsupported data type:" + tsBlock.getColumn(column).getDataType());
         }
       }
       valueStatistics.setEmpty(false);
     }
-    IChunkMetadata vectorChunkMetadata =
+    IChunkMetadata alignedChunkMetadata =
         new AlignedChunkMetadata(timeChunkMetadata, valueChunkMetadataList);
-    vectorChunkMetadata.setChunkLoader(new MemAlignedChunkLoader(this));
-    vectorChunkMetadata.setVersion(Long.MAX_VALUE);
-    cachedMetaData = vectorChunkMetadata;
+    alignedChunkMetadata.setChunkLoader(new MemAlignedChunkLoader(this));
+    alignedChunkMetadata.setVersion(Long.MAX_VALUE);
+    cachedMetaData = alignedChunkMetadata;
+  }
+
+  @Override
+  public boolean isEmpty() throws IOException {
+    return tsBlock.isEmpty();
   }
 
+  @TestOnly
   @Override
   public IPointReader getPointReader() {
-    chunkPointReader =
-        chunkData.getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    return chunkPointReader;
+    return chunkData.getAlignedIterator(null, null, deletionList);

Review Comment:
   Use IPointReader in TsBlock.



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {
+        Statistics valueStatistics = Statistics.getStatsByType(dataTypes.get(column));
         valueStatistics.setEmpty(true);
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
         continue;
       }
-      for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-        long time = alignedChunkData.getTime(row);
-        int originRowIndex = alignedChunkData.getValueIndex(row);
-        boolean isNull = alignedChunkData.isValueMarked(originRowIndex, column);
-        if (isNull) {
+      Statistics valueStatistics =
+          Statistics.getStatsByType(tsBlock.getColumn(column).getDataType());
+      IChunkMetadata valueChunkMetadata =
+          new ChunkMetadata(
+              valueChunkNames.get(column),
+              tsBlock.getColumn(column).getDataType(),
+              0,
+              valueStatistics);
+      valueChunkMetadataList.add(valueChunkMetadata);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        long time = tsBlock.getTimeColumn().getLong(row);
+        if (tsBlock.getColumn(column).isNull(row)) {
           continue;
         }
-        switch (dataTypeList.get(column)) {
+        switch (tsBlock.getColumn(column).getDataType()) {

Review Comment:
   put switch-case out of for loop.



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {
+        Statistics valueStatistics = Statistics.getStatsByType(dataTypes.get(column));
         valueStatistics.setEmpty(true);
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
         continue;
       }
-      for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-        long time = alignedChunkData.getTime(row);
-        int originRowIndex = alignedChunkData.getValueIndex(row);
-        boolean isNull = alignedChunkData.isValueMarked(originRowIndex, column);
-        if (isNull) {
+      Statistics valueStatistics =
+          Statistics.getStatsByType(tsBlock.getColumn(column).getDataType());
+      IChunkMetadata valueChunkMetadata =
+          new ChunkMetadata(
+              valueChunkNames.get(column),
+              tsBlock.getColumn(column).getDataType(),

Review Comment:
   same as above



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java:
##########
@@ -513,107 +510,66 @@ void updateMinTimeAndSorted(long[] time, int start, int end) {
   protected abstract TimeValuePair getTimeValuePair(
       int index, long time, Integer floatPrecision, TSEncoding encoding);
 
-  public TimeValuePair getTimeValuePairForTimeDuplicatedRows(
-      List<Integer> timeDuplicatedVectorRowIndexList,
-      long time,
-      Integer floatPrecision,
-      TSEncoding encoding) {
-    throw new UnsupportedOperationException(ERR_DATATYPE_NOT_CONSISTENT);
-  }
-
   @TestOnly
-  public IPointReader getIterator() {
-    return new Ite();
+  public TsBlock getTsBlock() {
+    return getTsBlock(0, TSEncoding.PLAIN, null);
   }
 
-  public IPointReader getIterator(
-      int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-    return new Ite(floatPrecision, encoding, size, deletionList);
-  }
-
-  protected class Ite implements IPointReader {
-
-    protected TimeValuePair cachedTimeValuePair;
-    protected boolean hasCachedPair;
-    protected int cur;
-    protected Integer floatPrecision;
-    private TSEncoding encoding;
-    private int deleteCursor = 0;
-    /**
-     * because TV list may be share with different query, each iterator has to record it's own size
-     */
-    protected int iteSize = 0;
-    /** this field is effective only in the Tvlist in a RealOnlyMemChunk. */
-    private List<TimeRange> deletionList;
-
-    public Ite() {
-      this.iteSize = TVList.this.rowCount;
-    }
-
-    public Ite(int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-      this.floatPrecision = floatPrecision;
-      this.encoding = encoding;
-      this.iteSize = size;
-      this.deletionList = deletionList;
-    }
-
-    @Override
-    public boolean hasNextTimeValuePair() {
-      if (hasCachedPair) {
-        return true;
-      }
-
-      while (cur < iteSize) {
-        long time = getTime(cur);
-        if (isPointDeleted(time) || (cur + 1 < rowCount() && (time == getTime(cur + 1)))) {
-          cur++;
-          continue;
-        }
-        TimeValuePair tvPair;
-        tvPair = getTimeValuePair(cur, time, floatPrecision, encoding);
-        cur++;
-        if (tvPair.getValue() != null) {
-          cachedTimeValuePair = tvPair;
-          hasCachedPair = true;
-          return true;
-        }
+  public TsBlock getTsBlock(int floatPrecision, TSEncoding encoding, List<TimeRange> deletionList) {
+    TsBlockBuilder builder = new TsBlockBuilder(Collections.singletonList(this.getDataType()));
+    // Time column
+    TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
+    int validRowCount = 0;
+    Integer deleteCursor = 0;
+    for (int i = 0; i < rowCount; i++) {
+      if (!isPointDeleted(getTime(i), deletionList, deleteCursor)
+          && (i == rowCount - 1 || getTime(i) != getTime(i + 1))) {
+        timeBuilder.writeLong(this.getTime(i));
+        validRowCount++;
       }
-
-      return false;
     }
 
-    protected boolean isPointDeleted(long timestamp) {
-      while (deletionList != null && deleteCursor < deletionList.size()) {
-        if (deletionList.get(deleteCursor).contains(timestamp)) {
-          return true;
-        } else if (deletionList.get(deleteCursor).getMax() < timestamp) {
-          deleteCursor++;
-        } else {
-          return false;
-        }
-      }
-      return false;
-    }
+    // value column
+    ColumnBuilder valueBuilder = builder.getColumnBuilder(0);
+    writeValidValuesIntoTsBlock(valueBuilder, floatPrecision, encoding, deletionList);
+    builder.declarePositions(validRowCount);
+    return builder.build();
+  }
 
-    @Override
-    public TimeValuePair nextTimeValuePair() throws IOException {
-      if (hasCachedPair || hasNextTimeValuePair()) {
-        hasCachedPair = false;
-        return cachedTimeValuePair;
+  protected abstract void writeValidValuesIntoTsBlock(
+      ColumnBuilder valueBuilder,
+      int floatPrecision,
+      TSEncoding encoding,
+      List<TimeRange> deletionList);
+
+  protected boolean isPointDeleted(
+      long timestamp, List<TimeRange> deletionList, Integer deleteCursor) {

Review Comment:
   ```suggestion
         long timestamp, List<TimeRange> deletionList, int deleteCursor) {
   ```



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {

Review Comment:
   Column in TsBlock will never be null.



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {
+        Statistics valueStatistics = Statistics.getStatsByType(dataTypes.get(column));
         valueStatistics.setEmpty(true);
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
         continue;
       }
-      for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-        long time = alignedChunkData.getTime(row);
-        int originRowIndex = alignedChunkData.getValueIndex(row);
-        boolean isNull = alignedChunkData.isValueMarked(originRowIndex, column);
-        if (isNull) {
+      Statistics valueStatistics =
+          Statistics.getStatsByType(tsBlock.getColumn(column).getDataType());
+      IChunkMetadata valueChunkMetadata =
+          new ChunkMetadata(
+              valueChunkNames.get(column),
+              tsBlock.getColumn(column).getDataType(),
+              0,
+              valueStatistics);
+      valueChunkMetadataList.add(valueChunkMetadata);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        long time = tsBlock.getTimeColumn().getLong(row);
+        if (tsBlock.getColumn(column).isNull(row)) {
           continue;
         }
-        switch (dataTypeList.get(column)) {
+        switch (tsBlock.getColumn(column).getDataType()) {
           case BOOLEAN:
-            valueStatistics.update(
-                time, alignedChunkData.getBooleanByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getBoolean(row));
             break;
           case TEXT:
-            valueStatistics.update(
-                time, alignedChunkData.getBinaryByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getBinary(row));
             break;
           case FLOAT:
-            valueStatistics.update(
-                time, alignedChunkData.getFloatByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getFloat(row));
             break;
           case INT32:
-            valueStatistics.update(
-                time, alignedChunkData.getIntByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getInt(row));
             break;
           case INT64:
-            valueStatistics.update(
-                time, alignedChunkData.getLongByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getLong(row));
             break;
           case DOUBLE:
-            valueStatistics.update(
-                time, alignedChunkData.getDoubleByValueIndex(originRowIndex, column));
+            valueStatistics.update(time, tsBlock.getColumn(column).getDouble(row));
             break;
           default:
-            throw new QueryProcessException("Unsupported data type:" + dataType);
+            throw new QueryProcessException(
+                "Unsupported data type:" + tsBlock.getColumn(column).getDataType());
         }
       }
       valueStatistics.setEmpty(false);

Review Comment:
   setEmpty(true) at the very beginning and then setEmpty(false) when meet non null value.



##########
tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/block/TsBlockBuilder.java:
##########
@@ -95,6 +95,9 @@ private TsBlockBuilder(int initialExpectedEntries, int maxTsBlockBytes, List<TSD
     for (int i = 0; i < valueColumnBuilders.length; i++) {
       // TODO use Type interface to encapsulate createColumnBuilder to each concrete type class
       // instead of switch-case
+      if (types.get(i) == null) {
+        continue;
+      }

Review Comment:
   ```suggestion
   ```



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/LongTVList.java:
##########
@@ -194,6 +196,21 @@ protected TimeValuePair getTimeValuePair(
     return new TimeValuePair(time, TsPrimitiveType.getByType(TSDataType.INT64, getLong(index)));
   }
 
+  @Override
+  protected void writeValidValuesIntoTsBlock(
+      ColumnBuilder valueBuilder,
+      int floatPrecision,
+      TSEncoding encoding,
+      List<TimeRange> deletionList) {
+    Integer deleteCursor = 0;

Review Comment:
   ```suggestion
       int deleteCursor = 0;
   ```



##########
tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/block/TsBlockBuilder.java:
##########
@@ -293,6 +296,9 @@ public TsBlock build() {
 
     Column[] columns = new Column[valueColumnBuilders.length];
     for (int i = 0; i < columns.length; i++) {
+      if (valueColumnBuilders[i] == null) {
+        continue;
+      }

Review Comment:
   ```suggestion
   ```



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemPageReader.java:
##########
@@ -54,92 +51,71 @@ public MemPageReader(
   public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
     TSDataType dataType = chunkMetadata.getDataType();
     BatchData batchData = BatchDataFactory.createBatchData(dataType, ascending, false);
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
       if (valueFilter == null
           || valueFilter.satisfy(
-              timeValuePair.getTimestamp(), timeValuePair.getValue().getValue())) {
-        batchData.putAnObject(timeValuePair.getTimestamp(), timeValuePair.getValue().getValue());
+              tsBlock.getTimeColumn().getLong(i), tsBlock.getColumn(0).getObject(i))) {
+        batchData.putAnObject(
+            tsBlock.getTimeColumn().getLong(i), tsBlock.getColumn(0).getObject(i));
       }
     }

Review Comment:
   we have already know the datatype, should not use batchData.putAnObject() method. We should use putXXX, like putInt.



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java:
##########
@@ -513,107 +510,66 @@ void updateMinTimeAndSorted(long[] time, int start, int end) {
   protected abstract TimeValuePair getTimeValuePair(
       int index, long time, Integer floatPrecision, TSEncoding encoding);
 
-  public TimeValuePair getTimeValuePairForTimeDuplicatedRows(
-      List<Integer> timeDuplicatedVectorRowIndexList,
-      long time,
-      Integer floatPrecision,
-      TSEncoding encoding) {
-    throw new UnsupportedOperationException(ERR_DATATYPE_NOT_CONSISTENT);
-  }
-
   @TestOnly
-  public IPointReader getIterator() {
-    return new Ite();
+  public TsBlock getTsBlock() {
+    return getTsBlock(0, TSEncoding.PLAIN, null);
   }
 
-  public IPointReader getIterator(
-      int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-    return new Ite(floatPrecision, encoding, size, deletionList);
-  }
-
-  protected class Ite implements IPointReader {
-
-    protected TimeValuePair cachedTimeValuePair;
-    protected boolean hasCachedPair;
-    protected int cur;
-    protected Integer floatPrecision;
-    private TSEncoding encoding;
-    private int deleteCursor = 0;
-    /**
-     * because TV list may be share with different query, each iterator has to record it's own size
-     */
-    protected int iteSize = 0;
-    /** this field is effective only in the Tvlist in a RealOnlyMemChunk. */
-    private List<TimeRange> deletionList;
-
-    public Ite() {
-      this.iteSize = TVList.this.rowCount;
-    }
-
-    public Ite(int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-      this.floatPrecision = floatPrecision;
-      this.encoding = encoding;
-      this.iteSize = size;
-      this.deletionList = deletionList;
-    }
-
-    @Override
-    public boolean hasNextTimeValuePair() {
-      if (hasCachedPair) {
-        return true;
-      }
-
-      while (cur < iteSize) {
-        long time = getTime(cur);
-        if (isPointDeleted(time) || (cur + 1 < rowCount() && (time == getTime(cur + 1)))) {
-          cur++;
-          continue;
-        }
-        TimeValuePair tvPair;
-        tvPair = getTimeValuePair(cur, time, floatPrecision, encoding);
-        cur++;
-        if (tvPair.getValue() != null) {
-          cachedTimeValuePair = tvPair;
-          hasCachedPair = true;
-          return true;
-        }
+  public TsBlock getTsBlock(int floatPrecision, TSEncoding encoding, List<TimeRange> deletionList) {
+    TsBlockBuilder builder = new TsBlockBuilder(Collections.singletonList(this.getDataType()));
+    // Time column
+    TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
+    int validRowCount = 0;
+    Integer deleteCursor = 0;

Review Comment:
   ```suggestion
       int deleteCursor = 0;
   ```



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/DoubleTVList.java:
##########
@@ -199,6 +201,22 @@ protected TimeValuePair getTimeValuePair(
     return new TimeValuePair(time, TsPrimitiveType.getByType(TSDataType.DOUBLE, value));
   }
 
+  @Override
+  protected void writeValidValuesIntoTsBlock(
+      ColumnBuilder valueBuilder,
+      int floatPrecision,
+      TSEncoding encoding,
+      List<TimeRange> deletionList) {
+    Integer deleteCursor = 0;

Review Comment:
   ```suggestion
       int deleteCursor = 0;
   ```



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/IntTVList.java:
##########
@@ -194,6 +196,21 @@ protected TimeValuePair getTimeValuePair(
     return new TimeValuePair(time, TsPrimitiveType.getByType(TSDataType.INT32, getInt(index)));
   }
 
+  @Override
+  protected void writeValidValuesIntoTsBlock(
+      ColumnBuilder valueBuilder,
+      int floatPrecision,
+      TSEncoding encoding,
+      List<TimeRange> deletionList) {
+    Integer deleteCursor = 0;

Review Comment:
   ```suggestion
       int deleteCursor = 0;
   ```



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/FloatTVList.java:
##########
@@ -199,6 +201,22 @@ protected TimeValuePair getTimeValuePair(
     return new TimeValuePair(time, TsPrimitiveType.getByType(TSDataType.FLOAT, value));
   }
 
+  @Override
+  protected void writeValidValuesIntoTsBlock(
+      ColumnBuilder valueBuilder,
+      int floatPrecision,
+      TSEncoding encoding,
+      List<TimeRange> deletionList) {
+    Integer deleteCursor = 0;

Review Comment:
   ```suggestion
       int deleteCursor = 0;
   ```



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemPageReader.java:
##########
@@ -54,92 +51,71 @@ public MemPageReader(
   public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
     TSDataType dataType = chunkMetadata.getDataType();
     BatchData batchData = BatchDataFactory.createBatchData(dataType, ascending, false);
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
       if (valueFilter == null
           || valueFilter.satisfy(
-              timeValuePair.getTimestamp(), timeValuePair.getValue().getValue())) {
-        batchData.putAnObject(timeValuePair.getTimestamp(), timeValuePair.getValue().getValue());
+              tsBlock.getTimeColumn().getLong(i), tsBlock.getColumn(0).getObject(i))) {
+        batchData.putAnObject(
+            tsBlock.getTimeColumn().getLong(i), tsBlock.getColumn(0).getObject(i));
       }
     }
     return batchData.flip();
   }
 
   @Override
-  public TsBlock getAllSatisfiedData() throws IOException {
+  public TsBlock getAllSatisfiedData() {
     TSDataType dataType = chunkMetadata.getDataType();
     TsBlockBuilder builder = new TsBlockBuilder(Collections.singletonList(dataType));
     TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      timeBuilder.writeLong(tsBlock.getTimeColumn().getLong(i));
+    }

Review Comment:
   put it into for loop.



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -96,45 +81,38 @@ public ReadOnlyMemChunk(
         floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
       }
     }
-
-    this.chunkData = tvList;
-    this.chunkDataSize = size;
-    this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        tvList.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-    initChunkMeta();
+    this.tsBlock = tvList.getTsBlock(floatPrecision, encoding, deletionList);
+    initChunkMetaFromTsBlock();
   }
 
-  private void initChunkMeta() throws IOException, QueryProcessException {
-    Statistics statsByType = Statistics.getStatsByType(dataType);
-    IChunkMetadata metaData = new ChunkMetadata(measurementUid, dataType, 0, statsByType);
+  private void initChunkMetaFromTsBlock() throws IOException, QueryProcessException {
+    Statistics statsByType = Statistics.getStatsByType(tsBlock.getColumn(0).getDataType());
+    IChunkMetadata metaData =
+        new ChunkMetadata(measurementUid, tsBlock.getColumn(0).getDataType(), 0, statsByType);

Review Comment:
   don't get data type from tsBlock.



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedChunkReader.java:
##########
@@ -20,82 +20,39 @@
 
 import org.apache.iotdb.db.engine.querycontext.AlignedReadOnlyMemChunk;
 import org.apache.iotdb.tsfile.file.metadata.AlignedChunkMetadata;
-import org.apache.iotdb.tsfile.read.TimeValuePair;
 import org.apache.iotdb.tsfile.read.common.BatchData;
 import org.apache.iotdb.tsfile.read.filter.basic.Filter;
 import org.apache.iotdb.tsfile.read.reader.IChunkReader;
 import org.apache.iotdb.tsfile.read.reader.IPageReader;
-import org.apache.iotdb.tsfile.read.reader.IPointReader;
 
-import java.io.IOException;
 import java.util.Collections;
 import java.util.List;
 
 /** To read aligned chunk data in memory */
-public class MemAlignedChunkReader implements IChunkReader, IPointReader {
+public class MemAlignedChunkReader implements IChunkReader {
 
-  private IPointReader timeValuePairIterator;
-  private Filter filter;
-  private boolean hasCachedTimeValuePair;
-  private TimeValuePair cachedTimeValuePair;
   private List<IPageReader> pageReaderList;
 
   public MemAlignedChunkReader(AlignedReadOnlyMemChunk readableChunk, Filter filter) {
-    timeValuePairIterator = readableChunk.getPointReader();
-    this.filter = filter;
     // we treat one ReadOnlyMemChunk as one Page
     this.pageReaderList =
         Collections.singletonList(
             new MemAlignedPageReader(
-                timeValuePairIterator,
+                readableChunk.getTsBlock(),
                 (AlignedChunkMetadata) readableChunk.getChunkMetaData(),
                 filter));
   }
 
   @Override
-  public boolean hasNextTimeValuePair() throws IOException {
-    if (hasCachedTimeValuePair) {
-      return true;
-    }
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      if (filter == null
-          || filter.satisfy(timeValuePair.getTimestamp(), timeValuePair.getValue().getValue())) {
-        hasCachedTimeValuePair = true;
-        cachedTimeValuePair = timeValuePair;
-        break;
-      }
-    }
-    return hasCachedTimeValuePair;
+  public boolean hasNextSatisfiedPage() {
+    // mem chunk reader should not reach here
+    return false;

Review Comment:
   throw exception.



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -96,45 +81,38 @@ public ReadOnlyMemChunk(
         floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
       }
     }
-
-    this.chunkData = tvList;
-    this.chunkDataSize = size;
-    this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        tvList.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-    initChunkMeta();
+    this.tsBlock = tvList.getTsBlock(floatPrecision, encoding, deletionList);
+    initChunkMetaFromTsBlock();
   }
 
-  private void initChunkMeta() throws IOException, QueryProcessException {
-    Statistics statsByType = Statistics.getStatsByType(dataType);
-    IChunkMetadata metaData = new ChunkMetadata(measurementUid, dataType, 0, statsByType);
+  private void initChunkMetaFromTsBlock() throws IOException, QueryProcessException {
+    Statistics statsByType = Statistics.getStatsByType(tsBlock.getColumn(0).getDataType());

Review Comment:
   don't get data type from tsBlock.



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/BooleanTVList.java:
##########
@@ -196,6 +198,21 @@ protected TimeValuePair getTimeValuePair(
         time, TsPrimitiveType.getByType(TSDataType.BOOLEAN, getBoolean(index)));
   }
 
+  @Override
+  protected void writeValidValuesIntoTsBlock(
+      ColumnBuilder valueBuilder,
+      int floatPrecision,
+      TSEncoding encoding,
+      List<TimeRange> deletionList) {
+    Integer deleteCursor = 0;

Review Comment:
   ```suggestion
       int deleteCursor = 0;
   ```



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -145,23 +123,22 @@ private void initChunkMeta() throws IOException, QueryProcessException {
   }
 
   public TSDataType getDataType() {
-    return dataType;
+    return tsBlock.getColumn(0).getDataType();

Review Comment:
   don't get data type from tsBlock.



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -96,45 +81,38 @@ public ReadOnlyMemChunk(
         floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
       }
     }
-
-    this.chunkData = tvList;
-    this.chunkDataSize = size;
-    this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        tvList.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-    initChunkMeta();
+    this.tsBlock = tvList.getTsBlock(floatPrecision, encoding, deletionList);
+    initChunkMetaFromTsBlock();
   }
 
-  private void initChunkMeta() throws IOException, QueryProcessException {
-    Statistics statsByType = Statistics.getStatsByType(dataType);
-    IChunkMetadata metaData = new ChunkMetadata(measurementUid, dataType, 0, statsByType);
+  private void initChunkMetaFromTsBlock() throws IOException, QueryProcessException {
+    Statistics statsByType = Statistics.getStatsByType(tsBlock.getColumn(0).getDataType());
+    IChunkMetadata metaData =
+        new ChunkMetadata(measurementUid, tsBlock.getColumn(0).getDataType(), 0, statsByType);
     if (!isEmpty()) {
-      IPointReader iterator =
-          chunkData.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-      while (iterator.hasNextTimeValuePair()) {
-        TimeValuePair timeValuePair = iterator.nextTimeValuePair();
-        switch (dataType) {
+      for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+        switch (tsBlock.getColumn(0).getDataType()) {

Review Comment:
   don't get data type from tsBlock.



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java:
##########
@@ -58,14 +55,12 @@ public BatchData getAllSatisfiedPageData() throws IOException {
   @Override
   public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
     BatchData batchData = BatchDataFactory.createBatchData(TSDataType.VECTOR, ascending, false);
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      TsPrimitiveType[] values = timeValuePair.getValue().getVector();
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
       // save the first not null value of each row
       Object firstNotNullObject = null;
-      for (TsPrimitiveType value : values) {
-        if (value != null) {
-          firstNotNullObject = value.getValue();
+      for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+        if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {

Review Comment:
   ```suggestion
           if (!tsBlock.getColumn(column).isNull(row)) {
   ```



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -96,45 +81,38 @@ public ReadOnlyMemChunk(
         floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
       }
     }
-
-    this.chunkData = tvList;
-    this.chunkDataSize = size;
-    this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        tvList.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-    initChunkMeta();
+    this.tsBlock = tvList.getTsBlock(floatPrecision, encoding, deletionList);
+    initChunkMetaFromTsBlock();
   }
 
-  private void initChunkMeta() throws IOException, QueryProcessException {
-    Statistics statsByType = Statistics.getStatsByType(dataType);
-    IChunkMetadata metaData = new ChunkMetadata(measurementUid, dataType, 0, statsByType);
+  private void initChunkMetaFromTsBlock() throws IOException, QueryProcessException {
+    Statistics statsByType = Statistics.getStatsByType(tsBlock.getColumn(0).getDataType());
+    IChunkMetadata metaData =
+        new ChunkMetadata(measurementUid, tsBlock.getColumn(0).getDataType(), 0, statsByType);
     if (!isEmpty()) {
-      IPointReader iterator =
-          chunkData.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-      while (iterator.hasNextTimeValuePair()) {
-        TimeValuePair timeValuePair = iterator.nextTimeValuePair();
-        switch (dataType) {
+      for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+        switch (tsBlock.getColumn(0).getDataType()) {

Review Comment:
   put switch-case outside of for-loop



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java:
##########
@@ -75,44 +70,59 @@ public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
       // accept AlignedPath with only one sub sensor
       if (firstNotNullObject != null
           && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        batchData.putVector(timeValuePair.getTimestamp(), values);
+              || valueFilter.satisfy(tsBlock.getTimeByIndex(row), firstNotNullObject))) {
+        TsPrimitiveType[] values = new TsPrimitiveType[tsBlock.getValueColumnCount()];
+        for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+          if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {
+            values[column] = tsBlock.getColumn(column).getTsPrimitiveType(row);
+          }
+        }
+        batchData.putVector(tsBlock.getTimeByIndex(row), values);
       }
     }
     return batchData.flip();
   }
 
   @Override
-  public TsBlock getAllSatisfiedData() throws IOException {
-    // TODO change from the row-based style to column-based style
+  public TsBlock getAllSatisfiedData() {
     TsBlockBuilder builder =
         new TsBlockBuilder(
             chunkMetadata.getValueChunkMetadataList().stream()
                 .map(IChunkMetadata::getDataType)
                 .collect(Collectors.toList()));
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      TsPrimitiveType[] values = timeValuePair.getValue().getVector();
-      // save the first not null value of each row
-      Object firstNotNullObject = null;
-      for (TsPrimitiveType value : values) {
-        if (value != null) {
-          firstNotNullObject = value.getValue();
-          break;
-        }
-      }
+
+    boolean[] valueSatisfyInfo = new boolean[tsBlock.getPositionCount()];
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+
       // if all the sub sensors' value are null in current time
       // or current row is not satisfied with the filter, just discard it
-      // TODO fix value filter firstNotNullObject, currently, if it's a value filter, it will only
+      // currently, if it's a value filter, it will only
       // accept AlignedPath with only one sub sensor
-      if (firstNotNullObject != null
-          && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        builder.getTimeColumnBuilder().writeLong(timeValuePair.getTimestamp());
-        for (int i = 0; i < values.length; i++) {
-          builder.getColumnBuilder(i).writeTsPrimitiveType(values[i]);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        if (column == 0) {
+          Object value = tsBlock.getColumn(column).getObject(row);
+          if (value != null && (valueFilter == null || valueFilter.satisfy(0, value))) {
+            builder.getColumnBuilder(column).writeObject(tsBlock.getColumn(column).getObject(row));
+            valueSatisfyInfo[row] = true;
+            builder.declarePosition();
+          }
+        } else {
+          if (valueSatisfyInfo[row]) {
+            if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {
+              builder
+                  .getColumnBuilder(column)
+                  .writeObject(tsBlock.getColumn(column).getObject(row));

Review Comment:
   use `ColumnBuilder write(Column column, int index);` in `ColumnBuilder` to avoid boxing and unboxing.



##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java:
##########
@@ -75,44 +70,59 @@ public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
       // accept AlignedPath with only one sub sensor
       if (firstNotNullObject != null
           && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        batchData.putVector(timeValuePair.getTimestamp(), values);
+              || valueFilter.satisfy(tsBlock.getTimeByIndex(row), firstNotNullObject))) {
+        TsPrimitiveType[] values = new TsPrimitiveType[tsBlock.getValueColumnCount()];
+        for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+          if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {
+            values[column] = tsBlock.getColumn(column).getTsPrimitiveType(row);
+          }
+        }
+        batchData.putVector(tsBlock.getTimeByIndex(row), values);
       }
     }
     return batchData.flip();
   }
 
   @Override
-  public TsBlock getAllSatisfiedData() throws IOException {
-    // TODO change from the row-based style to column-based style
+  public TsBlock getAllSatisfiedData() {
     TsBlockBuilder builder =
         new TsBlockBuilder(
             chunkMetadata.getValueChunkMetadataList().stream()
                 .map(IChunkMetadata::getDataType)
                 .collect(Collectors.toList()));
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      TsPrimitiveType[] values = timeValuePair.getValue().getVector();
-      // save the first not null value of each row
-      Object firstNotNullObject = null;
-      for (TsPrimitiveType value : values) {
-        if (value != null) {
-          firstNotNullObject = value.getValue();
-          break;
-        }
-      }
+
+    boolean[] valueSatisfyInfo = new boolean[tsBlock.getPositionCount()];
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+
       // if all the sub sensors' value are null in current time
       // or current row is not satisfied with the filter, just discard it
-      // TODO fix value filter firstNotNullObject, currently, if it's a value filter, it will only
+      // currently, if it's a value filter, it will only
       // accept AlignedPath with only one sub sensor
-      if (firstNotNullObject != null
-          && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        builder.getTimeColumnBuilder().writeLong(timeValuePair.getTimestamp());
-        for (int i = 0; i < values.length; i++) {
-          builder.getColumnBuilder(i).writeTsPrimitiveType(values[i]);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        if (column == 0) {
+          Object value = tsBlock.getColumn(column).getObject(row);
+          if (value != null && (valueFilter == null || valueFilter.satisfy(0, value))) {
+            builder.getColumnBuilder(column).writeObject(tsBlock.getColumn(column).getObject(row));

Review Comment:
   use `ColumnBuilder write(Column column, int index);` in `ColumnBuilder` to avoid boxing and unboxing.



##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java:
##########
@@ -903,45 +887,142 @@ public void clear() {
     clearSortedValue();
   }
 
-  @Override
-  @TestOnly
-  public IPointReader getIterator() {
-    return new AlignedIte();
-  }
+  /** Build TsBlock by column. */
+  public TsBlock buildTsBlock(
+      int floatPrecision, List<TSEncoding> encodingList, List<List<TimeRange>> deletionList) {
+    TsBlockBuilder builder = new TsBlockBuilder(dataTypes);
+    // Time column
+    TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
+    int validRowCount = 0;
+    boolean[] timeDuplicateInfo = null;
+    // time column
+    for (int sortedRowIndex = 0; sortedRowIndex < rowCount; sortedRowIndex++) {
+      if (sortedRowIndex == rowCount - 1
+          || getTime(sortedRowIndex) != getTime(sortedRowIndex + 1)) {
+        timeBuilder.writeLong(getTime(sortedRowIndex));
+        validRowCount++;
+      } else {
+        if (Objects.isNull(timeDuplicateInfo)) {
+          timeDuplicateInfo = new boolean[rowCount];
+        }
+        timeDuplicateInfo[sortedRowIndex] = true;
+      }
+    }
 
-  @Override
-  public IPointReader getIterator(
-      int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-    throw new UnsupportedOperationException(ERR_DATATYPE_NOT_CONSISTENT);
+    // value columns
+    for (int columnIndex = 0; columnIndex < dataTypes.size(); columnIndex++) {
+      // skip non-exist column
+      // when there is a non-exist column, the Column in TsBlock is null
+      if (Objects.isNull(dataTypes.get(columnIndex))) {

Review Comment:
   should never be null



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865567520


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);

Review Comment:
   Fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865617321


##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemPageReader.java:
##########
@@ -54,92 +51,71 @@ public MemPageReader(
   public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
     TSDataType dataType = chunkMetadata.getDataType();
     BatchData batchData = BatchDataFactory.createBatchData(dataType, ascending, false);
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
       if (valueFilter == null
           || valueFilter.satisfy(
-              timeValuePair.getTimestamp(), timeValuePair.getValue().getValue())) {
-        batchData.putAnObject(timeValuePair.getTimestamp(), timeValuePair.getValue().getValue());
+              tsBlock.getTimeColumn().getLong(i), tsBlock.getColumn(0).getObject(i))) {
+        batchData.putAnObject(
+            tsBlock.getTimeColumn().getLong(i), tsBlock.getColumn(0).getObject(i));
       }
     }
     return batchData.flip();
   }
 
   @Override
-  public TsBlock getAllSatisfiedData() throws IOException {
+  public TsBlock getAllSatisfiedData() {
     TSDataType dataType = chunkMetadata.getDataType();
     TsBlockBuilder builder = new TsBlockBuilder(Collections.singletonList(dataType));
     TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
+    for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+      timeBuilder.writeLong(tsBlock.getTimeColumn().getLong(i));
+    }

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] sonarcloud[bot] commented on pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#issuecomment-1116373452

   SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=apache_incubator-iotdb&pullRequest=5772)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT) [![E](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/E-16px.png 'E')](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT) [1 Security Hotspot](https://sonarcloud.io/project/security_hotspots?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL) [32 Code Smells](https://sonarcloud.io/project/issues?id=apache_incubator-iotdb&pullRequest=5772&resolved=false&types=CODE_SMELL)
   
   [![71.2%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/60-16px.png '71.2%')](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_coverage&view=list) [71.2% Coverage](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_coverage&view=list)  
   [![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=apache_incubator-iotdb&pullRequest=5772&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865572731


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java:
##########
@@ -44,121 +44,118 @@
 
 public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<List<TimeRange>> deletionList;
+  private final String timeChunkName;
 
-  private String measurementUid;
-  private TSDataType dataType;
-  private List<TSEncoding> encodingList;
+  private final List<String> valueChunkNames;
 
-  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
+  private final List<TSDataType> dataTypes;
 
-  private int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+  private final List<List<TimeRange>> deletionList;
 
-  private AlignedTVList chunkData;
+  private static final Logger logger = LoggerFactory.getLogger(AlignedReadOnlyMemChunk.class);
 
-  private int chunkDataSize;
+  private AlignedTVList chunkData;
 
   /**
    * The constructor for Aligned type.
    *
    * @param schema VectorMeasurementSchema
    * @param tvList VectorTvList
-   * @param size The Number of Chunk data points
    * @param deletionList The timeRange of deletionList
    */
   public AlignedReadOnlyMemChunk(
-      IMeasurementSchema schema, TVList tvList, int size, List<List<TimeRange>> deletionList)
-      throws IOException, QueryProcessException {
+      IMeasurementSchema schema, TVList tvList, List<List<TimeRange>> deletionList)
+      throws QueryProcessException {
     super();
-    this.measurementUid = schema.getMeasurementId();
-    this.dataType = schema.getType();
-
-    this.encodingList = ((VectorMeasurementSchema) schema).getSubMeasurementsTSEncodingList();
+    this.timeChunkName = schema.getMeasurementId();
+    this.valueChunkNames = schema.getSubMeasurementsList();
+    this.dataTypes = schema.getSubMeasurementsTSDataTypeList();
+    int floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
+    List<TSEncoding> encodingList = schema.getSubMeasurementsTSEncodingList();
     this.chunkData = (AlignedTVList) tvList;
-    this.chunkDataSize = size;
     this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        (chunkData).getAlignedIterator(floatPrecision, encodingList, chunkDataSize, deletionList);
-    initAlignedChunkMeta((VectorMeasurementSchema) schema);
+    this.tsBlock = chunkData.buildTsBlock(floatPrecision, encodingList, deletionList);
+    initAlignedChunkMetaFromTsBlock();
   }
 
-  private void initAlignedChunkMeta(VectorMeasurementSchema schema)
-      throws IOException, QueryProcessException {
-    AlignedTVList alignedChunkData = (AlignedTVList) chunkData;
-    List<String> measurementList = schema.getSubMeasurementsList();
-    List<TSDataType> dataTypeList = schema.getSubMeasurementsTSDataTypeList();
+  private void initAlignedChunkMetaFromTsBlock() throws QueryProcessException {
     // time chunk
     Statistics timeStatistics = Statistics.getStatsByType(TSDataType.VECTOR);
     IChunkMetadata timeChunkMetadata =
-        new ChunkMetadata(measurementUid, TSDataType.VECTOR, 0, timeStatistics);
+        new ChunkMetadata(timeChunkName, TSDataType.VECTOR, 0, timeStatistics);
     List<IChunkMetadata> valueChunkMetadataList = new ArrayList<>();
     // update time chunk
-    for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-      timeStatistics.update(alignedChunkData.getTime(row));
+    for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+      timeStatistics.update(tsBlock.getTimeColumn().getLong(row));
     }
     timeStatistics.setEmpty(false);
     // update value chunk
-    for (int column = 0; column < measurementList.size(); column++) {
-      Statistics valueStatistics = Statistics.getStatsByType(dataTypeList.get(column));
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(
-              measurementList.get(column), dataTypeList.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
-      if (alignedChunkData.getValues().get(column) == null) {
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+      // empty value chunk for non-exist value column
+      if (tsBlock.getColumn(column) == null) {
+        Statistics valueStatistics = Statistics.getStatsByType(dataTypes.get(column));
         valueStatistics.setEmpty(true);
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
         continue;
       }
-      for (int row = 0; row < alignedChunkData.rowCount(); row++) {
-        long time = alignedChunkData.getTime(row);
-        int originRowIndex = alignedChunkData.getValueIndex(row);
-        boolean isNull = alignedChunkData.isValueMarked(originRowIndex, column);
-        if (isNull) {
+      Statistics valueStatistics =
+          Statistics.getStatsByType(tsBlock.getColumn(column).getDataType());

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865566044


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -45,44 +45,29 @@
  */
 public class ReadOnlyMemChunk {
 
-  // deletion list for this chunk
-  private final List<TimeRange> deletionList;
-
   private String measurementUid;
-  private TSDataType dataType;

Review Comment:
   Fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865580748


##########
tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/block/TsBlockBuilder.java:
##########
@@ -95,6 +95,9 @@ private TsBlockBuilder(int initialExpectedEntries, int maxTsBlockBytes, List<TSD
     for (int i = 0; i < valueColumnBuilders.length; i++) {
       // TODO use Type interface to encapsulate createColumnBuilder to each concrete type class
       // instead of switch-case
+      if (types.get(i) == null) {
+        continue;
+      }

Review Comment:
   Fixed



##########
tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/block/TsBlockBuilder.java:
##########
@@ -293,6 +296,9 @@ public TsBlock build() {
 
     Column[] columns = new Column[valueColumnBuilders.length];
     for (int i = 0; i < columns.length; i++) {
+      if (valueColumnBuilders[i] == null) {
+        continue;
+      }

Review Comment:
   Fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865620099


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -96,45 +81,38 @@ public ReadOnlyMemChunk(
         floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
       }
     }
-
-    this.chunkData = tvList;
-    this.chunkDataSize = size;
-    this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        tvList.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-    initChunkMeta();
+    this.tsBlock = tvList.getTsBlock(floatPrecision, encoding, deletionList);
+    initChunkMetaFromTsBlock();
   }
 
-  private void initChunkMeta() throws IOException, QueryProcessException {
-    Statistics statsByType = Statistics.getStatsByType(dataType);
-    IChunkMetadata metaData = new ChunkMetadata(measurementUid, dataType, 0, statsByType);
+  private void initChunkMetaFromTsBlock() throws IOException, QueryProcessException {
+    Statistics statsByType = Statistics.getStatsByType(tsBlock.getColumn(0).getDataType());
+    IChunkMetadata metaData =
+        new ChunkMetadata(measurementUid, tsBlock.getColumn(0).getDataType(), 0, statsByType);

Review Comment:
   fixed



##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -96,45 +81,38 @@ public ReadOnlyMemChunk(
         floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
       }
     }
-
-    this.chunkData = tvList;
-    this.chunkDataSize = size;
-    this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        tvList.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-    initChunkMeta();
+    this.tsBlock = tvList.getTsBlock(floatPrecision, encoding, deletionList);
+    initChunkMetaFromTsBlock();
   }
 
-  private void initChunkMeta() throws IOException, QueryProcessException {
-    Statistics statsByType = Statistics.getStatsByType(dataType);
-    IChunkMetadata metaData = new ChunkMetadata(measurementUid, dataType, 0, statsByType);
+  private void initChunkMetaFromTsBlock() throws IOException, QueryProcessException {
+    Statistics statsByType = Statistics.getStatsByType(tsBlock.getColumn(0).getDataType());
+    IChunkMetadata metaData =
+        new ChunkMetadata(measurementUid, tsBlock.getColumn(0).getDataType(), 0, statsByType);
     if (!isEmpty()) {
-      IPointReader iterator =
-          chunkData.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-      while (iterator.hasNextTimeValuePair()) {
-        TimeValuePair timeValuePair = iterator.nextTimeValuePair();
-        switch (dataType) {
+      for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+        switch (tsBlock.getColumn(0).getDataType()) {

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865619430


##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedChunkReader.java:
##########
@@ -20,82 +20,39 @@
 
 import org.apache.iotdb.db.engine.querycontext.AlignedReadOnlyMemChunk;
 import org.apache.iotdb.tsfile.file.metadata.AlignedChunkMetadata;
-import org.apache.iotdb.tsfile.read.TimeValuePair;
 import org.apache.iotdb.tsfile.read.common.BatchData;
 import org.apache.iotdb.tsfile.read.filter.basic.Filter;
 import org.apache.iotdb.tsfile.read.reader.IChunkReader;
 import org.apache.iotdb.tsfile.read.reader.IPageReader;
-import org.apache.iotdb.tsfile.read.reader.IPointReader;
 
-import java.io.IOException;
 import java.util.Collections;
 import java.util.List;
 
 /** To read aligned chunk data in memory */
-public class MemAlignedChunkReader implements IChunkReader, IPointReader {
+public class MemAlignedChunkReader implements IChunkReader {
 
-  private IPointReader timeValuePairIterator;
-  private Filter filter;
-  private boolean hasCachedTimeValuePair;
-  private TimeValuePair cachedTimeValuePair;
   private List<IPageReader> pageReaderList;
 
   public MemAlignedChunkReader(AlignedReadOnlyMemChunk readableChunk, Filter filter) {
-    timeValuePairIterator = readableChunk.getPointReader();
-    this.filter = filter;
     // we treat one ReadOnlyMemChunk as one Page
     this.pageReaderList =
         Collections.singletonList(
             new MemAlignedPageReader(
-                timeValuePairIterator,
+                readableChunk.getTsBlock(),
                 (AlignedChunkMetadata) readableChunk.getChunkMetaData(),
                 filter));
   }
 
   @Override
-  public boolean hasNextTimeValuePair() throws IOException {
-    if (hasCachedTimeValuePair) {
-      return true;
-    }
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      if (filter == null
-          || filter.satisfy(timeValuePair.getTimestamp(), timeValuePair.getValue().getValue())) {
-        hasCachedTimeValuePair = true;
-        cachedTimeValuePair = timeValuePair;
-        break;
-      }
-    }
-    return hasCachedTimeValuePair;
+  public boolean hasNextSatisfiedPage() {
+    // mem chunk reader should not reach here
+    return false;
   }
 
   @Override
-  public TimeValuePair nextTimeValuePair() throws IOException {
-    if (hasCachedTimeValuePair) {
-      hasCachedTimeValuePair = false;
-      return cachedTimeValuePair;
-    } else {
-      return timeValuePairIterator.nextTimeValuePair();
-    }
-  }
-
-  @Override
-  public TimeValuePair currentTimeValuePair() throws IOException {
-    if (!hasCachedTimeValuePair) {
-      cachedTimeValuePair = timeValuePairIterator.nextTimeValuePair();
-      hasCachedTimeValuePair = true;
-    }
-    return cachedTimeValuePair;
-  }
-
-  @Override
-  public boolean hasNextSatisfiedPage() throws IOException {
-    return hasNextTimeValuePair();
-  }
-
-  @Override
-  public BatchData nextPageData() throws IOException {
-    return pageReaderList.remove(0).getAllSatisfiedPageData();
+  public BatchData nextPageData() {
+    // mem chunk reader should not reach here
+    return null;

Review Comment:
   Fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865620319


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -96,45 +81,38 @@ public ReadOnlyMemChunk(
         floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
       }
     }
-
-    this.chunkData = tvList;
-    this.chunkDataSize = size;
-    this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        tvList.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-    initChunkMeta();
+    this.tsBlock = tvList.getTsBlock(floatPrecision, encoding, deletionList);
+    initChunkMetaFromTsBlock();
   }
 
-  private void initChunkMeta() throws IOException, QueryProcessException {
-    Statistics statsByType = Statistics.getStatsByType(dataType);
-    IChunkMetadata metaData = new ChunkMetadata(measurementUid, dataType, 0, statsByType);
+  private void initChunkMetaFromTsBlock() throws IOException, QueryProcessException {
+    Statistics statsByType = Statistics.getStatsByType(tsBlock.getColumn(0).getDataType());
+    IChunkMetadata metaData =
+        new ChunkMetadata(measurementUid, tsBlock.getColumn(0).getDataType(), 0, statsByType);
     if (!isEmpty()) {
-      IPointReader iterator =
-          chunkData.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-      while (iterator.hasNextTimeValuePair()) {
-        TimeValuePair timeValuePair = iterator.nextTimeValuePair();
-        switch (dataType) {
+      for (int i = 0; i < tsBlock.getPositionCount(); i++) {
+        switch (tsBlock.getColumn(0).getDataType()) {

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865619862


##########
server/src/main/java/org/apache/iotdb/db/engine/querycontext/ReadOnlyMemChunk.java:
##########
@@ -96,45 +81,38 @@ public ReadOnlyMemChunk(
         floatPrecision = TSFileDescriptor.getInstance().getConfig().getFloatPrecision();
       }
     }
-
-    this.chunkData = tvList;
-    this.chunkDataSize = size;
-    this.deletionList = deletionList;
-
-    this.chunkPointReader =
-        tvList.getIterator(floatPrecision, encoding, chunkDataSize, deletionList);
-    initChunkMeta();
+    this.tsBlock = tvList.getTsBlock(floatPrecision, encoding, deletionList);
+    initChunkMetaFromTsBlock();
   }
 
-  private void initChunkMeta() throws IOException, QueryProcessException {
-    Statistics statsByType = Statistics.getStatsByType(dataType);
-    IChunkMetadata metaData = new ChunkMetadata(measurementUid, dataType, 0, statsByType);
+  private void initChunkMetaFromTsBlock() throws IOException, QueryProcessException {
+    Statistics statsByType = Statistics.getStatsByType(tsBlock.getColumn(0).getDataType());

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865630400


##########
server/src/main/java/org/apache/iotdb/db/query/reader/chunk/MemAlignedPageReader.java:
##########
@@ -75,44 +70,59 @@ public BatchData getAllSatisfiedPageData(boolean ascending) throws IOException {
       // accept AlignedPath with only one sub sensor
       if (firstNotNullObject != null
           && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        batchData.putVector(timeValuePair.getTimestamp(), values);
+              || valueFilter.satisfy(tsBlock.getTimeByIndex(row), firstNotNullObject))) {
+        TsPrimitiveType[] values = new TsPrimitiveType[tsBlock.getValueColumnCount()];
+        for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+          if (tsBlock.getColumn(column) != null && !tsBlock.getColumn(column).isNull(row)) {
+            values[column] = tsBlock.getColumn(column).getTsPrimitiveType(row);
+          }
+        }
+        batchData.putVector(tsBlock.getTimeByIndex(row), values);
       }
     }
     return batchData.flip();
   }
 
   @Override
-  public TsBlock getAllSatisfiedData() throws IOException {
-    // TODO change from the row-based style to column-based style
+  public TsBlock getAllSatisfiedData() {
     TsBlockBuilder builder =
         new TsBlockBuilder(
             chunkMetadata.getValueChunkMetadataList().stream()
                 .map(IChunkMetadata::getDataType)
                 .collect(Collectors.toList()));
-    while (timeValuePairIterator.hasNextTimeValuePair()) {
-      TimeValuePair timeValuePair = timeValuePairIterator.nextTimeValuePair();
-      TsPrimitiveType[] values = timeValuePair.getValue().getVector();
-      // save the first not null value of each row
-      Object firstNotNullObject = null;
-      for (TsPrimitiveType value : values) {
-        if (value != null) {
-          firstNotNullObject = value.getValue();
-          break;
-        }
-      }
+
+    boolean[] valueSatisfyInfo = new boolean[tsBlock.getPositionCount()];
+    for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
+
       // if all the sub sensors' value are null in current time
       // or current row is not satisfied with the filter, just discard it
-      // TODO fix value filter firstNotNullObject, currently, if it's a value filter, it will only
+      // currently, if it's a value filter, it will only
       // accept AlignedPath with only one sub sensor
-      if (firstNotNullObject != null
-          && (valueFilter == null
-              || valueFilter.satisfy(timeValuePair.getTimestamp(), firstNotNullObject))) {
-        builder.getTimeColumnBuilder().writeLong(timeValuePair.getTimestamp());
-        for (int i = 0; i < values.length; i++) {
-          builder.getColumnBuilder(i).writeTsPrimitiveType(values[i]);
+      for (int row = 0; row < tsBlock.getPositionCount(); row++) {
+        if (column == 0) {
+          Object value = tsBlock.getColumn(column).getObject(row);
+          if (value != null && (valueFilter == null || valueFilter.satisfy(0, value))) {

Review Comment:
   fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb] HTHou commented on a diff in pull request #5772: [IOTDB-3093] Use TsBlock to query data in TVList

Posted by GitBox <gi...@apache.org>.
HTHou commented on code in PR #5772:
URL: https://github.com/apache/iotdb/pull/5772#discussion_r865801797


##########
server/src/main/java/org/apache/iotdb/db/utils/datastructure/TVList.java:
##########
@@ -513,107 +510,66 @@ void updateMinTimeAndSorted(long[] time, int start, int end) {
   protected abstract TimeValuePair getTimeValuePair(
       int index, long time, Integer floatPrecision, TSEncoding encoding);
 
-  public TimeValuePair getTimeValuePairForTimeDuplicatedRows(
-      List<Integer> timeDuplicatedVectorRowIndexList,
-      long time,
-      Integer floatPrecision,
-      TSEncoding encoding) {
-    throw new UnsupportedOperationException(ERR_DATATYPE_NOT_CONSISTENT);
-  }
-
   @TestOnly
-  public IPointReader getIterator() {
-    return new Ite();
+  public TsBlock getTsBlock() {
+    return getTsBlock(0, TSEncoding.PLAIN, null);
   }
 
-  public IPointReader getIterator(
-      int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-    return new Ite(floatPrecision, encoding, size, deletionList);
-  }
-
-  protected class Ite implements IPointReader {
-
-    protected TimeValuePair cachedTimeValuePair;
-    protected boolean hasCachedPair;
-    protected int cur;
-    protected Integer floatPrecision;
-    private TSEncoding encoding;
-    private int deleteCursor = 0;
-    /**
-     * because TV list may be share with different query, each iterator has to record it's own size
-     */
-    protected int iteSize = 0;
-    /** this field is effective only in the Tvlist in a RealOnlyMemChunk. */
-    private List<TimeRange> deletionList;
-
-    public Ite() {
-      this.iteSize = TVList.this.rowCount;
-    }
-
-    public Ite(int floatPrecision, TSEncoding encoding, int size, List<TimeRange> deletionList) {
-      this.floatPrecision = floatPrecision;
-      this.encoding = encoding;
-      this.iteSize = size;
-      this.deletionList = deletionList;
-    }
-
-    @Override
-    public boolean hasNextTimeValuePair() {
-      if (hasCachedPair) {
-        return true;
-      }
-
-      while (cur < iteSize) {
-        long time = getTime(cur);
-        if (isPointDeleted(time) || (cur + 1 < rowCount() && (time == getTime(cur + 1)))) {
-          cur++;
-          continue;
-        }
-        TimeValuePair tvPair;
-        tvPair = getTimeValuePair(cur, time, floatPrecision, encoding);
-        cur++;
-        if (tvPair.getValue() != null) {
-          cachedTimeValuePair = tvPair;
-          hasCachedPair = true;
-          return true;
-        }
+  public TsBlock getTsBlock(int floatPrecision, TSEncoding encoding, List<TimeRange> deletionList) {
+    TsBlockBuilder builder = new TsBlockBuilder(Collections.singletonList(this.getDataType()));
+    // Time column
+    TimeColumnBuilder timeBuilder = builder.getTimeColumnBuilder();
+    int validRowCount = 0;
+    Integer deleteCursor = 0;
+    for (int i = 0; i < rowCount; i++) {
+      if (!isPointDeleted(getTime(i), deletionList, deleteCursor)
+          && (i == rowCount - 1 || getTime(i) != getTime(i + 1))) {
+        timeBuilder.writeLong(this.getTime(i));

Review Comment:
   Fixed



-- 
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: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org