org.apache.kylin.metadata.filter.TupleFilter.FilterOperatorEnum Java Examples

The following examples show how to use org.apache.kylin.metadata.filter.TupleFilter.FilterOperatorEnum. 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: StreamingSegmentManagerTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testOneValueAggregation() {
    genEvents(80000);
    StreamingCubeDataSearcher searcher = streamingSegmentManager.getSearcher();
    String startTimeStr = "2018-07-30 20:00:00";
    long startTime = DateFormat.stringToMillis(startTimeStr);
    String endTimeStr = "2018-07-30 20:04:00";
    long endTime = DateFormat.stringToMillis(endTimeStr);
    CompareTupleFilter filter1 = testHelper.buildCompareFilter("STREAMING_V2_TABLE.MINUTE_START",
        FilterOperatorEnum.GTE, startTimeStr);
    CompareTupleFilter filter2 = testHelper.buildCompareFilter("STREAMING_V2_TABLE.MINUTE_START",
        FilterOperatorEnum.LT, endTimeStr);
    TupleFilter filter = testHelper.buildAndFilter(filter1, filter2);
    Set<FunctionDesc> metrics = Sets.newHashSet(testHelper.simulateCountMetric());
    Set<TblColRef> dimensions = testHelper.simulateDimensions("STREAMING_V2_TABLE.MINUTE_START");
    Set<TblColRef> groups = Sets.newHashSet();
    StreamingSearchContext searchRequest = new StreamingSearchContext(cubeDesc, dimensions, groups, metrics, filter,
        null);
    IStreamingSearchResult segmentResults1 = searcher.doSearch(searchRequest, -1, true);
    for (Record record : segmentResults1) {
        long minStart = Long.valueOf(record.getDimensions()[0]);
        assertTrue(startTime <= minStart && minStart < endTime);
        System.out.println(record);
    }
}
 
Example #2
Source File: FilterBaseTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
protected CompareTupleFilter buildINCompareFilter(TblColRef dateColumn) throws ParseException {
    CompareTupleFilter compareFilter = new CompareTupleFilter(FilterOperatorEnum.IN);
    ColumnTupleFilter columnFilter = new ColumnTupleFilter(dateColumn);
    compareFilter.addChild(columnFilter);

    List<String> inValues = Lists.newArrayList();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);
    Date startDate = simpleDateFormat.parse("1970-01-01");
    Date endDate = simpleDateFormat.parse("2100-01-01");
    Calendar start = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ROOT);
    start.setTime(startDate);
    Calendar end = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ROOT);
    end.setTime(endDate);
    for (Date date = start.getTime(); start.before(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
        inValues.add(simpleDateFormat.format(date));
    }

    ConstantTupleFilter constantFilter = new ConstantTupleFilter(inValues);
    compareFilter.addChild(constantFilter);
    return compareFilter;
}
 
Example #3
Source File: StreamingDataQueryPlanner.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
protected TupleFilter flattenToOrAndFilter(TupleFilter filter) {
    if (filter == null)
        return null;

    TupleFilter flatFilter = filter.flatFilter();

    // normalize to OR-AND filter
    if (flatFilter.getOperator() == FilterOperatorEnum.AND) {
        LogicalTupleFilter f = new LogicalTupleFilter(FilterOperatorEnum.OR);
        f.addChild(flatFilter);
        flatFilter = f;
    }

    if (flatFilter.getOperator() != FilterOperatorEnum.OR)
        throw new IllegalStateException();

    return flatFilter;
}
 
Example #4
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 #5
Source File: TupleFilterTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testMustTrueTupleFilter() {
    TupleFilter andFilter = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND);
    TupleFilter andFilter2  = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND);
    TupleFilter orFilter = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR);
    andFilter.addChild(andFilter2);
    andFilter.addChild(orFilter);

    Set<CompareTupleFilter> trueTupleFilters = andFilter.findMustTrueCompareFilters();
    Assert.assertTrue(trueTupleFilters.isEmpty());

    TupleFilter compFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.GT);
    compFilter.addChild(new ColumnTupleFilter(TblColRef.newInnerColumn("test1", TblColRef.InnerDataTypeEnum.LITERAL)));
    TupleFilter compFilter2 = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.GT);
    compFilter2.addChild(new ColumnTupleFilter(TblColRef.newInnerColumn("test2", TblColRef.InnerDataTypeEnum.LITERAL)));
    andFilter2.addChild(compFilter);
    orFilter.addChild(compFilter2);
    Assert.assertEquals(Sets.newHashSet(compFilter), andFilter.findMustTrueCompareFilters());
    
    Assert.assertEquals(Sets.newHashSet(compFilter2), compFilter2.findMustTrueCompareFilters());
}
 
Example #6
Source File: DictGridTableTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyConvertFilterConstants1() {
    GTInfo info = table.getInfo();

    TableDesc extTable = TableDesc.mockup("ext");
    TblColRef extColA = TblColRef.mockup(extTable, 1, "A", "timestamp");
    TblColRef extColB = TblColRef.mockup(extTable, 2, "B", "integer");

    CompareTupleFilter fComp1 = compare(extColA, FilterOperatorEnum.GT, "2015-01-14");
    CompareTupleFilter fComp2 = compare(extColB, FilterOperatorEnum.EQ, "10");
    LogicalTupleFilter filter = and(fComp1, fComp2);

    List<TblColRef> colMapping = Lists.newArrayList();
    colMapping.add(extColA);
    colMapping.add(extColB);

    TupleFilter newFilter = GTUtil.convertFilterColumnsAndConstants(filter, info, colMapping, null);
    assertEquals(
            "AND [UNKNOWN_MODEL:NULL.GT_MOCKUP_TABLE.0 GT [\\x00\\x00\\x01J\\xE5\\xBD\\x5C\\x00], UNKNOWN_MODEL:NULL.GT_MOCKUP_TABLE.1 EQ [\\x00]]",
            newFilter.toString());
}
 
Example #7
Source File: DictGridTableTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyConvertFilterConstants1() {
    GTInfo info = table.getInfo();

    TableDesc extTable = TableDesc.mockup("ext");
    TblColRef extColA = TblColRef.mockup(extTable, 1, "A", "timestamp");
    TblColRef extColB = TblColRef.mockup(extTable, 2, "B", "integer");

    CompareTupleFilter fComp1 = compare(extColA, FilterOperatorEnum.GT, "2015-01-14");
    CompareTupleFilter fComp2 = compare(extColB, FilterOperatorEnum.EQ, "10");
    LogicalTupleFilter filter = and(fComp1, fComp2);

    List<TblColRef> colMapping = Lists.newArrayList();
    colMapping.add(extColA);
    colMapping.add(extColB);

    TupleFilter newFilter = GTUtil.convertFilterColumnsAndConstants(filter, info, colMapping, null);
    assertEquals(
            "AND [UNKNOWN_MODEL:NULL.GT_MOCKUP_TABLE.0 GT [\\x00\\x00\\x01J\\xE5\\xBD\\x5C\\x00], UNKNOWN_MODEL:NULL.GT_MOCKUP_TABLE.1 EQ [\\x00]]",
            newFilter.toString());
}
 
Example #8
Source File: DictGridTableTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyScanWithEvaluatableFilter() throws IOException {
    GTInfo info = table.getInfo();

    CompareTupleFilter fComp1 = compare(info.colRef(0), FilterOperatorEnum.GT, enc(info, 0, "2015-01-14"));
    CompareTupleFilter fComp2 = compare(info.colRef(1), FilterOperatorEnum.GT, enc(info, 1, "10"));
    LogicalTupleFilter filter = and(fComp1, fComp2);

    GTScanRequest req = new GTScanRequestBuilder().setInfo(info).setRanges(null).setDimensions(null)
            .setAggrGroupBy(setOf(0)).setAggrMetrics(setOf(3)).setAggrMetricsFuncs(new String[] { "sum" })
            .setFilterPushDown(filter).createGTScanRequest();
    // note the evaluatable column 1 in filter is added to returned columns but not in group by
    assertEquals(
            "GTScanRequest [range=[[null, null]-[null, null]], columns={0, 1, 3}, filterPushDown=AND [UNKNOWN_MODEL:NULL.GT_MOCKUP_TABLE.0 GT [\\x00\\x00\\x01J\\xE5\\xBD\\x5C\\x00], UNKNOWN_MODEL:NULL.GT_MOCKUP_TABLE.1 GT [\\x00]], aggrGroupBy={0}, aggrMetrics={3}, aggrMetricsFuncs=[sum]]",
            req.toString());

    doScanAndVerify(table, useDeserializedGTScanRequest(req), "[1421280000000, 20, null, 30, null]",
            "[1421366400000, 20, null, 40, null]");
}
 
Example #9
Source File: DictGridTableTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyScanWithUnevaluatableFilter() throws IOException {
    GTInfo info = table.getInfo();

    CompareTupleFilter fComp = compare(info.colRef(0), FilterOperatorEnum.GT, enc(info, 0, "2015-01-14"));
    ExtractTupleFilter fUnevaluatable = unevaluatable(info.colRef(1));
    LogicalTupleFilter fNotPlusUnevaluatable = not(unevaluatable(info.colRef(1)));
    LogicalTupleFilter filter = and(fComp, fUnevaluatable, fNotPlusUnevaluatable);

    GTScanRequest req = new GTScanRequestBuilder().setInfo(info).setRanges(null).setDimensions(null)
            .setAggrGroupBy(setOf(0)).setAggrMetrics(setOf(3)).setAggrMetricsFuncs(new String[] { "sum" })
            .setFilterPushDown(filter).createGTScanRequest();

    // note the unEvaluatable column 1 in filter is added to group by
    assertEquals(
            "GTScanRequest [range=[[null, null]-[null, null]], columns={0, 1, 3}, filterPushDown=AND [UNKNOWN_MODEL:NULL.GT_MOCKUP_TABLE.0 GT [\\x00\\x00\\x01J\\xE5\\xBD\\x5C\\x00], [], []], aggrGroupBy={0, 1}, aggrMetrics={3}, aggrMetricsFuncs=[sum]]",
            req.toString());

    doScanAndVerify(table, useDeserializedGTScanRequest(req), "[1421280000000, 20, null, 20, null]",
            "[1421280000000, 30, null, 10, null]", "[1421366400000, 20, null, 20, null]",
            "[1421366400000, 30, null, 20, null]", "[1421452800000, 10, null, 10, null]");
}
 
Example #10
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 #11
Source File: CubeStorageEngine.java    From Kylin with Apache License 2.0 6 votes vote down vote up
private TupleFilter flattenToOrAndFilter(TupleFilter filter) {
    if (filter == null)
        return null;

    TupleFilter flatFilter = filter.flatFilter();

    // normalize to OR-AND filter
    if (flatFilter.getOperator() == FilterOperatorEnum.AND) {
        LogicalTupleFilter f = new LogicalTupleFilter(FilterOperatorEnum.OR);
        f.addChild(flatFilter);
        flatFilter = f;
    }

    if (flatFilter.getOperator() != FilterOperatorEnum.OR)
        throw new IllegalStateException();

    return flatFilter;
}
 
Example #12
Source File: StreamingSegmentManagerTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testOneValueAggregation() {
    genEvents(80000);
    StreamingCubeDataSearcher searcher = streamingSegmentManager.getSearcher();
    String startTimeStr = "2018-07-30 20:00:00";
    long startTime = DateFormat.stringToMillis(startTimeStr);
    String endTimeStr = "2018-07-30 20:04:00";
    long endTime = DateFormat.stringToMillis(endTimeStr);
    CompareTupleFilter filter1 = testHelper.buildCompareFilter("STREAMING_V2_TABLE.MINUTE_START",
        FilterOperatorEnum.GTE, startTimeStr);
    CompareTupleFilter filter2 = testHelper.buildCompareFilter("STREAMING_V2_TABLE.MINUTE_START",
        FilterOperatorEnum.LT, endTimeStr);
    TupleFilter filter = testHelper.buildAndFilter(filter1, filter2);
    Set<FunctionDesc> metrics = Sets.newHashSet(testHelper.simulateCountMetric());
    Set<TblColRef> dimensions = testHelper.simulateDimensions("STREAMING_V2_TABLE.MINUTE_START");
    Set<TblColRef> groups = Sets.newHashSet();
    StreamingSearchContext searchRequest = new StreamingSearchContext(cubeDesc, dimensions, groups, metrics, filter,
        null);
    IStreamingSearchResult segmentResults1 = searcher.doSearch(searchRequest, -1, true);
    for (Record record : segmentResults1) {
        long minStart = Long.valueOf(record.getDimensions()[0]);
        assertTrue(startTime <= minStart && minStart < endTime);
        System.out.println(record);
    }
}
 
Example #13
Source File: TupleFilterTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testMustTrueTupleFilter() {
    TupleFilter andFilter = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND);
    TupleFilter andFilter2  = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND);
    TupleFilter orFilter = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR);
    andFilter.addChild(andFilter2);
    andFilter.addChild(orFilter);

    Set<CompareTupleFilter> trueTupleFilters = andFilter.findMustTrueCompareFilters();
    Assert.assertTrue(trueTupleFilters.isEmpty());

    TupleFilter compFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.GT);
    compFilter.addChild(new ColumnTupleFilter(TblColRef.newInnerColumn("test1", TblColRef.InnerDataTypeEnum.LITERAL)));
    TupleFilter compFilter2 = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.GT);
    compFilter2.addChild(new ColumnTupleFilter(TblColRef.newInnerColumn("test2", TblColRef.InnerDataTypeEnum.LITERAL)));
    andFilter2.addChild(compFilter);
    orFilter.addChild(compFilter2);
    Assert.assertEquals(Sets.newHashSet(compFilter), andFilter.findMustTrueCompareFilters());
    
    Assert.assertEquals(Sets.newHashSet(compFilter2), compFilter2.findMustTrueCompareFilters());
}
 
Example #14
Source File: SegmentPrunerTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testPruneSegWithFilterIN() {
    // legacy cube segments does not have DimensionRangeInfo, but with TSRange can do some pruning
    CubeInstance cube = CubeManager.getInstance(getTestConfig())
            .getCube("test_kylin_cube_without_slr_left_join_ready_2_segments");
    TblColRef col = cube.getModel().findColumn("TEST_KYLIN_FACT.CAL_DT");
    CubeSegment seg = cube.getSegments(SegmentStatusEnum.READY).get(0);
    TSRange tsRange = seg.getTSRange();
    String start = DateFormat.formatToTimeStr(tsRange.start.v, "yyyy-MM-dd");
    CubeSegment seg2 = cube.getSegments(SegmentStatusEnum.READY).get(1);
    TSRange tsRange2 = seg2.getTSRange();
    try (SetAndUnsetSystemProp sns = new SetAndUnsetSystemProp("kylin.query.skip-empty-segments", "false")) {

        {
            TupleFilter inFilter = new ConstantTupleFilter(Sets.newHashSet(start,
                    DateFormat.formatToTimeStr(tsRange2.end.v + 1000 * 60 * 60 * 24L, "yyyy-MM-dd")));
            TupleFilter filter = compare(col, FilterOperatorEnum.IN, inFilter);
            SegmentPruner segmentPruner = new SegmentPruner(filter);
            Assert.assertTrue(segmentPruner.check(seg));
            Assert.assertFalse(segmentPruner.check(seg2));

        }
    }
}
 
Example #15
Source File: DerivedFilterTranslator.java    From kylin with Apache License 2.0 6 votes vote down vote up
private static TupleFilter buildInFilter(TblColRef[] hostCols, Set<Array<String>> satisfyingHostRecords) {
    if (satisfyingHostRecords.size() == 0) {
        return ConstantTupleFilter.FALSE;
    }

    int hn = hostCols.length;
    if (hn == 1) {
        CompareTupleFilter in = new CompareTupleFilter(FilterOperatorEnum.IN);
        in.addChild(new ColumnTupleFilter(hostCols[0]));
        in.addChild(new ConstantTupleFilter(asValues(satisfyingHostRecords)));
        return in;
    } else {
        LogicalTupleFilter or = new LogicalTupleFilter(FilterOperatorEnum.OR);
        for (Array<String> rec : satisfyingHostRecords) {
            LogicalTupleFilter and = new LogicalTupleFilter(FilterOperatorEnum.AND);
            for (int i = 0; i < hn; i++) {
                CompareTupleFilter eq = new CompareTupleFilter(FilterOperatorEnum.EQ);
                eq.addChild(new ColumnTupleFilter(hostCols[i]));
                eq.addChild(new ConstantTupleFilter(rec.data[i]));
                and.addChild(eq);
            }
            or.addChild(and);
        }
        return or;
    }
}
 
Example #16
Source File: DerivedFilterTranslator.java    From kylin with Apache License 2.0 6 votes vote down vote up
private static LogicalTupleFilter buildRangeFilter(TblColRef[] hostCols, Set<Array<String>> satisfyingHostRecords) {
    int hn = hostCols.length;
    String[] min = new String[hn];
    String[] max = new String[hn];
    findMinMax(satisfyingHostRecords, hostCols, min, max);
    LogicalTupleFilter and = new LogicalTupleFilter(FilterOperatorEnum.AND);
    for (int i = 0; i < hn; i++) {
        CompareTupleFilter compMin = new CompareTupleFilter(FilterOperatorEnum.GTE);
        compMin.addChild(new ColumnTupleFilter(hostCols[i]));
        compMin.addChild(new ConstantTupleFilter(min[i]));
        and.addChild(compMin);
        CompareTupleFilter compMax = new CompareTupleFilter(FilterOperatorEnum.LTE);
        compMax.addChild(new ColumnTupleFilter(hostCols[i]));
        compMax.addChild(new ConstantTupleFilter(max[i]));
        and.addChild(compMax);
    }
    return and;
}
 
Example #17
Source File: DerivedFilterTranslator.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private static LogicalTupleFilter buildRangeFilter(TblColRef[] hostCols, Set<Array<String>> satisfyingHostRecords) {
    int hn = hostCols.length;
    String[] min = new String[hn];
    String[] max = new String[hn];
    findMinMax(satisfyingHostRecords, hostCols, min, max);
    LogicalTupleFilter and = new LogicalTupleFilter(FilterOperatorEnum.AND);
    for (int i = 0; i < hn; i++) {
        CompareTupleFilter compMin = new CompareTupleFilter(FilterOperatorEnum.GTE);
        compMin.addChild(new ColumnTupleFilter(hostCols[i]));
        compMin.addChild(new ConstantTupleFilter(min[i]));
        and.addChild(compMin);
        CompareTupleFilter compMax = new CompareTupleFilter(FilterOperatorEnum.LTE);
        compMax.addChild(new ColumnTupleFilter(hostCols[i]));
        compMax.addChild(new ConstantTupleFilter(max[i]));
        and.addChild(compMax);
    }
    return and;
}
 
Example #18
Source File: FilterBaseTest.java    From Kylin with Apache License 2.0 5 votes vote down vote up
protected CompareTupleFilter buildCompareCaseFilter(List<TblColRef> groups, String constValue) {
    CompareTupleFilter compareFilter = new CompareTupleFilter(FilterOperatorEnum.EQ);
    CaseTupleFilter caseFilter = buildCaseFilter(groups);
    compareFilter.addChild(caseFilter);
    ConstantTupleFilter constantFilter = new ConstantTupleFilter(constValue);
    compareFilter.addChild(constantFilter);
    return compareFilter;
}
 
Example #19
Source File: TupleFilterTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
private TupleFilter createEQFilter(String colName, String colVal) {
    CompareTupleFilter compareTupleFilter = new CompareTupleFilter(FilterOperatorEnum.EQ);
    compareTupleFilter
            .addChild(new ColumnTupleFilter(TblColRef.newInnerColumn(colName, InnerDataTypeEnum.LITERAL)));
    compareTupleFilter.addChild(new ConstantTupleFilter(colVal));
    return compareTupleFilter;
}
 
Example #20
Source File: GTUtil.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public TupleFilter onSerialize(TupleFilter filter) {
    if (filter == null)
        return null;

    // In case of NOT(unEvaluatableFilter), we should immediately replace it as TRUE,
    // Otherwise, unEvaluatableFilter will later be replace with TRUE and NOT(unEvaluatableFilter)
    // will always return FALSE.
    if (filter.getOperator() == FilterOperatorEnum.NOT && !TupleFilter.isEvaluableRecursively(filter)) {
        TupleFilter.collectColumns(filter, unevaluatableColumnCollector);
        return ConstantTupleFilter.TRUE;
    }

    // shortcut for unEvaluatable filter
    if (!filter.isEvaluable()) {
        TupleFilter.collectColumns(filter, unevaluatableColumnCollector);
        return ConstantTupleFilter.TRUE;
    }

    // map to column onto grid table
    if (colMapping != null && filter instanceof ColumnTupleFilter) {
        ColumnTupleFilter colFilter = (ColumnTupleFilter) filter;
        int gtColIdx = mapCol(colFilter.getColumn());
        return new ColumnTupleFilter(info.colRef(gtColIdx));
    }

    // encode constants
    if (useEncodeConstants && filter instanceof CompareTupleFilter) {
        return encodeConstants((CompareTupleFilter) filter);
    }

    return filter;
}
 
Example #21
Source File: TupleFilterTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void flatFilterTooFatTest() {
    TupleFilter topAndFilter = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND);
    for (int i = 0; i < 3; i++) {
        TupleFilter orFilter = new LogicalTupleFilter(FilterOperatorEnum.OR);
        String col = "col-" + i;
        for (int j = 0; j < 100; j++) {
            orFilter.addChild(createEQFilter(col, String.valueOf(j)));
        }
        topAndFilter.addChild(orFilter);
    }
    TupleFilter flatFilter = topAndFilter.flatFilter(500000);
    System.out.println(flatFilter);
}
 
Example #22
Source File: GTScannerBenchmark2.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private CompareTupleFilter eq(ColumnTupleFilter col, int... values) {
    CompareTupleFilter r = new CompareTupleFilter(FilterOperatorEnum.IN);
    r.addChild(col);

    List<ByteArray> list = Lists.newArrayList();
    for (int v : values) {
        int c = col.getColumn().getColumnDesc().getZeroBasedIndex();
        int len = info.getCodeSystem().maxCodeLength(c);
        ByteArray bytes = new ByteArray(len);
        BytesUtil.writeLong(v, bytes.array(), bytes.offset(), len);
        list.add(bytes);
    }
    r.addChild(new ConstantTupleFilter(list));
    return r;
}
 
Example #23
Source File: GTUtil.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public TupleFilter onSerialize(TupleFilter filter) {
    if (filter == null)
        return null;

    // In case of NOT(unEvaluatableFilter), we should immediately replace it as TRUE,
    // Otherwise, unEvaluatableFilter will later be replace with TRUE and NOT(unEvaluatableFilter)
    // will always return FALSE.
    if (filter.getOperator() == FilterOperatorEnum.NOT && !TupleFilter.isEvaluableRecursively(filter)) {
        TupleFilter.collectColumns(filter, unevaluatableColumnCollector);
        return ConstantTupleFilter.TRUE;
    }

    // shortcut for unEvaluatable filter
    if (!filter.isEvaluable()) {
        TupleFilter.collectColumns(filter, unevaluatableColumnCollector);
        return ConstantTupleFilter.TRUE;
    }

    // map to column onto grid table
    if (colMapping != null && filter instanceof ColumnTupleFilter) {
        ColumnTupleFilter colFilter = (ColumnTupleFilter) filter;
        int gtColIdx = mapCol(colFilter.getColumn());
        return new ColumnTupleFilter(info.colRef(gtColIdx));
    }

    // encode constants
    if (useEncodeConstants && filter instanceof CompareTupleFilter) {
        return encodeConstants((CompareTupleFilter) filter);
    }

    return filter;
}
 
Example #24
Source File: TestHelper.java    From kylin with Apache License 2.0 5 votes vote down vote up
public CompareTupleFilter buildCompareFilter(String columnName, FilterOperatorEnum op, Object value) {
    CompareTupleFilter compareFilter = new CompareTupleFilter(op);
    ColumnTupleFilter columnFilter1 = buildColumnFilter(columnName);
    compareFilter.addChild(columnFilter1);
    ConstantTupleFilter constantFilter1 = new ConstantTupleFilter(value);
    compareFilter.addChild(constantFilter1);
    return compareFilter;
}
 
Example #25
Source File: TestHelper.java    From kylin with Apache License 2.0 5 votes vote down vote up
public TupleFilter buildLowerFilter(String columnName, FilterOperatorEnum op, String value) {
    CompareTupleFilter compareFilter = new CompareTupleFilter(op);
    ColumnTupleFilter columnFilter1 = buildColumnFilter(columnName);
    BuiltInFunctionTupleFilter lowerFilter = new BuiltInFunctionTupleFilter("lower");
    lowerFilter.addChild(columnFilter1);
    compareFilter.addChild(lowerFilter);
    compareFilter.addChild(new ConstantTupleFilter(value));
    return compareFilter;
}
 
Example #26
Source File: FilterSerializeTest.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialize10() {
    List<TblColRef> groups = buildGroups();
    TupleFilter orFilter = buildOrFilter(groups);
    TupleFilter andFilter = buildAndFilter(groups);

    LogicalTupleFilter logicFilter = new LogicalTupleFilter(FilterOperatorEnum.OR);
    logicFilter.addChild(orFilter);
    logicFilter.addChild(andFilter);

    byte[] bytes = TupleFilterSerializer.serialize(logicFilter);
    TupleFilter newFilter = TupleFilterSerializer.deserialize(bytes);

    compareFilter(logicFilter, newFilter);
}
 
Example #27
Source File: TupleFilterTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
// And(Not(true), false) ==> And(false, false)
public void removeNotTest3() {
    TupleFilter andFilter = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND);
    TupleFilter notFilter = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.NOT);
    notFilter.addChild(ConstantTupleFilter.TRUE);
    andFilter.addChildren(notFilter, ConstantTupleFilter.FALSE);

    TupleFilter andFilter2 = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.AND);
    andFilter2.addChildren(ConstantTupleFilter.FALSE, ConstantTupleFilter.FALSE);
    Assert.assertEquals(andFilter2, andFilter.removeNot());
}
 
Example #28
Source File: BitMapFilterEvaluatorTest.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testLogicalAnd() {
    for (int i = 0; i < basicFilters.size(); i++) {
        for (int j = 0; j < basicFilters.size(); j++) {
            LogicalTupleFilter f = logical(FilterOperatorEnum.AND, basicFilters.get(i), basicFilters.get(j));
            ConciseSet r = basicResults.get(i).clone();
            r.retainAll(basicResults.get(j));
            assertEquals(r, eval.evaluate(f));
        }
    }
}
 
Example #29
Source File: StorageTest.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private CompareTupleFilter buildFilter1(TblColRef column) {
    CompareTupleFilter compareFilter = new CompareTupleFilter(FilterOperatorEnum.EQ);
    ColumnTupleFilter columnFilter1 = new ColumnTupleFilter(column);
    compareFilter.addChild(columnFilter1);
    ConstantTupleFilter constantFilter1 = new ConstantTupleFilter("2013-03-10");
    compareFilter.addChild(constantFilter1);
    return compareFilter;
}
 
Example #30
Source File: FilterBaseTest.java    From Kylin with Apache License 2.0 5 votes vote down vote up
protected TupleFilter buildOrFilter(List<TblColRef> columns) {
    CompareTupleFilter compareFilter1 = buildCompareFilter(columns, 0);
    CompareTupleFilter compareFilter2 = buildCompareFilter(columns, 1);
    LogicalTupleFilter logicFilter = new LogicalTupleFilter(FilterOperatorEnum.OR);
    logicFilter.addChild(compareFilter1);
    logicFilter.addChild(compareFilter2);
    return logicFilter;
}