You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@carbondata.apache.org by GitBox <gi...@apache.org> on 2020/03/19 08:44:24 UTC

[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3672: [CRBONDATA-3746] Support column chunk cache in reader

ajantha-bhat commented on a change in pull request #3672: [CRBONDATA-3746] Support column chunk cache in reader
URL: https://github.com/apache/carbondata/pull/3672#discussion_r394867202
 
 

 ##########
 File path: core/src/main/java/org/apache/carbondata/core/indexstore/blockletindex/BlockletDataRefNode.java
 ##########
 @@ -133,35 +139,107 @@ public short blockletIndex() {
   }
 
   @Override
-  public DimensionRawColumnChunk[] readDimensionChunks(FileReader fileReader, int[][] blockIndexes)
+  public DimensionRawColumnChunk[] readDimensionChunks(FileReader fileReader, int[][] columnIndexes)
       throws IOException {
-    DimensionColumnChunkReader dimensionChunksReader = getDimensionColumnChunkReader(fileReader);
-    return dimensionChunksReader.readRawDimensionChunks(fileReader, blockIndexes);
+    TableBlockInfo blockInfo = blockInfos.get(index);
+    if (ColumnChunkCache.isEnabledForTable(tableId)) {
+      DimensionRawColumnChunk[] chunks = new DimensionRawColumnChunk[
+          blockInfo.getDetailInfo().getBlockletInfo().getDimensionChunkOffsets().size()];
+      for (int[] columnIndex : columnIndexes) {
+        int columnIndexStart = columnIndex[0];
+        int columnIndexEnd = columnIndex[1];
+        for (int j = columnIndexStart; j <= columnIndexEnd; j++) {
+          ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey(
+              blockInfo.getFilePath(),
+              blockInfo.getDetailInfo().getBlockletInfo().getDimensionChunkOffsets().get(j));
+          Optional<AbstractRawColumnChunk> chunkOp = ColumnChunkCache.get(tableId, key);
+          if (chunkOp.isPresent()) {
+            chunks[j] = (DimensionRawColumnChunk) chunkOp.get();
+          } else {
+            chunks[j] = readDimensionChunkWithoutCache(fileReader, j);
+            ColumnChunkCache.put(tableId, key, chunks[j]);
+          }
+        }
+      }
+      return chunks;
+    } else {
+      DimensionColumnChunkReader dimensionChunksReader = getDimensionColumnChunkReader(fileReader);
+      return dimensionChunksReader.readRawDimensionChunks(fileReader, columnIndexes);
+    }
   }
 
   @Override
   public DimensionRawColumnChunk readDimensionChunk(FileReader fileReader, int columnIndex)
       throws IOException {
-    DimensionColumnChunkReader dimensionChunksReader = getDimensionColumnChunkReader(fileReader);
-    return dimensionChunksReader.readRawDimensionChunk(fileReader, columnIndex);
+    TableBlockInfo blockInfo = blockInfos.get(index);
+    ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey(
+        blockInfo.getFilePath(),
+        blockInfo.getDetailInfo().getBlockletInfo().getDimensionChunkOffsets().get(columnIndex));
+    Optional<AbstractRawColumnChunk> columnChunkOp = ColumnChunkCache.get(tableId, key);
+    if (columnChunkOp.isPresent()) {
+      return (DimensionRawColumnChunk) columnChunkOp.get();
+    }
+    DimensionRawColumnChunk chunk = readDimensionChunkWithoutCache(fileReader, columnIndex);
+    ColumnChunkCache.put(tableId, key, chunk);
+    return chunk;
+  }
+
+  private DimensionRawColumnChunk readDimensionChunkWithoutCache(
+      FileReader fileReader, int columnIndex) throws IOException {
+    DimensionColumnChunkReader reader = getDimensionColumnChunkReader(fileReader);
+    return reader.readRawDimensionChunk(fileReader, columnIndex);
+  }
+
+  private MeasureRawColumnChunk readMeasureChunkWithoutCache(
+      FileReader fileReader, int columnIndex) throws IOException {
+    MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader);
+    return measureColumnChunkReader.readRawMeasureChunk(fileReader, columnIndex);
   }
 
   @Override
-  public MeasureRawColumnChunk[] readMeasureChunks(FileReader fileReader, int[][] columnIndexRange)
+  public MeasureRawColumnChunk[] readMeasureChunks(FileReader fileReader, int[][] columnIndexes)
       throws IOException {
-    MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader);
-    MeasureRawColumnChunk[] measureRawColumnChunks =
-        measureColumnChunkReader.readRawMeasureChunks(fileReader, columnIndexRange);
-    return measureRawColumnChunks;
+    TableBlockInfo blockInfo = blockInfos.get(index);
+    if (ColumnChunkCache.isEnabledForTable(tableId)) {
+      MeasureRawColumnChunk[] chunks = new MeasureRawColumnChunk[
+          blockInfo.getDetailInfo().getBlockletInfo().getMeasureChunkOffsets().size()];
+      for (int[] columnIndex : columnIndexes) {
+        int columnIndexStart = columnIndex[0];
+        int columnIndexEnd = columnIndex[1];
+        for (int j = columnIndexStart; j <= columnIndexEnd; j++) {
+          ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey(
+              blockInfo.getFilePath(),
+              blockInfo.getDetailInfo().getBlockletInfo().getMeasureChunkOffsets().get(j));
+          Optional<AbstractRawColumnChunk> chunkOp = ColumnChunkCache.get(tableId, key);
+          if (chunkOp.isPresent()) {
+            chunks[j] = (MeasureRawColumnChunk) chunkOp.get();
+          } else {
+            chunks[j] = readMeasureChunkWithoutCache(fileReader, j);
+            ColumnChunkCache.put(tableId, key, chunks[j]);
+          }
+        }
+      }
+      return chunks;
+    } else {
+      MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader);
+      return measureColumnChunkReader.readRawMeasureChunks(fileReader, columnIndexes);
+    }
   }
 
   @Override
   public MeasureRawColumnChunk readMeasureChunk(FileReader fileReader, int columnIndex)
       throws IOException {
-    MeasureColumnChunkReader measureColumnChunkReader = getMeasureColumnChunkReader(fileReader);
-    MeasureRawColumnChunk measureRawColumnChunk =
-        measureColumnChunkReader.readRawMeasureChunk(fileReader, columnIndex);
-    return measureRawColumnChunk;
+    TableBlockInfo blockInfo = blockInfos.get(index);
+    ColumnChunkCache.CacheKey key = new ColumnChunkCache.CacheKey(
+        blockInfo.getFilePath(),
 
 Review comment:
   If the task distribution is '`blocklet`' instead of `block` to get the splits in the driver. Two splits may have  same block but different blocklet id. In that cache will be overwritten for the last blokclet.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services