Search in sources :

Example 11 with CarbonMeasure

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

the class CarbonCompactionExecutor method prepareQueryModel.

/**
   * Preparing of the query model.
   *
   * @param blockList
   * @return
   */
private QueryModel prepareQueryModel(List<TableBlockInfo> blockList) {
    QueryModel model = new QueryModel();
    model.setTableBlockInfos(blockList);
    model.setForcedDetailRawQuery(true);
    model.setFilterExpressionResolverTree(null);
    List<QueryDimension> dims = new ArrayList<>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
    List<CarbonDimension> dimensions = carbonTable.getDimensionByTableName(carbonTable.getFactTableName());
    for (CarbonDimension dim : dimensions) {
        // check if dimension is deleted
        QueryDimension queryDimension = new QueryDimension(dim.getColName());
        queryDimension.setDimension(dim);
        dims.add(queryDimension);
    }
    model.setQueryDimension(dims);
    List<QueryMeasure> msrs = new ArrayList<>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE);
    List<CarbonMeasure> measures = carbonTable.getMeasureByTableName(carbonTable.getFactTableName());
    for (CarbonMeasure carbonMeasure : measures) {
        // check if measure is deleted
        QueryMeasure queryMeasure = new QueryMeasure(carbonMeasure.getColName());
        queryMeasure.setMeasure(carbonMeasure);
        msrs.add(queryMeasure);
    }
    model.setQueryMeasures(msrs);
    model.setQueryId(System.nanoTime() + "");
    model.setAbsoluteTableIdentifier(carbonTable.getAbsoluteTableIdentifier());
    model.setTable(carbonTable);
    return model;
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) QueryMeasure(org.apache.carbondata.core.scan.model.QueryMeasure) ArrayList(java.util.ArrayList) QueryModel(org.apache.carbondata.core.scan.model.QueryModel) QueryDimension(org.apache.carbondata.core.scan.model.QueryDimension) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 12 with CarbonMeasure

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

the class StoreCreator method writeDictionary.

private static void writeDictionary(String factFilePath, CarbonTable table) throws Exception {
    BufferedReader reader = new BufferedReader(new FileReader(factFilePath));
    String header = reader.readLine();
    String[] split = header.split(",");
    List<CarbonColumn> allCols = new ArrayList<CarbonColumn>();
    List<CarbonDimension> dims = table.getDimensionByTableName(table.getFactTableName());
    allCols.addAll(dims);
    List<CarbonMeasure> msrs = table.getMeasureByTableName(table.getFactTableName());
    allCols.addAll(msrs);
    Set<String>[] set = new HashSet[dims.size()];
    for (int i = 0; i < set.length; i++) {
        set[i] = new HashSet<String>();
    }
    String line = reader.readLine();
    while (line != null) {
        String[] data = line.split(",");
        for (int i = 0; i < set.length; i++) {
            set[i].add(data[i]);
        }
        line = reader.readLine();
    }
    Cache dictCache = CacheProvider.getInstance().createCache(CacheType.REVERSE_DICTIONARY, absoluteTableIdentifier.getStorePath());
    for (int i = 0; i < set.length; i++) {
        ColumnIdentifier columnIdentifier = new ColumnIdentifier(dims.get(i).getColumnId(), null, null);
        CarbonDictionaryWriter writer = new CarbonDictionaryWriterImpl(absoluteTableIdentifier.getStorePath(), absoluteTableIdentifier.getCarbonTableIdentifier(), columnIdentifier);
        for (String value : set[i]) {
            writer.write(value);
        }
        writer.close();
        writer.commit();
        Dictionary dict = (Dictionary) dictCache.get(new DictionaryColumnUniqueIdentifier(absoluteTableIdentifier.getCarbonTableIdentifier(), columnIdentifier, dims.get(i).getDataType()));
        CarbonDictionarySortInfoPreparator preparator = new CarbonDictionarySortInfoPreparator();
        List<String> newDistinctValues = new ArrayList<String>();
        CarbonDictionarySortInfo dictionarySortInfo = preparator.getDictionarySortInfo(newDistinctValues, dict, dims.get(i).getDataType());
        CarbonDictionarySortIndexWriter carbonDictionaryWriter = new CarbonDictionarySortIndexWriterImpl(absoluteTableIdentifier.getCarbonTableIdentifier(), columnIdentifier, absoluteTableIdentifier.getStorePath());
        try {
            carbonDictionaryWriter.writeSortIndex(dictionarySortInfo.getSortIndex());
            carbonDictionaryWriter.writeInvertedSortIndex(dictionarySortInfo.getSortIndexInverted());
        } finally {
            carbonDictionaryWriter.close();
        }
    }
    reader.close();
}
Also used : Dictionary(org.apache.carbondata.core.cache.dictionary.Dictionary) CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) Set(java.util.Set) HashSet(java.util.HashSet) CarbonDictionaryWriterImpl(org.apache.carbondata.core.writer.CarbonDictionaryWriterImpl) ArrayList(java.util.ArrayList) CarbonDictionarySortIndexWriterImpl(org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortIndexWriterImpl) FileReader(java.io.FileReader) HashSet(java.util.HashSet) CarbonDictionarySortInfoPreparator(org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortInfoPreparator) CarbonDictionarySortInfo(org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortInfo) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension) CarbonDictionarySortIndexWriter(org.apache.carbondata.core.writer.sortindex.CarbonDictionarySortIndexWriter) DictionaryColumnUniqueIdentifier(org.apache.carbondata.core.cache.dictionary.DictionaryColumnUniqueIdentifier) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) BufferedReader(java.io.BufferedReader) ColumnIdentifier(org.apache.carbondata.core.metadata.ColumnIdentifier) CarbonDictionaryWriter(org.apache.carbondata.core.writer.CarbonDictionaryWriter) Cache(org.apache.carbondata.core.cache.Cache)

Example 13 with CarbonMeasure

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

the class CarbonInputFormatUtil method processFilterExpression.

public static void processFilterExpression(Expression filterExpression, CarbonTable carbonTable) {
    List<CarbonDimension> dimensions = carbonTable.getDimensionByTableName(carbonTable.getFactTableName());
    List<CarbonMeasure> measures = carbonTable.getMeasureByTableName(carbonTable.getFactTableName());
    QueryModel.processFilterExpression(filterExpression, dimensions, measures);
    if (null != filterExpression) {
        // Optimize Filter Expression and fit RANGE filters is conditions apply.
        FilterOptimizer rangeFilterOptimizer = new RangeFilterOptmizer(new FilterOptimizerBasic(), filterExpression);
        rangeFilterOptimizer.optimizeFilter();
    }
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) FilterOptimizer(org.apache.carbondata.core.scan.filter.intf.FilterOptimizer) RangeFilterOptmizer(org.apache.carbondata.core.scan.filter.optimizer.RangeFilterOptmizer) FilterOptimizerBasic(org.apache.carbondata.core.scan.filter.intf.FilterOptimizerBasic) CarbonDimension(org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)

Example 14 with CarbonMeasure

use of org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure 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 15 with CarbonMeasure

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

the class CarbonUtil method getColumnSchemaList.

public static List<ColumnSchema> getColumnSchemaList(List<CarbonDimension> carbonDimensionsList, List<CarbonMeasure> carbonMeasureList) {
    List<ColumnSchema> wrapperColumnSchemaList = new ArrayList<ColumnSchema>();
    fillCollumnSchemaListForComplexDims(carbonDimensionsList, wrapperColumnSchemaList);
    for (CarbonMeasure carbonMeasure : carbonMeasureList) {
        wrapperColumnSchemaList.add(carbonMeasure.getColumnSchema());
    }
    return wrapperColumnSchemaList;
}
Also used : CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) ArrayList(java.util.ArrayList) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)

Aggregations

CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)24 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)15 ArrayList (java.util.ArrayList)10 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)8 QueryMeasure (org.apache.carbondata.core.scan.model.QueryMeasure)5 HashSet (java.util.HashSet)4 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)4 DataType (org.apache.carbondata.core.metadata.datatype.DataType)3 CarbonColumn (org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)3 QueryDimension (org.apache.carbondata.core.scan.model.QueryDimension)3 Test (org.junit.Test)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 Set (java.util.Set)2 Cache (org.apache.carbondata.core.cache.Cache)2 Dictionary (org.apache.carbondata.core.cache.dictionary.Dictionary)2 DictionaryColumnUniqueIdentifier (org.apache.carbondata.core.cache.dictionary.DictionaryColumnUniqueIdentifier)2 ColumnIdentifier (org.apache.carbondata.core.metadata.ColumnIdentifier)2 BlockExecutionInfo (org.apache.carbondata.core.scan.executor.infos.BlockExecutionInfo)2 MeasureInfo (org.apache.carbondata.core.scan.executor.infos.MeasureInfo)2