Search in sources :

Example 16 with DataType

use of org.apache.carbondata.core.metadata.datatype.DataType in project carbondata by apache.

the class CarbondataSplitManager method parseFilterExpression.

/**
   * Convert presto-TupleDomain predication into Carbon scan express condition
   * @param originalConstraint  presto-TupleDomain
   * @param carbonTable
   * @return
   */
public Expression parseFilterExpression(TupleDomain<ColumnHandle> originalConstraint, CarbonTable carbonTable) {
    ImmutableList.Builder<Expression> filters = ImmutableList.builder();
    Domain domain = null;
    for (ColumnHandle c : originalConstraint.getDomains().get().keySet()) {
        CarbondataColumnHandle cdch = (CarbondataColumnHandle) c;
        Type type = cdch.getColumnType();
        List<CarbonColumn> ccols = carbonTable.getCreateOrderColumn(carbonTable.getFactTableName());
        Optional<CarbonColumn> target = ccols.stream().filter(a -> a.getColName().equals(cdch.getColumnName())).findFirst();
        if (target.get() == null)
            return null;
        DataType coltype = target.get().getDataType();
        ColumnExpression colExpression = new ColumnExpression(cdch.getColumnName(), target.get().getDataType());
        //colExpression.setColIndex(cs.getSchemaOrdinal());
        colExpression.setDimension(target.get().isDimension());
        colExpression.setDimension(carbonTable.getDimensionByName(carbonTable.getFactTableName(), cdch.getColumnName()));
        colExpression.setCarbonColumn(target.get());
        domain = originalConstraint.getDomains().get().get(c);
        checkArgument(domain.getType().isOrderable(), "Domain type must be orderable");
        if (domain.getValues().isNone()) {
        }
        if (domain.getValues().isAll()) {
        }
        List<Object> singleValues = new ArrayList<>();
        List<Expression> rangeFilter = new ArrayList<>();
        for (Range range : domain.getValues().getRanges().getOrderedRanges()) {
            // Already checked
            checkState(!range.isAll());
            if (range.isSingleValue()) {
                singleValues.add(range.getLow().getValue());
            } else {
                List<String> rangeConjuncts = new ArrayList<>();
                if (!range.getLow().isLowerUnbounded()) {
                    Object value = ConvertDataByType(range.getLow().getValue(), type);
                    switch(range.getLow().getBound()) {
                        case ABOVE:
                            if (type == TimestampType.TIMESTAMP) {
                            //todo not now
                            } else {
                                GreaterThanExpression greater = new GreaterThanExpression(colExpression, new LiteralExpression(value, coltype));
                                rangeFilter.add(greater);
                            }
                            break;
                        case EXACTLY:
                            GreaterThanEqualToExpression greater = new GreaterThanEqualToExpression(colExpression, new LiteralExpression(value, coltype));
                            rangeFilter.add(greater);
                            break;
                        case BELOW:
                            throw new IllegalArgumentException("Low marker should never use BELOW bound");
                        default:
                            throw new AssertionError("Unhandled bound: " + range.getLow().getBound());
                    }
                }
                if (!range.getHigh().isUpperUnbounded()) {
                    Object value = ConvertDataByType(range.getHigh().getValue(), type);
                    switch(range.getHigh().getBound()) {
                        case ABOVE:
                            throw new IllegalArgumentException("High marker should never use ABOVE bound");
                        case EXACTLY:
                            LessThanEqualToExpression less = new LessThanEqualToExpression(colExpression, new LiteralExpression(value, coltype));
                            rangeFilter.add(less);
                            break;
                        case BELOW:
                            LessThanExpression less2 = new LessThanExpression(colExpression, new LiteralExpression(value, coltype));
                            rangeFilter.add(less2);
                            break;
                        default:
                            throw new AssertionError("Unhandled bound: " + range.getHigh().getBound());
                    }
                }
            }
        }
        if (singleValues.size() == 1) {
            Expression ex = null;
            if (coltype.equals(DataType.STRING)) {
                ex = new EqualToExpression(colExpression, new LiteralExpression(((Slice) singleValues.get(0)).toStringUtf8(), coltype));
            } else
                ex = new EqualToExpression(colExpression, new LiteralExpression(singleValues.get(0), coltype));
            filters.add(ex);
        } else if (singleValues.size() > 1) {
            ListExpression candidates = null;
            List<Expression> exs = singleValues.stream().map((a) -> {
                return new LiteralExpression(ConvertDataByType(a, type), coltype);
            }).collect(Collectors.toList());
            candidates = new ListExpression(exs);
            if (candidates != null)
                filters.add(new InExpression(colExpression, candidates));
        } else if (rangeFilter.size() > 0) {
            if (rangeFilter.size() > 1) {
                Expression finalFilters = new OrExpression(rangeFilter.get(0), rangeFilter.get(1));
                if (rangeFilter.size() > 2) {
                    for (int i = 2; i < rangeFilter.size(); i++) {
                        filters.add(new AndExpression(finalFilters, rangeFilter.get(i)));
                    }
                }
            } else if (//only have one value
            rangeFilter.size() == 1)
                filters.add(rangeFilter.get(0));
        }
    }
    Expression finalFilters;
    List<Expression> tmp = filters.build();
    if (tmp.size() > 1) {
        finalFilters = new AndExpression(tmp.get(0), tmp.get(1));
        if (tmp.size() > 2) {
            for (int i = 2; i < tmp.size(); i++) {
                finalFilters = new AndExpression(finalFilters, tmp.get(i));
            }
        }
    } else if (tmp.size() == 1)
        finalFilters = tmp.get(0);
    else
        //no filter
        return null;
    return finalFilters;
}
Also used : Slice(io.airlift.slice.Slice) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) CarbonLocalInputSplit(org.apache.carbondata.presto.impl.CarbonLocalInputSplit) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) com.facebook.presto.spi.type(com.facebook.presto.spi.type) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CarbonTableReader(org.apache.carbondata.presto.impl.CarbonTableReader) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) Objects.requireNonNull(java.util.Objects.requireNonNull) CarbonTableCacheModel(org.apache.carbondata.presto.impl.CarbonTableCacheModel) CarbonTable(org.apache.carbondata.core.metadata.schema.table.CarbonTable) Expression(org.apache.carbondata.core.scan.expression.Expression) CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) DataType(org.apache.carbondata.core.metadata.datatype.DataType) Types.checkType(org.apache.carbondata.presto.Types.checkType) Range(com.facebook.presto.spi.predicate.Range) OrExpression(org.apache.carbondata.core.scan.expression.logical.OrExpression) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) Domain(com.facebook.presto.spi.predicate.Domain) org.apache.carbondata.core.scan.expression.conditional(org.apache.carbondata.core.scan.expression.conditional) List(java.util.List) Optional(java.util.Optional) com.facebook.presto.spi(com.facebook.presto.spi) CarbonColumn(org.apache.carbondata.core.metadata.schema.table.column.CarbonColumn) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) OrExpression(org.apache.carbondata.core.scan.expression.logical.OrExpression) AndExpression(org.apache.carbondata.core.scan.expression.logical.AndExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) DataType(org.apache.carbondata.core.metadata.datatype.DataType) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) Range(com.facebook.presto.spi.predicate.Range) DataType(org.apache.carbondata.core.metadata.datatype.DataType) Types.checkType(org.apache.carbondata.presto.Types.checkType) 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) OrExpression(org.apache.carbondata.core.scan.expression.logical.OrExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain)

Example 17 with DataType

use of org.apache.carbondata.core.metadata.datatype.DataType in project carbondata by apache.

the class ValueCompressionUtil method getDoubleCompressorFinder.

private static CompressionFinder getDoubleCompressorFinder(Object maxValue, Object minValue, int mantissa, byte dataTypeSelected, DataType measureStoreType) {
    //Here we should use the Max abs as max to getDatatype, let's say -1 and -10000000, -1 is max,
    //but we can't use -1 to getDatatype, we should use -10000000.
    double absMaxValue = Math.abs((double) maxValue) >= Math.abs((double) minValue) ? (double) maxValue : (double) minValue;
    DataType adaptiveDataType = getDataType(absMaxValue, mantissa, dataTypeSelected);
    DataType deltaDataType = getDataType((double) maxValue - (double) minValue, mantissa, dataTypeSelected);
    if (mantissa == 0) {
        // short, int, long
        int adaptiveSize = getSize(adaptiveDataType);
        int deltaSize = getSize(deltaDataType);
        if (adaptiveSize > deltaSize) {
            return new CompressionFinder(COMPRESSION_TYPE.DELTA_DOUBLE, DataType.DOUBLE, deltaDataType, measureStoreType);
        } else if (adaptiveSize < deltaSize) {
            return new CompressionFinder(COMPRESSION_TYPE.ADAPTIVE, DataType.DOUBLE, deltaDataType, measureStoreType);
        } else {
            return new CompressionFinder(COMPRESSION_TYPE.ADAPTIVE, DataType.DOUBLE, adaptiveDataType, measureStoreType);
        }
    } else {
        // double
        DataType maxNonDecDataType = getDataType(Math.pow(10, mantissa) * absMaxValue, 0, dataTypeSelected);
        DataType diffNonDecDataType = getDataType(Math.pow(10, mantissa) * ((double) maxValue - (double) minValue), 0, dataTypeSelected);
        CompressionFinder[] finders = { new CompressionFinder(COMPRESSION_TYPE.ADAPTIVE, adaptiveDataType, adaptiveDataType, CompressionFinder.PRIORITY.ACTUAL, measureStoreType), new CompressionFinder(COMPRESSION_TYPE.DELTA_DOUBLE, adaptiveDataType, deltaDataType, CompressionFinder.PRIORITY.DIFFSIZE, measureStoreType), new CompressionFinder(COMPRESSION_TYPE.BIGINT, adaptiveDataType, maxNonDecDataType, CompressionFinder.PRIORITY.MAXNONDECIMAL, measureStoreType), new CompressionFinder(COMPRESSION_TYPE.DELTA_NON_DECIMAL, adaptiveDataType, diffNonDecDataType, CompressionFinder.PRIORITY.DIFFNONDECIMAL, measureStoreType) };
        // sort the compressionFinder.The top have the highest priority
        Arrays.sort(finders);
        return finders[0];
    }
}
Also used : DataType(org.apache.carbondata.core.metadata.datatype.DataType)

Example 18 with DataType

use of org.apache.carbondata.core.metadata.datatype.DataType in project carbondata by apache.

the class RangeExpressionEvaluator method addFilterExpressionMap.

private void addFilterExpressionMap(Map<String, List<FilterModificationNode>> filterExpressionMap, Expression currentNode, Expression parentNode) {
    String colName = getColumnName(currentNode);
    DataType dataType = getLiteralDataType(currentNode);
    Object literalVal = getLiteralValue(currentNode);
    ExpressionType expType = getExpressionType(currentNode);
    FilterModificationNode filterExpression = new FilterModificationNode(currentNode, parentNode, expType, dataType, literalVal, colName);
    if (null == filterExpressionMap.get(colName)) {
        filterExpressionMap.put(colName, new ArrayList<FilterModificationNode>());
    }
    filterExpressionMap.get(colName).add(filterExpression);
}
Also used : DataType(org.apache.carbondata.core.metadata.datatype.DataType) ExpressionType(org.apache.carbondata.core.scan.filter.intf.ExpressionType)

Example 19 with DataType

use of org.apache.carbondata.core.metadata.datatype.DataType in project carbondata by apache.

the class ValueCompressionUtilTest method testToGetValueCompressionModelForByteAndIntAndDataTypeSelected0.

@Test
public void testToGetValueCompressionModelForByteAndIntAndDataTypeSelected0() {
    Object[] maxValues = { -32766.00 };
    Object[] minValues = { 32744.0 };
    int[] decimalLength = { 1 };
    Object[] uniqueValues = { 5 };
    DataType[] types = { DataType.DOUBLE };
    byte[] dataTypeSelected = { 0 };
    MeasureMetaDataModel measureMetaDataModel = new MeasureMetaDataModel(maxValues, minValues, decimalLength, 1, uniqueValues, types, dataTypeSelected);
    WriterCompressModel writerCompressModel = ValueCompressionUtil.getWriterCompressModel(measureMetaDataModel);
    assertEquals(ValueCompressionUtil.COMPRESSION_TYPE.BIGINT, writerCompressModel.getCompType(0));
}
Also used : WriterCompressModel(org.apache.carbondata.core.datastore.compression.WriterCompressModel) MeasureMetaDataModel(org.apache.carbondata.core.datastore.compression.MeasureMetaDataModel) DataType(org.apache.carbondata.core.metadata.datatype.DataType) Test(org.junit.Test)

Example 20 with DataType

use of org.apache.carbondata.core.metadata.datatype.DataType in project carbondata by apache.

the class ValueCompressionUtilTest method testToGetValueCompressionModelForDefaultAggregatorType.

@Test
public void testToGetValueCompressionModelForDefaultAggregatorType() {
    Object[] maxValues = { 10.0 };
    Object[] minValues = { 1.0 };
    int[] decimalLength = { 0 };
    Object[] uniqueValues = { 5 };
    DataType[] types = { DataType.DOUBLE };
    byte[] dataTypeSelected = { 1 };
    MeasureMetaDataModel measureMetaDataModel = new MeasureMetaDataModel(maxValues, minValues, decimalLength, 1, uniqueValues, types, dataTypeSelected);
    WriterCompressModel writerCompressModel = ValueCompressionUtil.getWriterCompressModel(measureMetaDataModel);
    assertEquals(ValueCompressionUtil.COMPRESSION_TYPE.ADAPTIVE, writerCompressModel.getCompType(0));
}
Also used : WriterCompressModel(org.apache.carbondata.core.datastore.compression.WriterCompressModel) MeasureMetaDataModel(org.apache.carbondata.core.datastore.compression.MeasureMetaDataModel) DataType(org.apache.carbondata.core.metadata.datatype.DataType) Test(org.junit.Test)

Aggregations

DataType (org.apache.carbondata.core.metadata.datatype.DataType)27 MeasureMetaDataModel (org.apache.carbondata.core.datastore.compression.MeasureMetaDataModel)9 WriterCompressModel (org.apache.carbondata.core.datastore.compression.WriterCompressModel)9 Test (org.junit.Test)8 IOException (java.io.IOException)3 List (java.util.List)3 Domain (com.facebook.presto.spi.predicate.Domain)2 Range (com.facebook.presto.spi.predicate.Range)2 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)2 ImmutableList (com.google.common.collect.ImmutableList)2 DataOutputStream (java.io.DataOutputStream)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 BitSet (java.util.BitSet)2 Comparator (java.util.Comparator)2 CarbonTable (org.apache.carbondata.core.metadata.schema.table.CarbonTable)2 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)2 Expression (org.apache.carbondata.core.scan.expression.Expression)2 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)2 AndExpression (org.apache.carbondata.core.scan.expression.logical.AndExpression)2