Search in sources :

Example 11 with SerializableComparator

use of org.apache.carbondata.core.util.comparator.SerializableComparator in project carbondata by apache.

the class RestructureEvaluatorImpl method isMeasureDefaultValuePresentInFilterValues.

/**
 * This method will check whether a default value for the non-existing column is present
 * in the filter values list
 *
 * @param measureColumnResolvedFilterInfo
 * @return
 */
protected boolean isMeasureDefaultValuePresentInFilterValues(MeasureColumnResolvedFilterInfo measureColumnResolvedFilterInfo) {
    boolean isDefaultValuePresentInFilterValues = false;
    ColumnFilterInfo filterValues = measureColumnResolvedFilterInfo.getFilterValues();
    CarbonMeasure measure = measureColumnResolvedFilterInfo.getMeasure();
    SerializableComparator comparator = Comparator.getComparatorByDataTypeForMeasure(measure.getDataType());
    Object defaultValue = null;
    if (null != measure.getDefaultValue()) {
        // default value for case where user gives is Null condition
        defaultValue = DataTypeUtil.getMeasureObjectFromDataType(measure.getDefaultValue(), measure.getDataType());
    }
    List<Object> measureFilterValuesList = filterValues.getMeasuresFilterValuesList();
    for (Object filterValue : measureFilterValuesList) {
        int compare = comparator.compare(defaultValue, filterValue);
        if (compare == 0) {
            isDefaultValuePresentInFilterValues = true;
            break;
        }
    }
    return isDefaultValuePresentInFilterValues;
}
Also used : SerializableComparator(org.apache.carbondata.core.util.comparator.SerializableComparator) CarbonMeasure(org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure) ColumnFilterInfo(org.apache.carbondata.core.scan.filter.ColumnFilterInfo)

Example 12 with SerializableComparator

use of org.apache.carbondata.core.util.comparator.SerializableComparator in project carbondata by apache.

the class RowLevelRangeGrtThanFiterExecuterImpl method getFilteredIndexesForMeasures.

private BitSet getFilteredIndexesForMeasures(ColumnPage columnPage, int numerOfRows) {
    BitSet bitSet = new BitSet(numerOfRows);
    Object[] filterValues = this.msrFilterRangeValues;
    DataType msrType = msrColEvalutorInfoList.get(0).getType();
    SerializableComparator comparator = Comparator.getComparatorByDataTypeForMeasure(msrType);
    BitSet nullBitSet = columnPage.getNullBits();
    for (int i = 0; i < filterValues.length; i++) {
        if (filterValues[i] == null) {
            for (int j = nullBitSet.nextSetBit(0); j >= 0; j = nullBitSet.nextSetBit(j + 1)) {
                bitSet.set(j);
            }
            continue;
        }
        for (int startIndex = 0; startIndex < numerOfRows; startIndex++) {
            if (!nullBitSet.get(startIndex)) {
                Object msrValue = DataTypeUtil.getMeasureObjectBasedOnDataType(columnPage, startIndex, msrType, msrColEvalutorInfoList.get(0).getMeasure());
                if (comparator.compare(msrValue, filterValues[i]) > 0) {
                    // This is a match.
                    bitSet.set(startIndex);
                }
            }
        }
    }
    return bitSet;
}
Also used : SerializableComparator(org.apache.carbondata.core.util.comparator.SerializableComparator) BitSet(java.util.BitSet) DataType(org.apache.carbondata.core.metadata.datatype.DataType)

Example 13 with SerializableComparator

use of org.apache.carbondata.core.util.comparator.SerializableComparator in project carbondata by apache.

the class PartitionFilterUtil method getPartitionMapForRangeFilter.

/**
 * get partition map of range filter on list partition table
 * @param partitionInfo
 * @param partitioner
 * @param filterValue
 * @param isGreaterThan
 * @param isEqualTo
 * @return
 */
public static BitSet getPartitionMapForRangeFilter(PartitionInfo partitionInfo, ListPartitioner partitioner, Object filterValue, boolean isGreaterThan, boolean isEqualTo, DateFormat timestampFormatter, DateFormat dateFormatter) {
    List<List<String>> listInfo = partitionInfo.getListInfo();
    DataType partitionColumnDataType = partitionInfo.getColumnSchemaList().get(0).getDataType();
    SerializableComparator comparator = Comparator.getComparator(partitionColumnDataType);
    BitSet partitionMap = PartitionUtil.generateBitSetBySize(partitioner.numPartitions(), false);
    // add default partition
    partitionMap.set(0);
    int partitions = listInfo.size();
    if (isGreaterThan) {
        if (isEqualTo) {
            // GreaterThanEqualTo(>=)
            outer1: for (int i = 0; i < partitions; i++) {
                for (String value : listInfo.get(i)) {
                    Object listValue = PartitionUtil.getDataBasedOnDataType(value, partitionColumnDataType, timestampFormatter, dateFormatter);
                    if (listValue instanceof String) {
                        listValue = ByteUtil.toBytes((String) listValue);
                    }
                    if (comparator.compare(listValue, filterValue) >= 0) {
                        partitionMap.set(i + 1);
                        continue outer1;
                    }
                }
            }
        } else {
            // GreaterThan(>)
            outer2: for (int i = 0; i < partitions; i++) {
                for (String value : listInfo.get(i)) {
                    Object listValue = PartitionUtil.getDataBasedOnDataType(value, partitionColumnDataType, timestampFormatter, dateFormatter);
                    if (listValue instanceof String) {
                        listValue = ByteUtil.toBytes((String) listValue);
                    }
                    if (comparator.compare(listValue, filterValue) > 0) {
                        partitionMap.set(i + 1);
                        continue outer2;
                    }
                }
            }
        }
    } else {
        if (isEqualTo) {
            // LessThanEqualTo(<=)
            outer3: for (int i = 0; i < partitions; i++) {
                for (String value : listInfo.get(i)) {
                    Object listValue = PartitionUtil.getDataBasedOnDataType(value, partitionColumnDataType, timestampFormatter, dateFormatter);
                    if (listValue instanceof String) {
                        listValue = ByteUtil.toBytes((String) listValue);
                    }
                    if (comparator.compare(listValue, filterValue) <= 0) {
                        partitionMap.set(i + 1);
                        continue outer3;
                    }
                }
            }
        } else {
            // LessThan(<)
            outer4: for (int i = 0; i < partitions; i++) {
                for (String value : listInfo.get(i)) {
                    Object listValue = PartitionUtil.getDataBasedOnDataType(value, partitionColumnDataType, timestampFormatter, dateFormatter);
                    if (listValue instanceof String) {
                        listValue = ByteUtil.toBytes((String) listValue);
                    }
                    if (comparator.compare(listValue, filterValue) < 0) {
                        partitionMap.set(i + 1);
                        continue outer4;
                    }
                }
            }
        }
    }
    return partitionMap;
}
Also used : SerializableComparator(org.apache.carbondata.core.util.comparator.SerializableComparator) BitSet(java.util.BitSet) DataType(org.apache.carbondata.core.metadata.datatype.DataType) List(java.util.List)

Aggregations

SerializableComparator (org.apache.carbondata.core.util.comparator.SerializableComparator)13 BitSet (java.util.BitSet)10 DataType (org.apache.carbondata.core.metadata.datatype.DataType)7 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CarbonMeasure (org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure)1 FilterUnsupportedException (org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)1 ColumnFilterInfo (org.apache.carbondata.core.scan.filter.ColumnFilterInfo)1