Java Code Examples for org.apache.kylin.metadata.filter.CompareTupleFilter#getOperator()

The following examples show how to use org.apache.kylin.metadata.filter.CompareTupleFilter#getOperator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CubeStorageEngine.java    From Kylin with Apache License 2.0 6 votes vote down vote up
private Collection<ColumnValueRange> translateToAndDimRanges(List<? extends TupleFilter> andFilters, CubeSegment cubeSegment) {
    Map<TblColRef, ColumnValueRange> rangeMap = new HashMap<TblColRef, ColumnValueRange>();
    for (TupleFilter filter : andFilters) {
        if ((filter instanceof CompareTupleFilter) == false) {
            continue;
        }

        CompareTupleFilter comp = (CompareTupleFilter) filter;
        if (comp.getColumn() == null) {
            continue;
        }

        ColumnValueRange range = new ColumnValueRange(comp.getColumn(), comp.getValues(), comp.getOperator());
        andMerge(range, rangeMap);

    }
    return rangeMap.values();
}
 
Example 2
Source File: GTCubeStorageQueryBase.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
protected Set<CompareTupleFilter> findSingleValuesCompFilters(TupleFilter filter) {
    Collection<? extends TupleFilter> toCheck;
    if (filter instanceof CompareTupleFilter) {
        toCheck = Collections.singleton(filter);
    } else if (filter instanceof LogicalTupleFilter && filter.getOperator() == FilterOperatorEnum.AND) {
        toCheck = filter.getChildren();
    } else {
        return Collections.emptySet();
    }

    Set<CompareTupleFilter> result = Sets.newHashSet();
    for (TupleFilter f : toCheck) {
        if (f instanceof CompareTupleFilter) {
            CompareTupleFilter compFilter = (CompareTupleFilter) f;
            // is COL=const ?
            if (compFilter.getOperator() == FilterOperatorEnum.EQ && compFilter.getValues().size() == 1
                    && compFilter.getColumn() != null) {
                result.add(compFilter);
            }
        }
    }
    return result;
}
 
Example 3
Source File: InvertIndexSearcher.java    From kylin with Apache License 2.0 6 votes vote down vote up
private EvalResult doEvalCompare(CompareTupleFilter filter) {
    switch (filter.getOperator()) {
    case EQ:
        return doEvalCompareEqual(filter);
    case IN:
        return doEvalCompareIn(filter);
    case ISNULL:
        return doEvalCompareIsNull(filter);
    case ISNOTNULL:
        return doEvalCompareIsNotNull(filter);
    case NEQ:
        return doEvalCompareNotEqual(filter);
    case NOTIN:
        return doEvalCompareNotIn(filter);
    case LT:
        return doEvalCompareLT(filter);
    case LTE:
        return doEvalCompareLTE(filter);
    case GT:
        return doEvalCompareGT(filter);
    case GTE:
        return doEvalCompareGTE(filter);
    default:
        throw new IllegalStateException("Unsupported operator " + filter.getOperator());
    }
}
 
Example 4
Source File: BitMapFilterEvaluator.java    From Kylin with Apache License 2.0 6 votes vote down vote up
private ConciseSet evalCompare(CompareTupleFilter filter) {
    switch (filter.getOperator()) {
    case ISNULL:
        return evalCompareIsNull(filter);
    case ISNOTNULL:
        return evalCompareIsNotNull(filter);
    case EQ:
        return evalCompareEqual(filter);
    case NEQ:
        return evalCompareNotEqual(filter);
    case IN:
        return evalCompareIn(filter);
    case NOTIN:
        return evalCompareNotIn(filter);
    case LT:
        return evalCompareLT(filter);
    case LTE:
        return evalCompareLTE(filter);
    case GT:
        return evalCompareGT(filter);
    case GTE:
        return evalCompareGTE(filter);
    default:
        throw new IllegalStateException("Unsupported operator " + filter.getOperator());
    }
}
 
Example 5
Source File: InvertIndexSearcher.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private EvalResult doEvalCompare(CompareTupleFilter filter) {
    switch (filter.getOperator()) {
    case EQ:
        return doEvalCompareEqual(filter);
    case IN:
        return doEvalCompareIn(filter);
    case ISNULL:
        return doEvalCompareIsNull(filter);
    case ISNOTNULL:
        return doEvalCompareIsNotNull(filter);
    case NEQ:
        return doEvalCompareNotEqual(filter);
    case NOTIN:
        return doEvalCompareNotIn(filter);
    case LT:
        return doEvalCompareLT(filter);
    case LTE:
        return doEvalCompareLTE(filter);
    case GT:
        return doEvalCompareGT(filter);
    case GTE:
        return doEvalCompareGTE(filter);
    default:
        throw new IllegalStateException("Unsupported operator " + filter.getOperator());
    }
}
 
Example 6
Source File: GTCubeStorageQueryBase.java    From kylin with Apache License 2.0 6 votes vote down vote up
protected Set<CompareTupleFilter> findSingleValuesCompFilters(TupleFilter filter) {
    Collection<? extends TupleFilter> toCheck;
    if (filter instanceof CompareTupleFilter) {
        toCheck = Collections.singleton(filter);
    } else if (filter instanceof LogicalTupleFilter && filter.getOperator() == FilterOperatorEnum.AND) {
        toCheck = filter.getChildren();
    } else {
        return Collections.emptySet();
    }

    Set<CompareTupleFilter> result = Sets.newHashSet();
    for (TupleFilter f : toCheck) {
        if (f instanceof CompareTupleFilter) {
            CompareTupleFilter compFilter = (CompareTupleFilter) f;
            // is COL=const ?
            if (compFilter.getOperator() == FilterOperatorEnum.EQ && compFilter.getValues().size() == 1
                    && compFilter.getColumn() != null) {
                result.add(compFilter);
            }
        }
    }
    return result;
}
 
Example 7
Source File: CubeStorageEngine.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Set<TblColRef> findSingleValueColumns(TupleFilter filter) {
    Collection<? extends TupleFilter> toCheck;
    if (filter instanceof CompareTupleFilter) {
        toCheck = Collections.singleton(filter);
    } else if (filter instanceof LogicalTupleFilter && filter.getOperator() == FilterOperatorEnum.AND) {
        toCheck = filter.getChildren();
    } else {
        return (Set<TblColRef>) Collections.EMPTY_SET;
    }

    Set<TblColRef> result = Sets.newHashSet();
    for (TupleFilter f : toCheck) {
        if (f instanceof CompareTupleFilter) {
            CompareTupleFilter compFilter = (CompareTupleFilter) f;
            // is COL=const ?
            if (compFilter.getOperator() == FilterOperatorEnum.EQ && compFilter.getValues().size() == 1 && compFilter.getColumn() != null) {
                result.add(compFilter.getColumn());
            }
        }
    }

    // expand derived
    Set<TblColRef> resultD = Sets.newHashSet();
    for (TblColRef col : result) {
        if (cubeDesc.isDerived(col)) {
            DeriveInfo hostInfo = cubeDesc.getHostInfo(col);
            if (hostInfo.isOneToOne) {
                for (TblColRef hostCol : hostInfo.columns) {
                    resultD.add(hostCol);
                }
            }
            //if not one2one, it will be pruned
        } else {
            resultD.add(col);
        }
    }
    return resultD;
}
 
Example 8
Source File: ScanRangePlannerBase.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private Collection<ColumnRange> translateToAndDimRanges(List<? extends TupleFilter> andFilters) {
    Map<TblColRef, ColumnRange> rangeMap = new HashMap<TblColRef, ColumnRange>();
    for (TupleFilter filter : andFilters) {
        if ((filter instanceof CompareTupleFilter) == false) {
            if (filter instanceof ConstantTupleFilter && !filter.evaluate(null, null)) {
                return null;
            } else {
                continue;
            }
        }

        CompareTupleFilter comp = (CompareTupleFilter) filter;
        if (comp.getColumn() == null) {
            continue;
        }

        @SuppressWarnings("unchecked")
        ColumnRange newRange = new ColumnRange(comp.getColumn(), (Set<ByteArray>) comp.getValues(), comp.getOperator());
        ColumnRange existing = rangeMap.get(newRange.column);
        if (existing == null) {
            rangeMap.put(newRange.column, newRange);
        } else {
            existing.andMerge(newRange);
        }
    }
    return rangeMap.values();
}
 
Example 9
Source File: SegmentPruner.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static boolean satisfy(CompareTupleFilter comp, String minVal, String maxVal) {

        // When both min and max are null, it means all cells of the column are null.
        // In such case, return true to let query engine scan the segment, since the
        // result of null comparison is query engine specific.
        if (minVal == null && maxVal == null)
            return true;
        
        // pass on non-constant filter
        if (comp.getChildren().size() > 1 && !(comp.getChildren().get(1) instanceof ConstantTupleFilter))
            return true;

        TblColRef col = comp.getColumn();
        DataTypeOrder order = col.getType().getOrder();
        String filterVal = toString(comp.getFirstValue());
        
        switch (comp.getOperator()) {
        case EQ:
        case IN:
            for (String filterValue : (Set<String>) comp.getValues()) {
                if (order.compare(filterValue, maxVal) <= 0 && order.compare(minVal, filterValue) <= 0)
                    return true;
            }
            return false;
        case LT:
            return order.compare(minVal, filterVal) < 0;
        case LTE:
            return order.compare(minVal, filterVal) <= 0;
        case GT:
            return order.compare(maxVal, filterVal) > 0;
        case GTE:
            return order.compare(maxVal, filterVal) >= 0;
        case NEQ:
        case NOTIN:
        case ISNULL:
        case ISNOTNULL:
        default:
            return true;
        }
    }
 
Example 10
Source File: SegmentPruner.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static boolean satisfy(CompareTupleFilter comp, String minVal, String maxVal) {

        // When both min and max are null, it means all cells of the column are null.
        // In such case, return true to let query engine scan the segment, since the
        // result of null comparison is query engine specific.
        if (minVal == null && maxVal == null)
            return true;
        
        // pass on non-constant filter
        if (comp.getChildren().size() <= 1 || !isConstantValue(comp.getChildren().get(1)))
            return true;

        TblColRef col = comp.getColumn();
        DataTypeOrder order = col.getType().getOrder();
        String filterVal = toString(comp.getFirstValue());
        
        switch (comp.getOperator()) {
        case EQ:
        case IN:
            for (String filterValue : (Set<String>) comp.getValues()) {
                if (order.compare(filterValue, maxVal) <= 0 && order.compare(minVal, filterValue) <= 0)
                    return true;
            }
            return false;
        case LT:
            return order.compare(minVal, filterVal) < 0;
        case LTE:
            return order.compare(minVal, filterVal) <= 0;
        case GT:
            return order.compare(maxVal, filterVal) > 0;
        case GTE:
            return order.compare(maxVal, filterVal) >= 0;
        case NEQ:
        case NOTIN:
        case ISNULL:
        case ISNOTNULL:
        default:
            return true;
        }
    }
 
Example 11
Source File: ScanRangePlannerBase.java    From kylin with Apache License 2.0 5 votes vote down vote up
private Collection<ColumnRange> translateToAndDimRanges(List<? extends TupleFilter> andFilters) {
    Map<TblColRef, ColumnRange> rangeMap = new HashMap<TblColRef, ColumnRange>();
    for (TupleFilter filter : andFilters) {
        if ((filter instanceof CompareTupleFilter) == false) {
            if (filter instanceof ConstantTupleFilter && !filter.evaluate(null, null)) {
                return null;
            } else {
                continue;
            }
        }

        CompareTupleFilter comp = (CompareTupleFilter) filter;
        if (comp.getColumn() == null) {
            continue;
        }

        @SuppressWarnings("unchecked")
        ColumnRange newRange = new ColumnRange(comp.getColumn(), (Set<ByteArray>) comp.getValues(),
                comp.getOperator());
        ColumnRange existing = rangeMap.get(newRange.column);
        if (existing == null) {
            rangeMap.put(newRange.column, newRange);
        } else {
            existing.andMerge(newRange);
        }
    }
    return rangeMap.values();
}
 
Example 12
Source File: TsConditionExtractor.java    From kylin with Apache License 2.0 4 votes vote down vote up
private static Range<Long> extractTsConditionInternal(TupleFilter filter, TblColRef colRef) {
    if (filter == null) {
        return Range.all();
    }

    if (filter instanceof LogicalTupleFilter) {
        if (filter.getOperator() == TupleFilter.FilterOperatorEnum.AND) {
            Range<Long> ret = Range.all();
            for (TupleFilter child : filter.getChildren()) {
                Range childRange = extractTsConditionInternal(child, colRef);
                if (childRange != null) {
                    if (ret.isConnected(childRange) && !ret.intersection(childRange).isEmpty()) {
                        ret = ret.intersection(childRange);
                    } else {
                        return null;
                    }
                } else {
                    return null;
                }
            }
            return ret.isEmpty() ? null : ret;
        } else {
            //for conditions like date > DATE'2000-11-11' OR date < DATE '1999-01-01'
            //we will use Ranges.all() rather than two ranges to represent them
            return Range.all();
        }
    }

    if (filter instanceof CompareTupleFilter) {
        CompareTupleFilter compareTupleFilter = (CompareTupleFilter) filter;
        if (compareTupleFilter.getColumn() == null)// column will be null at filters like " 1<>1"
            return Range.all();

        if (compareTupleFilter.getColumn().equals(colRef)) {
            Object firstValue = compareTupleFilter.getFirstValue();
            long t;
            switch (compareTupleFilter.getOperator()) {
            case EQ:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.closed(t, t);
            case LT:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.lessThan(t);
            case LTE:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.atMost(t);
            case GT:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.greaterThan(t);
            case GTE:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.atLeast(t);
            case NEQ:
            case IN://not handled for now
                break;
            default:
            }
        }
    }
    return Range.all();
}
 
Example 13
Source File: CompareFilterTimeRangeChecker.java    From kylin with Apache License 2.0 4 votes vote down vote up
public CheckResult check(CompareTupleFilter compFilter, TimeDerivedColumnType timeDerivedColumnType, long timezoneOffset) {
    Object timestampValue = compFilter.getFirstValue();
    Set conditionValues = compFilter.getValues();
    Pair<Long, Long> timeUnitRange;
    if (timeDerivedColumnType != TimeDerivedColumnType.MINUTE_START
            && timeDerivedColumnType != TimeDerivedColumnType.HOUR_START) {
        timeUnitRange = timezoneOffset == 0 ? timeDerivedColumnType.getTimeUnitRange(timestampValue)
                : timeDerivedColumnType.getTimeUnitRangeTimezoneAware(timestampValue, timezoneOffset);
    } else {
        timeUnitRange = timeDerivedColumnType.getTimeUnitRange(timestampValue);
    }
    switch (compFilter.getOperator()) {
    case EQ:
        return checkForEqValue(timeUnitRange);
    case NEQ:
        if (timeUnitRange.getFirst() <= timeStart && timeUnitRange.getSecond() >= timeEnd) {
            return CheckResult.EXCLUDED;
        }
        if (timeUnitRange.getSecond() <= timeStart || timeUnitRange.getFirst() >= timeEnd) {
            return CheckResult.INCLUDED;
        }
        return CheckResult.OVERLAP;
    case LT:
        if ((!endClose && timeUnitRange.getFirst() >= timeEnd) || (endClose && timeUnitRange.getFirst() > timeEnd)) {
            return CheckResult.INCLUDED;
        }
        if (timeUnitRange.getFirst() <= timeStart) {
            return CheckResult.EXCLUDED;
        }
        return CheckResult.OVERLAP;
    case LTE:
        if (timeUnitRange.getFirst() >= timeEnd) {
            return CheckResult.INCLUDED;
        }
        if (timeUnitRange.getSecond() < timeStart) {
            return CheckResult.EXCLUDED;
        }
        return CheckResult.OVERLAP;
    case GT:
        if (timeUnitRange.getSecond() < timeStart) {
            return CheckResult.INCLUDED;
        }
        if (timeUnitRange.getFirst() >= timeEnd) {
            return CheckResult.EXCLUDED;
        }
        return CheckResult.OVERLAP;
    case GTE:
        if (timeUnitRange.getFirst() <= timeStart) {
            return CheckResult.INCLUDED;
        }
        if ((!endClose && timeUnitRange.getFirst() >= timeEnd) || (endClose && timeUnitRange.getFirst() > timeEnd)) {
            return CheckResult.EXCLUDED;
        }
        return CheckResult.OVERLAP;
    case IN:
        return checkForInValues(timeDerivedColumnType, conditionValues, timezoneOffset);
    default:
        return CheckResult.OVERLAP;
    }
}
 
Example 14
Source File: StreamingBuiltInFunctionTransformer.java    From kylin with Apache License 2.0 4 votes vote down vote up
protected BuildInFuncCompareTupleFilter(CompareTupleFilter delegate) {
    super(new ArrayList<>(delegate.getChildren()), delegate.getOperator());
    this.delegate = delegate;
    this.buildInFunctionTupleFilter = (BuiltInFunctionTupleFilter) delegate.getFunction();
}
 
Example 15
Source File: FilterDecorator.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public TupleFilter onSerialize(TupleFilter filter) {
    if (filter == null)
        return null;

    BuiltInFunctionTransformer translator = new BuiltInFunctionTransformer(dimEncMap);
    filter = translator.transform(filter);

    // un-evaluatable filter is replaced with TRUE
    if (!filter.isEvaluable()) {
        TupleFilter.collectColumns(filter, inevaluableColumns);
        return ConstantTupleFilter.TRUE;
    }

    if (!(filter instanceof CompareTupleFilter))
        return filter;

    // double check all internal of CompareTupleFilter is evaluatable
    if (!TupleFilter.isEvaluableRecursively(filter)) {
        TupleFilter.collectColumns(filter, inevaluableColumns);
        return ConstantTupleFilter.TRUE;
    }

    if (filterConstantsTreatment == FilterConstantsTreatment.AS_IT_IS) {
        return filter;
    } else {

        // extract ColumnFilter & ConstantFilter
        CompareTupleFilter compareFilter = (CompareTupleFilter) filter;
        TblColRef col = compareFilter.getColumn();

        if (col == null) {
            return filter;
        }

        Collection<String> constValues = (Collection<String>) compareFilter.getValues();
        if (constValues == null || constValues.isEmpty()) {
            return filter;
        }

        CompareTupleFilter newCompareFilter = new CompareTupleFilter(compareFilter.getOperator());
        newCompareFilter.addChild(new ColumnTupleFilter(col));

        if (filterConstantsTreatment == FilterConstantsTreatment.REPLACE_WITH_GLOBAL_DICT) {
            return replaceConstantsWithGlobalDict(compareFilter, newCompareFilter);
        } else if (filterConstantsTreatment == FilterConstantsTreatment.REPLACE_WITH_LOCAL_DICT) {
            return replaceConstantsWithLocalDict(compareFilter, newCompareFilter);
        } else {
            throw new RuntimeException("should not reach here");
        }
    }
}
 
Example 16
Source File: BuiltInFunctionTransformer.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private TupleFilter translateCompareTupleFilter(CompareTupleFilter compTupleFilter) {
    if (compTupleFilter.getFunction() == null
            || (!(compTupleFilter.getFunction() instanceof BuiltInFunctionTupleFilter)))
        return null;

    BuiltInFunctionTupleFilter builtInFunctionTupleFilter = (BuiltInFunctionTupleFilter) compTupleFilter
            .getFunction();

    if (!builtInFunctionTupleFilter.isValid())
        return null;

    TblColRef columnRef = builtInFunctionTupleFilter.getColumn();
    if (columnRef == null) {
        return null;
    }
    Dictionary<?> dict = dimEncMap.getDictionary(columnRef);
    if (dict == null)
        return null;

    CompareTupleFilter translated = new CompareTupleFilter(
            builtInFunctionTupleFilter.isReversed() ? FilterOperatorEnum.NOTIN : FilterOperatorEnum.IN);
    translated.addChild(new ColumnTupleFilter(columnRef));

    try {
        Collection<Object> inValues = Lists.newArrayList();
        for (int i = dict.getMinId(); i <= dict.getMaxId(); i++) {
            Object dictVal = dict.getValueFromId(i);
            Object computedVal = builtInFunctionTupleFilter.invokeFunction(dictVal);
            Class clazz = Primitives.wrap(computedVal.getClass());
            Object targetVal = compTupleFilter.getFirstValue();
            if (Primitives.isWrapperType(clazz))
                targetVal = clazz.cast(clazz.getDeclaredMethod("valueOf", String.class).invoke(null,
                        compTupleFilter.getFirstValue()));

            int comp = ((Comparable) computedVal).compareTo(targetVal);
            boolean compResult = false;
            switch (compTupleFilter.getOperator()) {
            case EQ:
                compResult = comp == 0;
                break;
            case NEQ:
                compResult = comp != 0;
                break;
            case LT:
                compResult = comp < 0;
                break;
            case LTE:
                compResult = comp <= 0;
                break;
            case GT:
                compResult = comp > 0;
                break;
            case GTE:
                compResult = comp >= 0;
                break;
            case IN:
                compResult = compTupleFilter.getValues().contains(computedVal.toString());
                break;
            case NOTIN:
                compResult = !compTupleFilter.getValues().contains(computedVal.toString());
                break;
            default:
                break;
            }
            if (compResult) {
                inValues.add(dictVal);
            }
        }
        translated.addChild(new ConstantTupleFilter(inValues));
    } catch (Exception e) {
        logger.debug(e.getMessage());
        return null;
    }
    return translated;
}
 
Example 17
Source File: BuiltInFunctionTransformer.java    From kylin with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private TupleFilter translateCompareTupleFilter(CompareTupleFilter compTupleFilter) {
    if (compTupleFilter.getFunction() == null
            || (!(compTupleFilter.getFunction() instanceof BuiltInFunctionTupleFilter)))
        return null;

    BuiltInFunctionTupleFilter builtInFunctionTupleFilter = (BuiltInFunctionTupleFilter) compTupleFilter
            .getFunction();

    if (!builtInFunctionTupleFilter.isValid())
        return null;

    TblColRef columnRef = builtInFunctionTupleFilter.getColumn();
    if (columnRef == null) {
        return null;
    }
    Dictionary<?> dict = dimEncMap.getDictionary(columnRef);
    if (dict == null)
        return null;

    CompareTupleFilter translated = new CompareTupleFilter(
            builtInFunctionTupleFilter.isReversed() ? FilterOperatorEnum.NOTIN : FilterOperatorEnum.IN);
    translated.addChild(new ColumnTupleFilter(columnRef));

    try {
        Collection<Object> inValues = Lists.newArrayList();
        for (int i = dict.getMinId(); i <= dict.getMaxId(); i++) {
            Object dictVal = dict.getValueFromId(i);
            Object computedVal = builtInFunctionTupleFilter.invokeFunction(dictVal);
            Class clazz = Primitives.wrap(computedVal.getClass());
            Object targetVal = compTupleFilter.getFirstValue();
            if (Primitives.isWrapperType(clazz))
                targetVal = clazz.cast(clazz.getDeclaredMethod("valueOf", String.class).invoke(null,
                        compTupleFilter.getFirstValue()));

            int comp = ((Comparable) computedVal).compareTo(targetVal);
            boolean compResult = false;
            switch (compTupleFilter.getOperator()) {
            case EQ:
                compResult = comp == 0;
                break;
            case NEQ:
                compResult = comp != 0;
                break;
            case LT:
                compResult = comp < 0;
                break;
            case LTE:
                compResult = comp <= 0;
                break;
            case GT:
                compResult = comp > 0;
                break;
            case GTE:
                compResult = comp >= 0;
                break;
            case IN:
                compResult = compTupleFilter.getValues().contains(computedVal.toString());
                break;
            case NOTIN:
                compResult = !compTupleFilter.getValues().contains(computedVal.toString());
                break;
            default:
                break;
            }
            if (compResult) {
                inValues.add(dictVal);
            }
        }
        translated.addChild(new ConstantTupleFilter(inValues));
    } catch (Exception e) {
        logger.debug(e.getMessage());
        return null;
    }
    return translated;
}
 
Example 18
Source File: StreamingBuiltInFunctionTransformer.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
protected BuildInFuncCompareTupleFilter(CompareTupleFilter delegate) {
    super(new ArrayList<>(delegate.getChildren()), delegate.getOperator());
    this.delegate = delegate;
    this.buildInFunctionTupleFilter = (BuiltInFunctionTupleFilter) delegate.getFunction();
}
 
Example 19
Source File: FilterDecorator.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public TupleFilter onSerialize(TupleFilter filter) {
    if (filter == null)
        return null;

    BuiltInFunctionTransformer translator = new BuiltInFunctionTransformer(dimEncMap);
    filter = translator.transform(filter);

    // un-evaluatable filter is replaced with TRUE
    if (!filter.isEvaluable()) {
        TupleFilter.collectColumns(filter, inevaluableColumns);
        return ConstantTupleFilter.TRUE;
    }

    if (!(filter instanceof CompareTupleFilter))
        return filter;

    // double check all internal of CompareTupleFilter is evaluatable
    if (!TupleFilter.isEvaluableRecursively(filter)) {
        TupleFilter.collectColumns(filter, inevaluableColumns);
        return ConstantTupleFilter.TRUE;
    }

    if (filterConstantsTreatment == FilterConstantsTreatment.AS_IT_IS) {
        return filter;
    } else {

        // extract ColumnFilter & ConstantFilter
        CompareTupleFilter compareFilter = (CompareTupleFilter) filter;
        TblColRef col = compareFilter.getColumn();

        if (col == null) {
            return filter;
        }

        Collection<String> constValues = (Collection<String>) compareFilter.getValues();
        if (constValues == null || constValues.isEmpty()) {
            return filter;
        }

        CompareTupleFilter newCompareFilter = new CompareTupleFilter(compareFilter.getOperator());
        newCompareFilter.addChild(new ColumnTupleFilter(col));

        if (filterConstantsTreatment == FilterConstantsTreatment.REPLACE_WITH_GLOBAL_DICT) {
            return replaceConstantsWithGlobalDict(compareFilter, newCompareFilter);
        } else if (filterConstantsTreatment == FilterConstantsTreatment.REPLACE_WITH_LOCAL_DICT) {
            return replaceConstantsWithLocalDict(compareFilter, newCompareFilter);
        } else {
            throw new RuntimeException("should not reach here");
        }
    }
}
 
Example 20
Source File: TsConditionExtractor.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
private static Range<Long> extractTsConditionInternal(TupleFilter filter, TblColRef colRef) {
    if (filter == null) {
        return Range.all();
    }

    if (filter instanceof LogicalTupleFilter) {
        if (filter.getOperator() == TupleFilter.FilterOperatorEnum.AND) {
            Range<Long> ret = Range.all();
            for (TupleFilter child : filter.getChildren()) {
                Range childRange = extractTsConditionInternal(child, colRef);
                if (childRange != null) {
                    if (ret.isConnected(childRange) && !ret.intersection(childRange).isEmpty()) {
                        ret = ret.intersection(childRange);
                    } else {
                        return null;
                    }
                } else {
                    return null;
                }
            }
            return ret.isEmpty() ? null : ret;
        } else {
            //for conditions like date > DATE'2000-11-11' OR date < DATE '1999-01-01'
            //we will use Ranges.all() rather than two ranges to represent them
            return Range.all();
        }
    }

    if (filter instanceof CompareTupleFilter) {
        CompareTupleFilter compareTupleFilter = (CompareTupleFilter) filter;
        if (compareTupleFilter.getColumn() == null)// column will be null at filters like " 1<>1"
            return Range.all();

        if (compareTupleFilter.getColumn().equals(colRef)) {
            Object firstValue = compareTupleFilter.getFirstValue();
            long t;
            switch (compareTupleFilter.getOperator()) {
            case EQ:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.closed(t, t);
            case LT:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.lessThan(t);
            case LTE:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.atMost(t);
            case GT:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.greaterThan(t);
            case GTE:
                t = DateFormat.stringToMillis((String) firstValue);
                return Range.atLeast(t);
            case NEQ:
            case IN://not handled for now
                break;
            default:
            }
        }
    }
    return Range.all();
}