carbondata-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gvramana <...@git.apache.org>
Subject [GitHub] incubator-carbondata pull request #641: [CARBONDATA-767] Alter table support...
Date Tue, 14 Mar 2017 13:33:26 GMT
Github user gvramana commented on a diff in the pull request:

    https://github.com/apache/incubator-carbondata/pull/641#discussion_r105879703
  
    --- Diff: core/src/main/java/org/apache/carbondata/core/scan/collector/impl/RestructureBasedVectorResultCollector.java
---
    @@ -0,0 +1,321 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.carbondata.core.scan.collector.impl;
    +
    +import java.math.BigDecimal;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.List;
    +
    +import org.apache.carbondata.core.keygenerator.directdictionary.DirectDictionaryKeyGeneratorFactory;
    +import org.apache.carbondata.core.metadata.encoder.Encoding;
    +import org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension;
    +import org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure;
    +import org.apache.carbondata.core.scan.executor.infos.BlockExecutionInfo;
    +import org.apache.carbondata.core.scan.model.QueryDimension;
    +import org.apache.carbondata.core.scan.model.QueryMeasure;
    +import org.apache.carbondata.core.scan.result.AbstractScannedResult;
    +import org.apache.carbondata.core.scan.result.vector.CarbonColumnVector;
    +import org.apache.carbondata.core.scan.result.vector.CarbonColumnarBatch;
    +import org.apache.carbondata.core.scan.result.vector.ColumnVectorInfo;
    +import org.apache.carbondata.core.scan.result.vector.MeasureDataVectorProcessor;
    +
    +import org.apache.spark.sql.types.Decimal;
    +
    +/**
    + * It is not a collector it is just a scanned result holder.
    + */
    +public class RestructureBasedVectorResultCollector extends AbstractScannedResultCollector
{
    +
    +  private ColumnVectorInfo[] dictionaryInfo;
    +
    +  private ColumnVectorInfo[] noDictionaryInfo;
    +
    +  private ColumnVectorInfo[] complexInfo;
    +
    +  private ColumnVectorInfo[] measureColumnInfo;
    +
    +  private ColumnVectorInfo[] allColumnInfo;
    +
    +  public RestructureBasedVectorResultCollector(BlockExecutionInfo blockExecutionInfos)
{
    +    super(blockExecutionInfos);
    +    QueryDimension[] queryDimensions = tableBlockExecutionInfos.getActualQueryDimensions();
    +    QueryMeasure[] queryMeasures = tableBlockExecutionInfos.getActualQueryMeasures();
    +    measureColumnInfo = new ColumnVectorInfo[queryMeasures.length];
    +    allColumnInfo = new ColumnVectorInfo[queryDimensions.length + queryMeasures.length];
    +    List<ColumnVectorInfo> dictInfoList = new ArrayList<>();
    +    List<ColumnVectorInfo> noDictInfoList = new ArrayList<>();
    +    List<ColumnVectorInfo> complexList = new ArrayList<>();
    +    int dimensionExistIndex = 0;
    +    for (int i = 0; i < queryDimensions.length; i++) {
    +      if (!dimensionInfo.getDimensionExists()[i]) {
    +        // add a dummy column vector result collector object
    +        ColumnVectorInfo columnVectorInfo = new ColumnVectorInfo();
    +        allColumnInfo[queryDimensions[i].getQueryOrder()] = columnVectorInfo;
    +        continue;
    +      }
    +      // get the current block dimension and fetch the required information from it
    +      QueryDimension currentBlockDimension =
    +          tableBlockExecutionInfos.getQueryDimensions()[dimensionExistIndex++];
    +      if (!queryDimensions[i].getDimension().hasEncoding(Encoding.DICTIONARY)) {
    +        ColumnVectorInfo columnVectorInfo = new ColumnVectorInfo();
    +        noDictInfoList.add(columnVectorInfo);
    +        columnVectorInfo.dimension = currentBlockDimension;
    +        columnVectorInfo.ordinal = currentBlockDimension.getDimension().getOrdinal();
    +        allColumnInfo[queryDimensions[i].getQueryOrder()] = columnVectorInfo;
    +      } else if (queryDimensions[i].getDimension().hasEncoding(Encoding.DIRECT_DICTIONARY))
{
    +        ColumnVectorInfo columnVectorInfo = new ColumnVectorInfo();
    +        dictInfoList.add(columnVectorInfo);
    +        columnVectorInfo.dimension = currentBlockDimension;
    +        columnVectorInfo.directDictionaryGenerator = DirectDictionaryKeyGeneratorFactory
    +            .getDirectDictionaryGenerator(currentBlockDimension.getDimension().getDataType());
    +        columnVectorInfo.ordinal = currentBlockDimension.getDimension().getOrdinal();
    +        allColumnInfo[queryDimensions[i].getQueryOrder()] = columnVectorInfo;
    +      } else if (queryDimensions[i].getDimension().isComplex()) {
    +        ColumnVectorInfo columnVectorInfo = new ColumnVectorInfo();
    +        complexList.add(columnVectorInfo);
    +        columnVectorInfo.dimension = currentBlockDimension;
    +        columnVectorInfo.ordinal = currentBlockDimension.getDimension().getOrdinal();
    +        columnVectorInfo.genericQueryType =
    +            tableBlockExecutionInfos.getComlexDimensionInfoMap().get(columnVectorInfo.ordinal);
    +        allColumnInfo[queryDimensions[i].getQueryOrder()] = columnVectorInfo;
    +      } else {
    +        ColumnVectorInfo columnVectorInfo = new ColumnVectorInfo();
    +        dictInfoList.add(columnVectorInfo);
    +        columnVectorInfo.dimension = currentBlockDimension;
    +        columnVectorInfo.ordinal = currentBlockDimension.getDimension().getOrdinal();
    +        allColumnInfo[queryDimensions[i].getQueryOrder()] = columnVectorInfo;
    +      }
    +    }
    +    int measureExistIndex = 0;
    +    for (int i = 0; i < queryMeasures.length; i++) {
    +      if (!measureInfo.getMeasureExists()[i]) {
    +        // add a dummy column vector result collector object
    +        ColumnVectorInfo columnVectorInfo = new ColumnVectorInfo();
    +        allColumnInfo[queryMeasures[i].getQueryOrder()] = columnVectorInfo;
    +        continue;
    +      }
    +      QueryMeasure currentBlockMeasure =
    +          tableBlockExecutionInfos.getQueryMeasures()[measureExistIndex++];
    +      ColumnVectorInfo columnVectorInfo = new ColumnVectorInfo();
    +      columnVectorInfo.measureVectorFiller = MeasureDataVectorProcessor.MeasureVectorFillerFactory
    +          .getMeasureVectorFiller(currentBlockMeasure.getMeasure().getDataType());
    +      columnVectorInfo.ordinal = currentBlockMeasure.getMeasure().getOrdinal();
    +      columnVectorInfo.measure = currentBlockMeasure;
    +      this.measureColumnInfo[i] = columnVectorInfo;
    +      allColumnInfo[queryMeasures[i].getQueryOrder()] = columnVectorInfo;
    +    }
    +    dictionaryInfo = dictInfoList.toArray(new ColumnVectorInfo[dictInfoList.size()]);
    +    noDictionaryInfo = noDictInfoList.toArray(new ColumnVectorInfo[noDictInfoList.size()]);
    +    complexInfo = complexList.toArray(new ColumnVectorInfo[complexList.size()]);
    +    Arrays.sort(dictionaryInfo);
    +    Arrays.sort(noDictionaryInfo);
    +    Arrays.sort(complexInfo);
    +  }
    +
    +  @Override public List<Object[]> collectData(AbstractScannedResult scannedResult,
int batchSize) {
    +    throw new UnsupportedOperationException("collectData is not supported here");
    +  }
    +
    +  @Override public void collectVectorBatch(AbstractScannedResult scannedResult,
    +      CarbonColumnarBatch columnarBatch) {
    +    int numberOfPages = scannedResult.numberOfpages();
    +    while (scannedResult.getCurrentPageCounter() < numberOfPages) {
    +      int currentPageRowCount = scannedResult.getCurrentPageRowCount();
    +      if (currentPageRowCount == 0) {
    +        scannedResult.incrementPageCounter();
    +        continue;
    +      }
    +      int rowCounter = scannedResult.getRowCounter();
    +      int availableRows = currentPageRowCount - rowCounter;
    +      int requiredRows = columnarBatch.getBatchSize() - columnarBatch.getActualSize();
    +      requiredRows = Math.min(requiredRows, availableRows);
    +      if (requiredRows < 1) {
    +        return;
    +      }
    +      for (int i = 0; i < allColumnInfo.length; i++) {
    +        allColumnInfo[i].size = requiredRows;
    +        allColumnInfo[i].offset = rowCounter;
    +        allColumnInfo[i].vectorOffset = columnarBatch.getRowCounter();
    +        allColumnInfo[i].vector = columnarBatch.columnVectors[i];
    +      }
    +
    +      scannedResult.fillColumnarDictionaryBatch(dictionaryInfo);
    +      scannedResult.fillColumnarNoDictionaryBatch(noDictionaryInfo);
    +      scannedResult.fillColumnarMeasureBatch(measureColumnInfo, measureInfo.getMeasureOrdinals());
    +      scannedResult.fillColumnarComplexBatch(complexInfo);
    +      // fill default values for non existing dimensions and measures
    +      fillDataForNonExistingDimensions();
    +      fillDataForNonExistingMeasures();
    +      // it means fetched all data out of page so increment the page counter
    +      if (availableRows == requiredRows) {
    +        scannedResult.incrementPageCounter();
    +      } else {
    +        // Or set the row counter.
    +        scannedResult.setRowCounter(rowCounter + requiredRows);
    +      }
    +      columnarBatch.setActualSize(columnarBatch.getActualSize() + requiredRows);
    +      columnarBatch.setRowCounter(columnarBatch.getRowCounter() + requiredRows);
    +    }
    +  }
    +
    +  /**
    +   * This method will fill the default values of non existing dimensions in the current
block
    +   */
    +  private void fillDataForNonExistingDimensions() {
    +    for (int i = 0; i < tableBlockExecutionInfos.getActualQueryDimensions().length;
i++) {
    +      if (!dimensionInfo.getDimensionExists()[i]) {
    +        CarbonDimension dimension =
    +            tableBlockExecutionInfos.getActualQueryDimensions()[i].getDimension();
    +        if (dimension.hasEncoding(Encoding.DIRECT_DICTIONARY)) {
    +          // fill direct dictionary column data
    +          fillDirectDictionaryData(allColumnInfo[i].vector, allColumnInfo[i],
    +              dimensionInfo.getDefaultValues()[i]);
    +        } else if (dimension.hasEncoding(Encoding.DICTIONARY)) {
    +          // fill dictionary column data
    +          fillDictionaryData(allColumnInfo[i].vector, allColumnInfo[i],
    +              dimensionInfo.getDefaultValues()[i]);
    +        } else {
    +          // fill no dictionary data
    +          fillNoDictionaryData(allColumnInfo[i].vector, allColumnInfo[i],
    +              dimension.getDefaultValue());
    +        }
    +      }
    +    }
    +  }
    +
    +  /**
    +   * This method will fill the dictionary column data
    +   *
    +   * @param vector
    +   * @param columnVectorInfo
    +   *
    +   * @param defaultValue
    +   */
    +  private void fillDictionaryData(CarbonColumnVector vector, ColumnVectorInfo columnVectorInfo,
    +      Object defaultValue) {
    +    int offset = columnVectorInfo.offset;
    +    int vectorOffset = columnVectorInfo.vectorOffset;
    +    int len = columnVectorInfo.size + offset;
    +    for (int j = offset; j < len; j++) {
    +      vector.putInt(vectorOffset++, (int) defaultValue);
    +    }
    +  }
    +
    +  /**
    +   * This method will fill the direct dictionary column data
    +   *
    +   * @param vector
    +   * @param columnVectorInfo
    +   * @param defaultValue
    +   */
    +  private void fillDirectDictionaryData(CarbonColumnVector vector,
    +      ColumnVectorInfo columnVectorInfo, Object defaultValue) {
    +    int offset = columnVectorInfo.offset;
    +    int vectorOffset = columnVectorInfo.vectorOffset;
    +    int len = columnVectorInfo.size + offset;
    +    for (int j = offset; j < len; j++) {
    --- End diff --
    
    Directly use default value fill method of ColumnVector to put at once.


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