Search in sources :

Example 11 with DataMapSchema

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

the class AggregateTableSelector method selectPreAggDataMapSchema.

/**
 * Below method will be used to select pre aggregate tables based on query plan
 * Rules for selecting the aggregate table is below:
 * 1. Select all aggregate table based on projection
 * 2. select aggregate table based on filter exp,
 * 2. select if aggregate tables based on aggregate columns
 *
 * @return selected pre aggregate table schema
 */
public List<DataMapSchema> selectPreAggDataMapSchema() {
    List<QueryColumn> projectionColumn = aggregateQueryPlan.getProjectionColumn();
    List<QueryColumn> filterColumns = aggregateQueryPlan.getFilterColumns();
    List<DataMapSchema> dataMapSchemaList = parentTable.getTableInfo().getDataMapSchemaList();
    List<DataMapSchema> selectedDataMapSchema = new ArrayList<>();
    boolean isMatch;
    // match projection columns
    if (null != projectionColumn && !projectionColumn.isEmpty()) {
        for (DataMapSchema dmSchema : dataMapSchemaList) {
            AggregationDataMapSchema aggregationDataMapSchema = (AggregationDataMapSchema) dmSchema;
            isMatch = true;
            for (QueryColumn queryColumn : projectionColumn) {
                ColumnSchema columnSchemaByParentName = getColumnSchema(queryColumn, aggregationDataMapSchema);
                if (null == columnSchemaByParentName) {
                    isMatch = false;
                    break;
                }
            }
            if (isMatch) {
                selectedDataMapSchema.add(dmSchema);
            }
        }
        // if projection column is present but selected table list size is zero then
        if (selectedDataMapSchema.size() == 0) {
            return selectedDataMapSchema;
        }
    }
    // match filter columns
    if (null != filterColumns && !filterColumns.isEmpty()) {
        List<DataMapSchema> dmSchemaToIterate = selectedDataMapSchema.isEmpty() ? dataMapSchemaList : selectedDataMapSchema;
        selectedDataMapSchema = new ArrayList<>();
        for (DataMapSchema dmSchema : dmSchemaToIterate) {
            isMatch = true;
            for (QueryColumn queryColumn : filterColumns) {
                AggregationDataMapSchema aggregationDataMapSchema = (AggregationDataMapSchema) dmSchema;
                ColumnSchema columnSchemaByParentName = getColumnSchema(queryColumn, aggregationDataMapSchema);
                if (null == columnSchemaByParentName) {
                    isMatch = false;
                    break;
                }
            }
            if (isMatch) {
                selectedDataMapSchema.add(dmSchema);
            }
        }
        // if filter column is present and selection size is zero then return
        if (selectedDataMapSchema.size() == 0) {
            return selectedDataMapSchema;
        }
    }
    return selectedDataMapSchema;
}
Also used : ArrayList(java.util.ArrayList) AggregationDataMapSchema(org.apache.carbondata.core.metadata.schema.table.AggregationDataMapSchema) DataMapSchema(org.apache.carbondata.core.metadata.schema.table.DataMapSchema) AggregationDataMapSchema(org.apache.carbondata.core.metadata.schema.table.AggregationDataMapSchema) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)

Aggregations

DataMapSchema (org.apache.carbondata.core.metadata.schema.table.DataMapSchema)11 ArrayList (java.util.ArrayList)8 RelationIdentifier (org.apache.carbondata.core.metadata.schema.table.RelationIdentifier)4 IOException (java.io.IOException)1 ICarbonLock (org.apache.carbondata.core.locks.ICarbonLock)1 AggregationDataMapSchema (org.apache.carbondata.core.metadata.schema.table.AggregationDataMapSchema)1 DataMapSchemaStorageProvider (org.apache.carbondata.core.metadata.schema.table.DataMapSchemaStorageProvider)1 DiskBasedDMSchemaStorageProvider (org.apache.carbondata.core.metadata.schema.table.DiskBasedDMSchemaStorageProvider)1 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)1