carbondata-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipesala <...@git.apache.org>
Subject [GitHub] carbondata pull request #1238: [CARBONDATA-1363] Add DataMapWriter interface
Date Mon, 07 Aug 2017 06:26:28 GMT
Github user ravipesala commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1238#discussion_r131579700
  
    --- Diff: processing/src/main/java/org/apache/carbondata/processing/store/writer/v3/CarbonFactDataWriterImplV3.java
---
    @@ -100,88 +104,117 @@ public CarbonFactDataWriterImplV3(CarbonDataWriterVo dataWriterVo)
{
       }
     
       /**
    -   * Below method will be used to write one table page data
    +   * Below method will be used to write one table page data, invoked by Consumer
    +   * @param tablePage
        */
    -  @Override public void writeTablePage(EncodedTablePage encodedTablePage)
    +  @Override public void writeTablePage(TablePage tablePage)
           throws CarbonDataWriterException {
         // condition for writting all the pages
    -    if (!encodedTablePage.isLastPage()) {
    +    if (!tablePage.isLastPage()) {
           boolean isAdded = false;
           // check if size more than blocklet size then write the page to file
    -      if (dataWriterHolder.getSize() + encodedTablePage.getEncodedSize() >= blockletSize)
{
    -        // if one page size is more than blocklet size
    -        if (dataWriterHolder.getEncodedTablePages().size() == 0) {
    +      if (blockletDataHolder.getSize() + tablePage.getEncodedTablePage().getEncodedSize()
>=
    +          blockletSizeThreshold) {
    +        // if blocklet size exceeds threshold, write blocklet data
    +        if (blockletDataHolder.getEncodedTablePages().size() == 0) {
               isAdded = true;
    -          dataWriterHolder.addPage(encodedTablePage);
    +          blockletDataHolder.addPage(tablePage);
             }
     
    -        LOGGER.info("Number of Pages for blocklet is: " + dataWriterHolder.getNumberOfPagesAdded()
    -            + " :Rows Added: " + dataWriterHolder.getTotalRows());
    +        LOGGER.info("Number of Pages for blocklet is: " + blockletDataHolder.getNumberOfPagesAdded()
    +            + " :Rows Added: " + blockletDataHolder.getTotalRows());
    +
             // write the data
             writeBlockletToFile();
    +
           }
           if (!isAdded) {
    -        dataWriterHolder.addPage(encodedTablePage);
    +        blockletDataHolder.addPage(tablePage);
           }
         } else {
           //for last blocklet check if the last page will exceed the blocklet size then write
           // existing pages and then last page
    -      if (encodedTablePage.getPageSize() > 0) {
    -        dataWriterHolder.addPage(encodedTablePage);
    +
    +      if (tablePage.getPageSize() > 0) {
    +        blockletDataHolder.addPage(tablePage);
           }
    -      if (dataWriterHolder.getNumberOfPagesAdded() > 0) {
    -        LOGGER.info("Number of Pages for blocklet is: " + dataWriterHolder.getNumberOfPagesAdded()
    -            + " :Rows Added: " + dataWriterHolder.getTotalRows());
    +      if (blockletDataHolder.getNumberOfPagesAdded() > 0) {
    +        LOGGER.info("Number of Pages for blocklet is: " + blockletDataHolder.getNumberOfPagesAdded()
    +            + " :Rows Added: " + blockletDataHolder.getTotalRows());
             writeBlockletToFile();
           }
         }
       }
     
       /**
    -   * Write one blocklet data to file
    +   * Write the collect blocklet data (blockletDataHolder) to file
        */
       private void writeBlockletToFile() {
         // get the list of all encoded table page
    -    List<EncodedTablePage> encodedTablePageList = dataWriterHolder.getEncodedTablePages();
    +    List<EncodedTablePage> encodedTablePageList = blockletDataHolder.getEncodedTablePages();
         int numDimensions = encodedTablePageList.get(0).getNumDimensions();
         int numMeasures = encodedTablePageList.get(0).getNumMeasures();
    -    long blockletDataSize = 0;
         // get data chunks for all the column
         byte[][] dataChunkBytes = new byte[numDimensions + numMeasures][];
    +    long metadataSize = fillDataChunk(encodedTablePageList, dataChunkBytes);
    +    // calculate the total size of data to be written
    +    long blockletSize = blockletDataHolder.getSize() + metadataSize;
    +    // to check if data size will exceed the block size then create a new file
    +    createNewFileIfReachThreshold(blockletSize);
    +    notifyDataMapBlockletCommit();
    +
    +    // write data to file
    +    try {
    +      if (fileChannel.size() == 0) {
    +        // write the header if file is empty
    +        writeHeaderToFile(fileChannel);
    +      }
    +      writeBlockletToFile(fileChannel, dataChunkBytes);
    +    } catch (IOException e) {
    +      throw new CarbonDataWriterException("Problem when writing file", e);
    +    }
    +    // clear the data holder
    +    blockletDataHolder.clear();
    +  }
    +
    +  private void notifyDataMapBlockletCommit() {
    --- End diff --
    
    I think we should not wait till all pages are collected as it will increase the memory
and also slows down. Better add tablepage to datamapwriter as soon as Consumer calls `writeTablePage`
method. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message