Search in sources :

Example 26 with CarbonColumn

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

the class FilterUtilTest method testGetFilterListForAllMembersRS.

@Test
public void testGetFilterListForAllMembersRS() throws Exception {
    Expression expression = new ColumnExpression("IMEI", DataTypes.STRING);
    ColumnExpression columnExpression = new ColumnExpression("IMEI", DataTypes.STRING);
    String defaultValues = "test";
    int defaultSurrogate = 1;
    boolean isIncludeFilter = true;
    int ordinal = 1;
    ColumnSchema dimColumn = new ColumnSchema();
    dimColumn.setColumnar(true);
    dimColumn.setColumnName("IMEI");
    dimColumn.setColumnUniqueId(UUID.randomUUID().toString());
    dimColumn.setDataType(DataTypes.STRING);
    dimColumn.setDimensionColumn(true);
    final CarbonColumn carbonColumn = new CarbonColumn(dimColumn, ordinal, -1);
    new MockUp<ColumnExpression>() {

        @Mock
        public CarbonColumn getCarbonColumn() {
            return carbonColumn;
        }
    };
    new MockUp<RowImpl>() {

        @Mock
        public Object getVal(int index) {
            return "test";
        }
    };
    assertTrue(FilterUtil.getFilterListForAllMembersRS(expression, columnExpression, defaultValues, defaultSurrogate, isIncludeFilter) instanceof ColumnFilterInfo);
}
Also used : CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) Expression(org.apache.carbondata.core.scan.expression.Expression) ListExpression(org.apache.carbondata.core.scan.expression.conditional.ListExpression) TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) MockUp(mockit.MockUp) Test(org.junit.Test) AbstractDictionaryCacheTest(org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)

Example 27 with CarbonColumn

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

the class FilterUtilTest method testGetFilterListForAllMembersRSWithDefaultValuesEqualsToNull.

@Test
public void testGetFilterListForAllMembersRSWithDefaultValuesEqualsToNull() throws Exception {
    Expression expression = new ColumnExpression("IMEI", DataTypes.STRING);
    ColumnExpression columnExpression = new ColumnExpression("IMEI", DataTypes.STRING);
    String defaultValues = CarbonCommonConstants.MEMBER_DEFAULT_VAL;
    int defaultSurrogate = 1;
    boolean isIncludeFilter = true;
    int ordinal = 1;
    ColumnSchema dimColumn = new ColumnSchema();
    dimColumn.setColumnar(true);
    dimColumn.setColumnName("IMEI");
    dimColumn.setColumnUniqueId(UUID.randomUUID().toString());
    dimColumn.setDataType(DataTypes.STRING);
    dimColumn.setDimensionColumn(true);
    final CarbonColumn carbonColumn = new CarbonColumn(dimColumn, ordinal, -1);
    new MockUp<ColumnExpression>() {

        @Mock
        public CarbonColumn getCarbonColumn() {
            return carbonColumn;
        }
    };
    new MockUp<RowImpl>() {

        @Mock
        public Object getVal(int index) {
            return "test";
        }
    };
    assertTrue(FilterUtil.getFilterListForAllMembersRS(expression, columnExpression, defaultValues, defaultSurrogate, isIncludeFilter) instanceof ColumnFilterInfo);
}
Also used : CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) Expression(org.apache.carbondata.core.scan.expression.Expression) ListExpression(org.apache.carbondata.core.scan.expression.conditional.ListExpression) TrueExpression(org.apache.carbondata.core.scan.expression.logical.TrueExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) ColumnSchema(org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema) MockUp(mockit.MockUp) Test(org.junit.Test) AbstractDictionaryCacheTest(org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)

Example 28 with CarbonColumn

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

the class SparkDataTypeConverterImpl method convertCarbonSchemaToSparkSchema.

/**
 * convert from CarbonColumn array to Spark's StructField array
 */
@Override
public Object[] convertCarbonSchemaToSparkSchema(CarbonColumn[] carbonColumns) {
    StructField[] fields = new StructField[carbonColumns.length];
    for (int i = 0; i < carbonColumns.length; i++) {
        CarbonColumn carbonColumn = carbonColumns[i];
        if (carbonColumn.isDimension()) {
            if (carbonColumn.hasEncoding(Encoding.DIRECT_DICTIONARY)) {
                DirectDictionaryGenerator generator = DirectDictionaryKeyGeneratorFactory.getDirectDictionaryGenerator(carbonColumn.getDataType());
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(generator.getReturnType()), true, null);
            } else if (!carbonColumn.hasEncoding(Encoding.DICTIONARY)) {
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(carbonColumn.getDataType()), true, null);
            } else if (carbonColumn.isComplex()) {
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(carbonColumn.getDataType()), true, null);
            } else {
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(org.apache.carbondata.core.metadata.datatype.DataTypes.INT), true, null);
            }
        } else if (carbonColumn.isMeasure()) {
            DataType dataType = carbonColumn.getDataType();
            if (dataType == org.apache.carbondata.core.metadata.datatype.DataTypes.BOOLEAN || dataType == org.apache.carbondata.core.metadata.datatype.DataTypes.SHORT || dataType == org.apache.carbondata.core.metadata.datatype.DataTypes.INT || dataType == org.apache.carbondata.core.metadata.datatype.DataTypes.LONG) {
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(dataType), true, null);
            } else if (org.apache.carbondata.core.metadata.datatype.DataTypes.isDecimal(dataType)) {
                CarbonMeasure measure = (CarbonMeasure) carbonColumn;
                fields[i] = new StructField(carbonColumn.getColName(), new DecimalType(measure.getPrecision(), measure.getScale()), true, null);
            } else {
                fields[i] = new StructField(carbonColumn.getColName(), convertCarbonToSparkDataType(org.apache.carbondata.core.metadata.datatype.DataTypes.DOUBLE), true, null);
            }
        }
    }
    return fields;
}
Also used : StructField(org.apache.spark.sql.types.StructField) CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) DataType(org.apache.carbondata.core.metadata.datatype.DataType) DecimalType(org.apache.spark.sql.types.DecimalType) DirectDictionaryGenerator(org.apache.carbondata.core.keygenerator.directdictionary.DirectDictionaryGenerator)

Example 29 with CarbonColumn

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

the class FilterExpressionProcessor method getFilterResolverBasedOnExpressionType.

/**
 * Factory method which will return the resolver instance based on filter expression
 * expressions.
 */
private FilterResolverIntf getFilterResolverBasedOnExpressionType(ExpressionType filterExpressionType, boolean isExpressionResolve, Expression expression, AbsoluteTableIdentifier tableIdentifier, Expression expressionTree) {
    BinaryConditionalExpression currentCondExpression = null;
    ConditionalExpression condExpression = null;
    switch(filterExpressionType) {
        case FALSE:
            return new FalseConditionalResolverImpl(expression, false, false);
        case TRUE:
            return new TrueConditionalResolverImpl(expression, false, false);
        case EQUALS:
            currentCondExpression = (BinaryConditionalExpression) expression;
            // check for implicit column in the expression
            if (currentCondExpression instanceof InExpression) {
                CarbonColumn carbonColumn = currentCondExpression.getColumnList().get(0).getCarbonColumn();
                if (carbonColumn.hasEncoding(Encoding.IMPLICIT)) {
                    return new ConditionalFilterResolverImpl(expression, isExpressionResolve, true, currentCondExpression.getColumnList().get(0).getCarbonColumn().isMeasure());
                }
            }
            CarbonColumn column = currentCondExpression.getColumnList().get(0).getCarbonColumn();
            if (currentCondExpression.isSingleColumn() && !column.getDataType().isComplexType()) {
                // expression as it is already resolved and has the surrogates in the filter value
                if (FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getLeft()) && FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getRight()) || (FilterUtil.checkIfRightExpressionRequireEvaluation(currentCondExpression.getRight()) || FilterUtil.checkIfLeftExpressionRequireEvaluation(currentCondExpression.getLeft()))) {
                    return new RowLevelFilterResolverImpl(expression, isExpressionResolve, true, tableIdentifier);
                }
                if (currentCondExpression.getFilterExpressionType() == ExpressionType.GREATERTHAN || currentCondExpression.getFilterExpressionType() == ExpressionType.LESSTHAN || currentCondExpression.getFilterExpressionType() == ExpressionType.GREATERTHAN_EQUALTO || currentCondExpression.getFilterExpressionType() == ExpressionType.LESSTHAN_EQUALTO) {
                    return new RowLevelRangeFilterResolverImpl(expression, isExpressionResolve, true, tableIdentifier);
                }
                return new ConditionalFilterResolverImpl(expression, isExpressionResolve, true, column.isMeasure());
            }
            break;
        case RANGE:
            return new ConditionalFilterResolverImpl(expression, isExpressionResolve, true, false);
        case NOT_EQUALS:
            currentCondExpression = (BinaryConditionalExpression) expression;
            column = currentCondExpression.getColumnList().get(0).getCarbonColumn();
            if (currentCondExpression.isSingleColumn() && !column.getDataType().isComplexType()) {
                if (FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getLeft()) && FilterUtil.checkIfExpressionContainsColumn(currentCondExpression.getRight()) || (FilterUtil.checkIfRightExpressionRequireEvaluation(currentCondExpression.getRight()) || FilterUtil.checkIfLeftExpressionRequireEvaluation(currentCondExpression.getLeft()))) {
                    return new RowLevelFilterResolverImpl(expression, isExpressionResolve, false, tableIdentifier);
                }
                if (expressionTree.getFilterExpressionType() == ExpressionType.GREATERTHAN || expressionTree.getFilterExpressionType() == ExpressionType.LESSTHAN || expressionTree.getFilterExpressionType() == ExpressionType.GREATERTHAN_EQUALTO || expressionTree.getFilterExpressionType() == ExpressionType.LESSTHAN_EQUALTO) {
                    return new RowLevelRangeFilterResolverImpl(expression, isExpressionResolve, false, tableIdentifier);
                }
                return new ConditionalFilterResolverImpl(expression, isExpressionResolve, false, column.isMeasure());
            }
            break;
        default:
            if (expression instanceof ConditionalExpression) {
                condExpression = (ConditionalExpression) expression;
                column = condExpression.getColumnList().get(0).getCarbonColumn();
                if (condExpression.isSingleColumn() && !column.isComplex()) {
                    condExpression = (ConditionalExpression) expression;
                    if (condExpression.getColumnList().get(0).getCarbonColumn().isMeasure()) {
                        return new ConditionalFilterResolverImpl(expression, true, true, condExpression.getColumnList().get(0).getCarbonColumn().isMeasure());
                    }
                }
            }
    }
    return new RowLevelFilterResolverImpl(expression, false, false, tableIdentifier);
}
Also used : ConditionalFilterResolverImpl(org.apache.carbondata.core.scan.filter.resolver.ConditionalFilterResolverImpl) CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) RowLevelFilterResolverImpl(org.apache.carbondata.core.scan.filter.resolver.RowLevelFilterResolverImpl) ConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.ConditionalExpression) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) InExpression(org.apache.carbondata.core.scan.expression.conditional.InExpression) RowLevelRangeFilterResolverImpl(org.apache.carbondata.core.scan.filter.resolver.RowLevelRangeFilterResolverImpl) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) FalseConditionalResolverImpl(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.FalseConditionalResolverImpl) TrueConditionalResolverImpl(org.apache.carbondata.core.scan.filter.resolver.resolverinfo.TrueConditionalResolverImpl)

Example 30 with CarbonColumn

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

the class FilterUtil method getFilterColumnIndexInCachedColumns.

/**
 * Method to check whether the filter dimension exists in the cached dimensions for a table
 *
 * @param carbonDimensionsToBeCached
 * @param filterColumn
 * @return
 */
private static int getFilterColumnIndexInCachedColumns(List<CarbonColumn> carbonDimensionsToBeCached, CarbonColumn filterColumn) {
    int columnIndexInMinMaxByteArray = -1;
    int columnCounter = 0;
    for (CarbonColumn cachedColumn : carbonDimensionsToBeCached) {
        if (cachedColumn.getColumnId().equalsIgnoreCase(filterColumn.getColumnId())) {
            columnIndexInMinMaxByteArray = columnCounter;
            break;
        }
        columnCounter++;
    }
    return columnIndexInMinMaxByteArray;
}
Also used : CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)

Aggregations

CarbonColumn (org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn)45 ArrayList (java.util.ArrayList)20 CarbonDimension (org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension)14 CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)11 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)6 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)6 DataType (org.apache.carbondata.core.metadata.datatype.DataType)5 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)5 Expression (org.apache.carbondata.core.scan.expression.Expression)5 AndExpression (org.apache.carbondata.core.scan.expression.logical.AndExpression)5 InExpression (org.apache.carbondata.core.scan.expression.conditional.InExpression)4 TrueExpression (org.apache.carbondata.core.scan.expression.logical.TrueExpression)4 DataField (org.apache.carbondata.processing.loading.DataField)4 HashMap (java.util.HashMap)3 MockUp (mockit.MockUp)3 AbstractDictionaryCacheTest (org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)3 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)3 Test (org.junit.Test)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2