Java Code Examples for org.apache.kylin.metadata.model.FunctionDesc#newInstance()

The following examples show how to use org.apache.kylin.metadata.model.FunctionDesc#newInstance() . 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: RawMeasureType.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public void adjustSqlDigest(List<MeasureDesc> measureDescs, SQLDigest sqlDigest) {

    if (sqlDigest.isRawQuery) {
        for (MeasureDesc measureDesc : measureDescs) {
            if (!sqlDigest.involvedMeasure.contains(measureDesc)) {
                continue;
            }
            TblColRef col = this.getRawColumn(measureDesc.getFunction());
            ParameterDesc colParameter = ParameterDesc.newInstance(col);
            FunctionDesc rawFunc = FunctionDesc.newInstance("RAW", colParameter, null);

            if (sqlDigest.allColumns.contains(col)) {
                if (measureDesc.getFunction().equals(rawFunc)) {
                    FunctionDesc sumFunc = FunctionDesc.newInstance("SUM", colParameter, null);
                    sqlDigest.aggregations.remove(sumFunc);
                    sqlDigest.aggregations.add(rawFunc);
                    logger.info("Add RAW measure on column " + col);
                }
                if (!sqlDigest.metricColumns.contains(col)) {
                    sqlDigest.metricColumns.add(col);
                }
            }
        }
    }
}
 
Example 2
Source File: StorageMockUtils.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public List<FunctionDesc> buildAggregations() {
    List<FunctionDesc> functions = new ArrayList<FunctionDesc>();

    TblColRef priceCol = model.findColumn("DEFAULT.TEST_KYLIN_FACT.PRICE");
    TblColRef sellerCol = model.findColumn("DEFAULT.TEST_KYLIN_FACT.SELLER_ID");

    FunctionDesc f1 = FunctionDesc.newInstance("SUM", //
            ParameterDesc.newInstance(priceCol), "decimal(19,4)");
    functions.add(f1);

    FunctionDesc f2 = FunctionDesc.newInstance("COUNT_DISTINCT", //
            ParameterDesc.newInstance(sellerCol), "hllc(10)");
    functions.add(f2);

    return functions;
}
 
Example 3
Source File: RawMeasureType.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Override
public void adjustSqlDigest(List<MeasureDesc> measureDescs, SQLDigest sqlDigest) {

    if (sqlDigest.isRawQuery) {
        for (MeasureDesc measureDesc : measureDescs) {
            if (!sqlDigest.involvedMeasure.contains(measureDesc)) {
                continue;
            }
            TblColRef col = this.getRawColumn(measureDesc.getFunction());
            ParameterDesc colParameter = ParameterDesc.newInstance(col);
            FunctionDesc rawFunc = FunctionDesc.newInstance("RAW", colParameter, null);

            if (sqlDigest.allColumns.contains(col)) {
                if (measureDesc.getFunction().equals(rawFunc)) {
                    FunctionDesc sumFunc = FunctionDesc.newInstance("SUM", colParameter, null);
                    sqlDigest.aggregations.remove(sumFunc);
                    sqlDigest.aggregations.add(rawFunc);
                    logger.info("Add RAW measure on column " + col);
                }
                if (!sqlDigest.metricColumns.contains(col)) {
                    sqlDigest.metricColumns.add(col);
                }
            }
        }
    }
}
 
Example 4
Source File: StorageMockUtils.java    From kylin with Apache License 2.0 6 votes vote down vote up
public List<FunctionDesc> buildAggregations() {
    List<FunctionDesc> functions = new ArrayList<FunctionDesc>();

    TblColRef priceCol = model.findColumn("DEFAULT.TEST_KYLIN_FACT.PRICE");
    TblColRef sellerCol = model.findColumn("DEFAULT.TEST_KYLIN_FACT.SELLER_ID");

    FunctionDesc f1 = FunctionDesc.newInstance("SUM", //
            ParameterDesc.newInstance(priceCol), "decimal(19,4)");
    functions.add(f1);

    FunctionDesc f2 = FunctionDesc.newInstance("COUNT_DISTINCT", //
            ParameterDesc.newInstance(sellerCol), "hllc(10)");
    functions.add(f2);

    return functions;
}
 
Example 5
Source File: StorageMockUtils.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public List<FunctionDesc> buildAggregations1() {
    List<FunctionDesc> functions = new ArrayList<FunctionDesc>();

    TblColRef priceCol = model.findColumn("DEFAULT.TEST_KYLIN_FACTPRICE");

    FunctionDesc f1 = FunctionDesc.newInstance("SUM", //
            ParameterDesc.newInstance(priceCol), "decimal(19,4)");
    functions.add(f1);

    return functions;
}
 
Example 6
Source File: StorageMockUtils.java    From kylin with Apache License 2.0 5 votes vote down vote up
public List<FunctionDesc> buildAggregations1() {
    List<FunctionDesc> functions = new ArrayList<FunctionDesc>();

    TblColRef priceCol = model.findColumn("DEFAULT.TEST_KYLIN_FACTPRICE");

    FunctionDesc f1 = FunctionDesc.newInstance("SUM", //
            ParameterDesc.newInstance(priceCol), "decimal(19,4)");
    functions.add(f1);

    return functions;
}
 
Example 7
Source File: TopNMeasureType.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public IAdvMeasureFiller getAdvancedTupleFiller(FunctionDesc function, TupleInfo tupleInfo,
        Map<TblColRef, Dictionary<String>> dictionaryMap) {
    final List<TblColRef> literalCols = getTopNLiteralColumn(function);
    final TblColRef numericCol = getTopNNumericColumn(function);
    final int[] literalTupleIdx = new int[literalCols.size()];
    final DimensionEncoding[] dimensionEncodings = getDimensionEncodings(function, literalCols, dictionaryMap);
    for (int i = 0; i < literalCols.size(); i++) {
        TblColRef colRef = literalCols.get(i);
        literalTupleIdx[i] = tupleInfo.hasColumn(colRef) ? tupleInfo.getColumnIndex(colRef) : -1;
    }

    // for TopN, the aggr must be SUM
    final int numericTupleIdx;
    if (numericCol != null) {
        FunctionDesc sumFunc = FunctionDesc.newInstance(FunctionDesc.FUNC_SUM,
                ParameterDesc.newInstance(numericCol), numericCol.getType().toString());
        String sumFieldName = sumFunc.getRewriteFieldName();
        numericTupleIdx = tupleInfo.hasField(sumFieldName) ? tupleInfo.getFieldIndex(sumFieldName) : -1;
    } else {
        FunctionDesc countFunction = FunctionDesc.newInstance(FunctionDesc.FUNC_COUNT,
                ParameterDesc.newInstance("1"), "bigint");
        numericTupleIdx = tupleInfo.getFieldIndex(countFunction.getRewriteFieldName());
    }
    return new IAdvMeasureFiller() {
        private TopNCounter<ByteArray> topNCounter;
        private Iterator<Counter<ByteArray>> topNCounterIterator;
        private int expectRow = 0;

        @SuppressWarnings("unchecked")
        @Override
        public void reload(Object measureValue) {
            this.topNCounter = (TopNCounter<ByteArray>) measureValue;
            this.topNCounterIterator = topNCounter.iterator();
            this.expectRow = 0;
        }

        @Override
        public int getNumOfRows() {
            return topNCounter.size();
        }

        @Override
        public void fillTuple(Tuple tuple, int row) {
            if (expectRow++ != row)
                throw new IllegalStateException();

            Counter<ByteArray> counter = topNCounterIterator.next();
            int offset = counter.getItem().offset();
            for (int i = 0; i < dimensionEncodings.length; i++) {
                String colValue = dimensionEncodings[i].decode(counter.getItem().array(), offset,
                        dimensionEncodings[i].getLengthOfEncoding());
                tuple.setDimensionValue(literalTupleIdx[i], colValue);
                offset += dimensionEncodings[i].getLengthOfEncoding();
            }
            tuple.setMeasureValue(numericTupleIdx, counter.getCount());
        }
    };
}
 
Example 8
Source File: MeasureCodecTest.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
private MeasureDesc measure(String returnType) {
    MeasureDesc desc = new MeasureDesc();
    FunctionDesc func = FunctionDesc.newInstance(null, null, returnType);
    desc.setFunction(func);
    return desc;
}
 
Example 9
Source File: TopNMeasureType.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Override
public IAdvMeasureFiller getAdvancedTupleFiller(FunctionDesc function, TupleInfo tupleInfo,
        Map<TblColRef, Dictionary<String>> dictionaryMap) {
    final List<TblColRef> literalCols = getTopNLiteralColumn(function);
    final TblColRef numericCol = getTopNNumericColumn(function);
    final int[] literalTupleIdx = new int[literalCols.size()];
    final DimensionEncoding[] dimensionEncodings = getDimensionEncodings(function, literalCols, dictionaryMap);
    for (int i = 0; i < literalCols.size(); i++) {
        TblColRef colRef = literalCols.get(i);
        literalTupleIdx[i] = tupleInfo.hasColumn(colRef) ? tupleInfo.getColumnIndex(colRef) : -1;
    }

    // for TopN, the aggr must be SUM
    final int numericTupleIdx;
    if (numericCol != null) {
        FunctionDesc sumFunc = FunctionDesc.newInstance(FunctionDesc.FUNC_SUM,
                ParameterDesc.newInstance(numericCol), numericCol.getType().toString());
        String sumFieldName = sumFunc.getRewriteFieldName();
        numericTupleIdx = tupleInfo.hasField(sumFieldName) ? tupleInfo.getFieldIndex(sumFieldName) : -1;
    } else {
        FunctionDesc countFunction = FunctionDesc.newInstance(FunctionDesc.FUNC_COUNT,
                ParameterDesc.newInstance("1"), "bigint");
        numericTupleIdx = tupleInfo.getFieldIndex(countFunction.getRewriteFieldName());
    }
    return new IAdvMeasureFiller() {
        private TopNCounter<ByteArray> topNCounter;
        private Iterator<Counter<ByteArray>> topNCounterIterator;
        private int expectRow = 0;

        @SuppressWarnings("unchecked")
        @Override
        public void reload(Object measureValue) {
            this.topNCounter = (TopNCounter<ByteArray>) measureValue;
            this.topNCounterIterator = topNCounter.iterator();
            this.expectRow = 0;
        }

        @Override
        public int getNumOfRows() {
            return topNCounter.size();
        }

        @Override
        public void fillTuple(Tuple tuple, int row) {
            if (expectRow++ != row)
                throw new IllegalStateException();

            Counter<ByteArray> counter = topNCounterIterator.next();
            int offset = counter.getItem().offset();
            for (int i = 0; i < dimensionEncodings.length; i++) {
                String colValue = dimensionEncodings[i].decode(counter.getItem().array(), offset,
                        dimensionEncodings[i].getLengthOfEncoding());
                tuple.setDimensionValue(literalTupleIdx[i], colValue);
                offset += dimensionEncodings[i].getLengthOfEncoding();
            }
            tuple.setMeasureValue(numericTupleIdx, counter.getCount());
        }
    };
}
 
Example 10
Source File: MeasureCodecTest.java    From kylin with Apache License 2.0 4 votes vote down vote up
private MeasureDesc measure(String returnType) {
    MeasureDesc desc = new MeasureDesc();
    FunctionDesc func = FunctionDesc.newInstance(null, null, returnType);
    desc.setFunction(func);
    return desc;
}