Search in sources :

Example 41 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class CarbonInputFormatUtil method createQueryPlan.

public static CarbonQueryPlan createQueryPlan(CarbonTable carbonTable, String columnString) {
    String[] columns = null;
    if (columnString != null) {
        columns = columnString.split(",");
    }
    String factTableName = carbonTable.getFactTableName();
    CarbonQueryPlan plan = new CarbonQueryPlan(carbonTable.getDatabaseName(), factTableName);
    // fill dimensions
    // If columns are null, set all dimensions and measures
    int i = 0;
    if (columns != null) {
        for (String column : columns) {
            CarbonDimension dimensionByName = carbonTable.getDimensionByName(factTableName, column);
            if (dimensionByName != null) {
                addQueryDimension(plan, i, dimensionByName);
                i++;
            } else {
                CarbonMeasure measure = carbonTable.getMeasureByName(factTableName, column);
                if (measure == null) {
                    throw new RuntimeException(column + " column not found in the table " + factTableName);
                }
                addQueryMeasure(plan, i, measure);
                i++;
            }
        }
    }
    plan.setQueryId(System.nanoTime() + "");
    return plan;
}
Also used : CarbonQueryPlan(org.apache.carbondata.core.scan.model.CarbonQueryPlan) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 42 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class CarbonUtil method identifyDimensionType.

/**
   * Below method will be used to get the dimension
   *
   * @param tableDimensionList table dimension list
   * @return boolean array specifying true if dimension is dictionary
   * and false if dimension is not a dictionary column
   */
public static boolean[] identifyDimensionType(List<CarbonDimension> tableDimensionList) {
    List<Boolean> isDictionaryDimensions = new ArrayList<Boolean>();
    Set<Integer> processedColumnGroup = new HashSet<Integer>();
    for (CarbonDimension carbonDimension : tableDimensionList) {
        List<CarbonDimension> childs = carbonDimension.getListOfChildDimensions();
        //assuming complex dimensions will always be atlast
        if (null != childs && childs.size() > 0) {
            break;
        }
        if (carbonDimension.isColumnar() && hasEncoding(carbonDimension.getEncoder(), Encoding.DICTIONARY)) {
            isDictionaryDimensions.add(true);
        } else if (!carbonDimension.isColumnar()) {
            if (processedColumnGroup.add(carbonDimension.columnGroupId())) {
                isDictionaryDimensions.add(true);
            }
        } else {
            isDictionaryDimensions.add(false);
        }
    }
    return ArrayUtils.toPrimitive(isDictionaryDimensions.toArray(new Boolean[isDictionaryDimensions.size()]));
}
Also used : ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 43 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class CarbonUtil method fillCollumnSchemaListForComplexDims.

private static void fillCollumnSchemaListForComplexDims(List<CarbonDimension> carbonDimensionsList, List<ColumnSchema> wrapperColumnSchemaList) {
    for (CarbonDimension carbonDimension : carbonDimensionsList) {
        wrapperColumnSchemaList.add(carbonDimension.getColumnSchema());
        List<CarbonDimension> childDims = carbonDimension.getListOfChildDimensions();
        if (null != childDims && childDims.size() > 0) {
            fillCollumnSchemaListForComplexDims(childDims, wrapperColumnSchemaList);
        }
    }
}
Also used : CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 44 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class FilterUtil method getStartKeyForNoDictionaryDimension.

/**
   * Algorithm for getting the start key for a filter
   * step 1: Iterate through each dimension and verify whether its not an exclude filter.
   * step 2: Intialize start key with the first filter member value present in each filter model
   * for the respective dimensions.
   * step 3: since its a no dictionary start key there will only actual value so compare
   * the first filter model value with respect to the dimension data type.
   * step 4: The least value will be considered as the start key of dimension by comparing all
   * its filter model.
   * step 5: create a byte array of start key which comprises of least filter member value of
   * all dimension and the indexes which will help to read the respective filter value.
   *
   * @param dimColResolvedFilterInfo
   * @param setOfStartKeyByteArray
   * @return
   */
public static void getStartKeyForNoDictionaryDimension(DimColumnResolvedFilterInfo dimColResolvedFilterInfo, SegmentProperties segmentProperties, SortedMap<Integer, byte[]> setOfStartKeyByteArray) {
    Map<CarbonDimension, List<DimColumnFilterInfo>> dimensionFilter = dimColResolvedFilterInfo.getDimensionResolvedFilterInstance();
    // step 1
    for (Map.Entry<CarbonDimension, List<DimColumnFilterInfo>> entry : dimensionFilter.entrySet()) {
        if (!entry.getKey().hasEncoding(Encoding.DICTIONARY)) {
            List<DimColumnFilterInfo> listOfDimColFilterInfo = entry.getValue();
            if (null == listOfDimColFilterInfo) {
                continue;
            }
            boolean isExcludePresent = false;
            for (DimColumnFilterInfo info : listOfDimColFilterInfo) {
                if (!info.isIncludeFilter()) {
                    isExcludePresent = true;
                }
            }
            if (isExcludePresent) {
                continue;
            }
            // in case of restructure scenarios it can happen that the filter dimension is not
            // present in the current block. In those cases no need to determine the key
            CarbonDimension dimensionFromCurrentBlock = CarbonUtil.getDimensionFromCurrentBlock(segmentProperties.getDimensions(), entry.getKey());
            if (null == dimensionFromCurrentBlock) {
                continue;
            }
            // step 2
            byte[] noDictionaryStartKey = listOfDimColFilterInfo.get(0).getNoDictionaryFilterValuesList().get(0);
            if (setOfStartKeyByteArray.isEmpty()) {
                setOfStartKeyByteArray.put(dimensionFromCurrentBlock.getOrdinal(), noDictionaryStartKey);
            } else if (null == setOfStartKeyByteArray.get(dimensionFromCurrentBlock.getOrdinal())) {
                setOfStartKeyByteArray.put(dimensionFromCurrentBlock.getOrdinal(), noDictionaryStartKey);
            } else if (ByteUtil.UnsafeComparer.INSTANCE.compareTo(setOfStartKeyByteArray.get(dimensionFromCurrentBlock.getOrdinal()), noDictionaryStartKey) > 0) {
                setOfStartKeyByteArray.put(dimensionFromCurrentBlock.getOrdinal(), noDictionaryStartKey);
            }
        }
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) SortedMap(java.util.SortedMap) TreeMap(java.util.TreeMap) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 45 with CarbonDimension

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension in project carbondata by apache.

the class RowLevelRangeGrtThanFiterExecuterImpl method ifDefaultValueMatchesFilter.

/**
   * This method will check whether default value is present in the given filter values
   */
private void ifDefaultValueMatchesFilter() {
    if (!this.isDimensionPresentInCurrentBlock[0]) {
        CarbonDimension dimension = this.dimColEvaluatorInfoList.get(0).getDimension();
        byte[] defaultValue = dimension.getDefaultValue();
        if (null != defaultValue) {
            for (int k = 0; k < filterRangeValues.length; k++) {
                int maxCompare = ByteUtil.UnsafeComparer.INSTANCE.compareTo(filterRangeValues[k], defaultValue);
                if (maxCompare < 0) {
                    isDefaultValuePresentInFilter = true;
                    break;
                }
            }
        }
    }
}
Also used : CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Aggregations

CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)85 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)31 ArrayList (java.util.ArrayList)26 Test (org.junit.Test)23 CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)15 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)13 QueryDimension (org.apache.carbondata.core.scan.model.QueryDimension)9 CarbonMetadata (org.apache.carbondata.core.metadata.CarbonMetadata)7 HashSet (java.util.HashSet)6 List (java.util.List)5 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)5 Expression (org.apache.carbondata.core.scan.expression.Expression)5 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)5 FilterOptimizer (org.apache.carbondata.core.scan.filter.intf.FilterOptimizer)5 FilterOptimizerBasic (org.apache.carbondata.core.scan.filter.intf.FilterOptimizerBasic)5 RangeFilterOptmizer (org.apache.carbondata.core.scan.filter.optimizer.RangeFilterOptmizer)5 Map (java.util.Map)4 SortedMap (java.util.SortedMap)4 TreeMap (java.util.TreeMap)4 TableInfo (org.apache.carbondata.core.metadata.schema.table.TableInfo)4