Java Code Examples for org.apache.kylin.metadata.model.TblColRef#newInnerColumn()

The following examples show how to use org.apache.kylin.metadata.model.TblColRef#newInnerColumn() . 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: OLAPWindowRel.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
ColumnRowType buildColumnRowType() {
    OLAPRel olapChild = (OLAPRel) getInput(0);
    ColumnRowType inputColumnRowType = olapChild.getColumnRowType();

    List<TblColRef> columns = new ArrayList<>();
    // the input col always be collected by left
    columns.addAll(inputColumnRowType.getAllColumns());

    // add window aggregate calls column
    for (Group group : groups) {
        List<TupleExpression> sourceColOuter = Lists.newArrayList();
        group.keys.asSet().stream().map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColOuter::add);
        group.orderKeys.getFieldCollations().stream().map(RelFieldCollation::getFieldIndex)
                .map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColOuter::add);
        for (AggregateCall aggrCall : group.getAggregateCalls(this)) {
            TblColRef aggrCallCol = TblColRef.newInnerColumn(aggrCall.getName(),
                    TblColRef.InnerDataTypeEnum.LITERAL);
            List<TupleExpression> sourceColInner = Lists.newArrayList(sourceColOuter.iterator());
            aggrCall.getArgList().stream().filter(i -> i < inputColumnRowType.size())
                    .map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColInner::add);
            aggrCallCol.setSubTupleExps(sourceColInner);
            columns.add(aggrCallCol);
        }
    }
    return new ColumnRowType(columns);
}
 
Example 2
Source File: OLAPWindowRel.java    From kylin with Apache License 2.0 6 votes vote down vote up
ColumnRowType buildColumnRowType() {
    OLAPRel olapChild = (OLAPRel) getInput(0);
    ColumnRowType inputColumnRowType = olapChild.getColumnRowType();

    List<TblColRef> columns = new ArrayList<>();
    // the input col always be collected by left
    columns.addAll(inputColumnRowType.getAllColumns());

    // add window aggregate calls column
    for (Group group : groups) {
        List<TupleExpression> sourceColOuter = Lists.newArrayList();
        group.keys.asSet().stream().map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColOuter::add);
        group.orderKeys.getFieldCollations().stream().map(RelFieldCollation::getFieldIndex)
                .map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColOuter::add);
        for (AggregateCall aggrCall : group.getAggregateCalls(this)) {
            TblColRef aggrCallCol = TblColRef.newInnerColumn(aggrCall.getName(),
                    TblColRef.InnerDataTypeEnum.LITERAL);
            List<TupleExpression> sourceColInner = Lists.newArrayList(sourceColOuter.iterator());
            aggrCall.getArgList().stream().filter(i -> i < inputColumnRowType.size())
                    .map(inputColumnRowType::getTupleExpressionByIndex).forEach(sourceColInner::add);
            aggrCallCol.setSubTupleExps(sourceColInner);
            columns.add(aggrCallCol);
        }
    }
    return new ColumnRowType(columns);
}
 
Example 3
Source File: OLAPProjectRel.java    From kylin with Apache License 2.0 6 votes vote down vote up
private TblColRef translateRexNode(RexNode rexNode, ColumnRowType inputColumnRowType, TupleExpression tupleExpr,
        String fieldName) {
    if (tupleExpr instanceof ColumnTupleExpression) {
        return ((ColumnTupleExpression) tupleExpr).getColumn();
    } else if (tupleExpr instanceof ConstantTupleExpression) {
        Object value = ((ConstantTupleExpression) tupleExpr).getValue();
        return TblColRef.newInnerColumn(value == null ? "null" : value.toString(), InnerDataTypeEnum.LITERAL);
    } else if (tupleExpr instanceof RexCallTupleExpression && rexNode instanceof RexInputRef) {
        RexInputRef inputRef = (RexInputRef) rexNode;
        int index = inputRef.getIndex();
        if (index < inputColumnRowType.size()) {
            return inputColumnRowType.getColumnByIndex(index);
        }
    }
    return TblColRef.newInnerColumn(fieldName, InnerDataTypeEnum.LITERAL, tupleExpr.getDigest());
}
 
Example 4
Source File: TupleFilterVisitorTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private TupleFilter getMockFilter1() {
    LogicalTupleFilter ret = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR);

    TblColRef colRef1 = TblColRef.newInnerColumn("DEFAULT.TEST_KYLIN_FACT.LSTG_FORMAT_NAME",
            TblColRef.InnerDataTypeEnum.LITERAL);
    ret.addChildren(getCompareEQFilter(colRef1, "ABIN"));
    ret.addChildren(getCompareEQFilter(colRef1, "Auction"));

    TblColRef colRef2 = TblColRef.newInnerColumn("DEFAULT.TEST_KYLIN_FACT.DEAL_YEAR",
            TblColRef.InnerDataTypeEnum.LITERAL);
    ret.addChildren(getCompareEQFilter(colRef2, "2012"));
    ret.addChildren(getCompareEQFilter(colRef2, "2013"));

    return ret;
}
 
Example 5
Source File: TupleFilterVisitorTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private TupleFilter getMockFilter2() {
    LogicalTupleFilter ret = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR);

    TblColRef colRef = TblColRef.newInnerColumn("DEFAULT.TEST_KYLIN_FACT.LSTG_FORMAT_NAME",
            TblColRef.InnerDataTypeEnum.LITERAL);
    ret.addChildren(getCompareEQFilter(colRef, "ABIN"));
    ret.addChildren(getCompareEQFilter(colRef, "Auction"));

    CompareTupleFilter notInFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.NOTIN);
    notInFilter.addChildren(getCompareEQFilter(colRef, "Auction", "Others"));
    ret.addChildren(notInFilter);

    return ret;
}
 
Example 6
Source File: DictGridTableTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyAggregateAndHavingFilter() throws IOException {
    GTInfo info = table.getInfo();

    TblColRef havingCol = TblColRef.newInnerColumn("SUM_OF_BIGDECIMAL", InnerDataTypeEnum.LITERAL);
    havingCol.getColumnDesc().setId("1"); // point to the first aggregated measure
    CompareTupleFilter havingFilter = compare(havingCol, FilterOperatorEnum.GT, "20");

    GTScanRequest req = new GTScanRequestBuilder().setInfo(info).setRanges(null).setDimensions(null)
            .setAggrGroupBy(setOf(1)).setAggrMetrics(setOf(4)).setAggrMetricsFuncs(new String[] { "sum" })
            .setHavingFilterPushDown(havingFilter).createGTScanRequest();

    doScanAndVerify(table, useDeserializedGTScanRequest(req), "[null, 20, null, null, 42.0]",
            "[null, 30, null, null, 52.5]");
}
 
Example 7
Source File: TupleFilterVisitorTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
private TupleFilter getMockFilter1() {
    LogicalTupleFilter ret = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR);

    TblColRef colRef1 = TblColRef.newInnerColumn("DEFAULT.TEST_KYLIN_FACT.LSTG_FORMAT_NAME",
            TblColRef.InnerDataTypeEnum.LITERAL);
    ret.addChildren(getCompareEQFilter(colRef1, "ABIN"));
    ret.addChildren(getCompareEQFilter(colRef1, "Auction"));

    TblColRef colRef2 = TblColRef.newInnerColumn("DEFAULT.TEST_KYLIN_FACT.DEAL_YEAR",
            TblColRef.InnerDataTypeEnum.LITERAL);
    ret.addChildren(getCompareEQFilter(colRef2, "2012"));
    ret.addChildren(getCompareEQFilter(colRef2, "2013"));

    return ret;
}
 
Example 8
Source File: TupleFilterVisitorTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
private TupleFilter getMockFilter2() {
    LogicalTupleFilter ret = new LogicalTupleFilter(TupleFilter.FilterOperatorEnum.OR);

    TblColRef colRef = TblColRef.newInnerColumn("DEFAULT.TEST_KYLIN_FACT.LSTG_FORMAT_NAME",
            TblColRef.InnerDataTypeEnum.LITERAL);
    ret.addChildren(getCompareEQFilter(colRef, "ABIN"));
    ret.addChildren(getCompareEQFilter(colRef, "Auction"));

    CompareTupleFilter notInFilter = new CompareTupleFilter(TupleFilter.FilterOperatorEnum.NOTIN);
    notInFilter.addChildren(getCompareEQFilter(colRef, "Auction", "Others"));
    ret.addChildren(notInFilter);

    return ret;
}
 
Example 9
Source File: DictGridTableTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyAggregateAndHavingFilter() throws IOException {
    GTInfo info = table.getInfo();

    TblColRef havingCol = TblColRef.newInnerColumn("SUM_OF_BIGDECIMAL", InnerDataTypeEnum.LITERAL);
    havingCol.getColumnDesc().setId("1"); // point to the first aggregated measure
    CompareTupleFilter havingFilter = compare(havingCol, FilterOperatorEnum.GT, "20");

    GTScanRequest req = new GTScanRequestBuilder().setInfo(info).setRanges(null).setDimensions(null)
            .setAggrGroupBy(setOf(1)).setAggrMetrics(setOf(4)).setAggrMetricsFuncs(new String[] { "sum" })
            .setHavingFilterPushDown(havingFilter).createGTScanRequest();

    doScanAndVerify(table, useDeserializedGTScanRequest(req), "[null, 20, null, null, 42.0]",
            "[null, 30, null, null, 52.5]");
}
 
Example 10
Source File: OLAPProjectRel.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private TblColRef translateRexLiteral(RexLiteral literal) {
    if (RexLiteral.isNullLiteral(literal)) {
        return TblColRef.newInnerColumn("null", InnerDataTypeEnum.LITERAL);
    } else {
        return TblColRef.newInnerColumn(literal.getValue().toString(), InnerDataTypeEnum.LITERAL);
    }

}
 
Example 11
Source File: OLAPAggregateRel.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
ColumnRowType buildColumnRowType() {
    buildGroups();
    buildAggregations();

    ColumnRowType inputColumnRowType = ((OLAPRel) getInput()).getColumnRowType();
    List<TblColRef> columns = new ArrayList<TblColRef>(this.rowType.getFieldCount());
    columns.addAll(this.groups);

    // Add group column indicators
    if (indicator) {
        final Set<String> containedNames = Sets.newHashSet();
        for (TblColRef groupCol : groups) {
            String base = "i$" + groupCol.getName();
            String name = base;
            int i = 0;
            while (containedNames.contains(name)) {
                name = base + "_" + i++;
            }
            containedNames.add(name);
            TblColRef indicatorCol = TblColRef.newInnerColumn(name, TblColRef.InnerDataTypeEnum.LITERAL);
            columns.add(indicatorCol);
        }
    }

    for (int i = 0; i < this.aggregations.size(); i++) {
        FunctionDesc aggFunc = this.aggregations.get(i);
        String aggOutName;
        if (aggFunc != null) {
            aggOutName = aggFunc.getRewriteFieldName();
        } else {
            AggregateCall aggCall = this.rewriteAggCalls.get(i);
            int index = aggCall.getArgList().get(0);
            aggOutName = getSqlFuncName(aggCall) + "_"
                    + inputColumnRowType.getColumnByIndex(index).getIdentity().replace('.', '_') + "_";
        }
        TblColRef aggOutCol = TblColRef.newInnerColumn(aggOutName, TblColRef.InnerDataTypeEnum.LITERAL);
        aggOutCol.getColumnDesc().setId("" + (i + 1)); // mark the index of aggregation
        columns.add(aggOutCol);
    }
    return new ColumnRowType(columns);
}
 
Example 12
Source File: OLAPAggregateRel.java    From kylin with Apache License 2.0 4 votes vote down vote up
ColumnRowType buildColumnRowType() {
    buildGroups();
    buildAggregations();

    ColumnRowType inputColumnRowType = ((OLAPRel) getInput()).getColumnRowType();
    List<TblColRef> columns = new ArrayList<TblColRef>(this.rowType.getFieldCount());
    columns.addAll(this.groups);

    // Add group column indicators
    if (indicator) {
        final Set<String> containedNames = Sets.newHashSet();
        for (TblColRef groupCol : groups) {
            String base = "i$" + groupCol.getName();
            String name = base;
            int i = 0;
            while (containedNames.contains(name)) {
                name = base + "_" + i++;
            }
            containedNames.add(name);
            TblColRef indicatorCol = TblColRef.newInnerColumn(name, TblColRef.InnerDataTypeEnum.LITERAL);
            columns.add(indicatorCol);
        }
    }

    for (int i = 0; i < this.aggregations.size(); i++) {
        FunctionDesc aggFunc = this.aggregations.get(i);
        String aggOutName;
        if (aggFunc != null) {
            aggOutName = aggFunc.getRewriteFieldName();
        } else {
            AggregateCall aggCall = this.rewriteAggCalls.get(i);
            int index = aggCall.getArgList().get(0);
            aggOutName = getSqlFuncName(aggCall) + "_"
                    + inputColumnRowType.getColumnByIndex(index).getIdentity().replace('.', '_') + "_";
        }
        TblColRef aggOutCol = TblColRef.newInnerColumn(aggOutName, TblColRef.InnerDataTypeEnum.LITERAL);
        aggOutCol.getColumnDesc().setId("" + (i + 1)); // mark the index of aggregation
        columns.add(aggOutCol);
    }
    return new ColumnRowType(columns);
}