org.apache.kylin.metadata.model.ParameterDesc Java Examples

The following examples show how to use org.apache.kylin.metadata.model.ParameterDesc. 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: CubeDescCreator.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public static MeasureDesc getMeasureSum(String column, String dataType) {
    ParameterDesc parameterDesc = new ParameterDesc();
    parameterDesc.setValue(column);
    parameterDesc.setType(FunctionDesc.PARAMETER_TYPE_COLUMN);

    FunctionDesc function = new FunctionDesc();
    function.setExpression(FunctionDesc.FUNC_SUM);
    function.setParameter(parameterDesc);
    function.setReturnType(dataType.equals(HiveTableCreator.HiveTypeEnum.HDOUBLE.toString())
            ? HiveTableCreator.HiveTypeEnum.HDECIMAL.toString()
            : dataType);

    MeasureDesc result = new MeasureDesc();
    result.setName(column + "_SUM");
    result.setFunction(function);
    return result;
}
 
Example #2
Source File: StorageTest.java    From Kylin with Apache License 2.0 6 votes vote down vote up
private List<FunctionDesc> buildAggregations() {
    List<FunctionDesc> functions = new ArrayList<FunctionDesc>();

    FunctionDesc f1 = new FunctionDesc();
    f1.setExpression("SUM");
    ParameterDesc p1 = new ParameterDesc();
    p1.setType("column");
    p1.setValue("PRICE");
    f1.setParameter(p1);
    functions.add(f1);

    FunctionDesc f2 = new FunctionDesc();
    f2.setExpression("COUNT_DISTINCT");
    ParameterDesc p2 = new ParameterDesc();
    p2.setType("column");
    p2.setValue("SELLER_ID");
    f2.setParameter(p2);
    functions.add(f2);

    return functions;
}
 
Example #3
Source File: NewBaseCuboidMapper.java    From Kylin with Apache License 2.0 6 votes vote down vote up
private byte[] getValueBytes(SplittedBytes[] splitBuffers, int measureIdx) {
    MeasureDesc desc = cubeDesc.getMeasures().get(measureIdx);
    ParameterDesc paramDesc = desc.getFunction().getParameter();
    int[] flatTableIdx = this.measureColumnIndice[measureIdx];

    byte[] result = null;

    // constant
    if (flatTableIdx == null) {
        result = Bytes.toBytes(paramDesc.getValue());
    }
    // column values
    else {
        for (int i = 0; i < flatTableIdx.length; i++) {
            SplittedBytes split = splitBuffers[flatTableIdx[i]];
            result = Arrays.copyOf(split.value, split.length);
        }
    }

    if (desc.getFunction().isCount()) {
        result = Bytes.toBytes("1");
    }

    return result;
}
 
Example #4
Source File: TestHelper.java    From kylin with Apache License 2.0 6 votes vote down vote up
public Set<FunctionDesc> simulateMetrics() {
        List<FunctionDesc> functions = Lists.newArrayList();
        TblColRef gmvCol = getColumnRef("STREAMING_V2_TABLE.GMV");

//        FunctionDesc f1 = new FunctionDesc();
//        f1.setExpression("SUM");
//        ParameterDesc p1 = ParameterDesc.newInstance(gmvCol);
//        f1.setParameter(p1);
//        f1.setReturnType("decimal(19,6)");
//        functions.add(f1);

        FunctionDesc f2 = new FunctionDesc();
        f2.setExpression(PercentileMeasureType.FUNC_PERCENTILE_APPROX);
        ParameterDesc p2 = ParameterDesc.newInstance(gmvCol);
        f2.setParameter(p2);
        f2.setReturnType("percentile(100)");
        functions.add(f2);

        return Sets.newHashSet(functions);
    }
 
Example #5
Source File: SegmentMemoryStore.java    From kylin with Apache License 2.0 6 votes vote down vote up
private Object buildValueOf(int idxOfMeasure, List<String> row) {
    MeasureDesc measure = parsedStreamingCubeInfo.measureDescs[idxOfMeasure];
    FunctionDesc function = measure.getFunction();
    int[] colIdxOnFlatTable = parsedStreamingCubeInfo.intermediateTableDesc.getMeasureColumnIndexes()[idxOfMeasure];

    int paramCount = function.getParameterCount();
    String[] inputToMeasure = new String[paramCount];

    // pick up parameter values
    ParameterDesc param = function.getParameter();
    int paramColIdx = 0; // index among parameters of column type
    for (int i = 0; i < paramCount; i++, param = param.getNextParameter()) {
        String value;
        if (function.isCount()) {
            value = "1";
        } else if (param.isColumnType()) {
            value = row.get(colIdxOnFlatTable[paramColIdx++]);
        } else {
            value = param.getValue();
        }
        inputToMeasure[i] = value;
    }
    return parsedStreamingCubeInfo.measureIngesters[idxOfMeasure].valueOf(inputToMeasure, measure, dictionaryMap);
}
 
Example #6
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 #7
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 #8
Source File: CubeDescCreator.java    From kylin with Apache License 2.0 6 votes vote down vote up
public static MeasureDesc getMeasureSum(String column, String dataType) {
    ParameterDesc parameterDesc = new ParameterDesc();
    parameterDesc.setValue(column);
    parameterDesc.setType(FunctionDesc.PARAMETER_TYPE_COLUMN);

    FunctionDesc function = new FunctionDesc();
    function.setExpression(FunctionDesc.FUNC_SUM);
    function.setParameter(parameterDesc);
    function.setReturnType(dataType.equals(HiveTableCreator.HiveTypeEnum.HDOUBLE.toString())
            ? HiveTableCreator.HiveTypeEnum.HDECIMAL.toString()
            : dataType);

    MeasureDesc result = new MeasureDesc();
    result.setName(column + "_SUM");
    result.setFunction(function);
    return result;
}
 
Example #9
Source File: TestHelper.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public Set<FunctionDesc> simulateMetrics() {
        List<FunctionDesc> functions = Lists.newArrayList();
        TblColRef gmvCol = getColumnRef("STREAMING_V2_TABLE.GMV");

//        FunctionDesc f1 = new FunctionDesc();
//        f1.setExpression("SUM");
//        ParameterDesc p1 = ParameterDesc.newInstance(gmvCol);
//        f1.setParameter(p1);
//        f1.setReturnType("decimal(19,6)");
//        functions.add(f1);

        FunctionDesc f2 = new FunctionDesc();
        f2.setExpression(PercentileMeasureType.FUNC_PERCENTILE_APPROX);
        ParameterDesc p2 = ParameterDesc.newInstance(gmvCol);
        f2.setParameter(p2);
        f2.setReturnType("percentile(100)");
        functions.add(f2);

        return Sets.newHashSet(functions);
    }
 
Example #10
Source File: SegmentMemoryStore.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private Object buildValueOf(int idxOfMeasure, List<String> row) {
    MeasureDesc measure = parsedStreamingCubeInfo.measureDescs[idxOfMeasure];
    FunctionDesc function = measure.getFunction();
    int[] colIdxOnFlatTable = parsedStreamingCubeInfo.intermediateTableDesc.getMeasureColumnIndexes()[idxOfMeasure];

    int paramCount = function.getParameterCount();
    String[] inputToMeasure = new String[paramCount];

    // pick up parameter values
    ParameterDesc param = function.getParameter();
    int paramColIdx = 0; // index among parameters of column type
    for (int i = 0; i < paramCount; i++, param = param.getNextParameter()) {
        String value;
        if (function.isCount()) {
            value = "1";
        } else if (param.isColumnType()) {
            value = row.get(colIdxOnFlatTable[paramColIdx++]);
        } else {
            value = param.getValue();
        }
        inputToMeasure[i] = value;
    }
    return parsedStreamingCubeInfo.measureIngesters[idxOfMeasure].valueOf(inputToMeasure, measure, dictionaryMap);
}
 
Example #11
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 #12
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 #13
Source File: TestHelper.java    From kylin with Apache License 2.0 5 votes vote down vote up
public FunctionDesc simulateMetric(String columnName, String funcName, String returnType) {
    TblColRef gmvCol = getColumnRef(columnName);

    FunctionDesc f1 = new FunctionDesc();
    f1.setExpression(funcName);
    ParameterDesc p1 = ParameterDesc.newInstance(gmvCol);
    f1.setParameter(p1);
    f1.setReturnType(returnType);
    return f1;
}
 
Example #14
Source File: CubeCapabilityChecker.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private static void tryDimensionAsMeasures(Collection<FunctionDesc> unmatchedAggregations, CapabilityResult result,
        Set<TblColRef> dimCols) {

    Iterator<FunctionDesc> it = unmatchedAggregations.iterator();
    while (it.hasNext()) {
        FunctionDesc functionDesc = it.next();

        // let calcite handle count
        if (functionDesc.isCount()) {
            logger.warn("No count measure found for column {}, will use count(1) to replace it, please note that it will count all value(include null value)", functionDesc.getParameter() == null ? "" : functionDesc.getParameter().getColRef().getName());
            it.remove();
            continue;
        }

        // calcite can do aggregation from columns on-the-fly
        ParameterDesc parameterDesc = functionDesc.getParameter();
        if (parameterDesc == null) {
            continue;
        }
        List<TblColRef> neededCols = parameterDesc.getColRefs();
        if (neededCols.size() > 0 && dimCols.containsAll(neededCols)
                && FunctionDesc.BUILT_IN_AGGREGATIONS.contains(functionDesc.getExpression())) {
            result.influences.add(new CapabilityResult.DimensionAsMeasure(functionDesc));
            it.remove();
            continue;
        }
    }
}
 
Example #15
Source File: CubeDescCreator.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static MeasureDesc getMeasurePercentile(String column) {
    ParameterDesc parameterDesc = new ParameterDesc();
    parameterDesc.setValue(column);
    parameterDesc.setType(FunctionDesc.PARAMETER_TYPE_COLUMN);

    FunctionDesc function = new FunctionDesc();
    function.setExpression(PercentileMeasureType.FUNC_PERCENTILE);
    function.setParameter(parameterDesc);
    function.setReturnType("percentile(100)");

    MeasureDesc result = new MeasureDesc();
    result.setName(column + "_PERCENTILE");
    result.setFunction(function);
    return result;
}
 
Example #16
Source File: CubeCapabilityChecker.java    From kylin with Apache License 2.0 5 votes vote down vote up
private static void tryDimensionAsMeasures(Collection<FunctionDesc> unmatchedAggregations, CapabilityResult result,
        Set<TblColRef> dimCols) {

    Iterator<FunctionDesc> it = unmatchedAggregations.iterator();
    while (it.hasNext()) {
        FunctionDesc functionDesc = it.next();

        // let calcite handle count
        if (functionDesc.isCount()) {
            logger.warn("No count measure found for column {}, will use count(1) to replace it, please note that it will count all value(include null value)", functionDesc.getParameter() == null ? "" : functionDesc.getParameter().getColRef().getName());
            it.remove();
            continue;
        }

        // calcite can do aggregation from columns on-the-fly
        ParameterDesc parameterDesc = functionDesc.getParameter();
        if (parameterDesc == null) {
            continue;
        }

        List<TblColRef> neededCols = functionDesc instanceof ExpressionDynamicFunctionDesc
                ? Lists.newArrayList(ExpressionColCollector
                        .collectColumns(((ExpressionDynamicFunctionDesc) functionDesc).getTupleExpression()))
                : parameterDesc.getColRefs();
        if (neededCols.size() > 0 && dimCols.containsAll(neededCols)
                && FunctionDesc.BUILT_IN_AGGREGATIONS.contains(functionDesc.getExpression())) {
            result.influences.add(new CapabilityResult.DimensionAsMeasure(functionDesc));
            it.remove();
            continue;
        }
    }
}
 
Example #17
Source File: KeyValueBuilder.java    From kylin with Apache License 2.0 5 votes vote down vote up
public String[] buildValueOf(int idxOfMeasure, String[] row) {
    MeasureDesc measure = cubeDesc.getMeasures().get(idxOfMeasure);
    FunctionDesc function = measure.getFunction();
    int[] colIdxOnFlatTable = flatDesc.getMeasureColumnIndexes()[idxOfMeasure];

    int paramCount = function.getParameterCount();
    List<String> inputToMeasure = Lists.newArrayListWithExpectedSize(paramCount);

    // pick up parameter values
    ParameterDesc param = function.getParameter();
    int colParamIdx = 0; // index among parameters of column type
    for (int i = 0; i < paramCount; i++, param = param.getNextParameter()) {
        String value;
        if (param.isColumnType()) {
            value = getCell(colIdxOnFlatTable[colParamIdx++], row);
            if (function.isCount() && value == null) {
                value = ZERO;
            } else if (function.isCount()) {
                value = ONE;
            }
        } else {
            value = param.getValue();
            if (function.isCount()) {
                value = ONE;
            }
        }
        inputToMeasure.add(value);
    }
    if (BitmapMapMeasureType.DATATYPE_BITMAP_MAP.equalsIgnoreCase(function.getReturnType())) {
        inputToMeasure.add(segmentStartTime);
    }

    return inputToMeasure.toArray(new String[inputToMeasure.size()]);
}
 
Example #18
Source File: CubeDescCreator.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static MeasureDesc getMeasureHLL(String column) {
    ParameterDesc parameterDesc = new ParameterDesc();
    parameterDesc.setValue(column);
    parameterDesc.setType(FunctionDesc.PARAMETER_TYPE_COLUMN);

    FunctionDesc function = new FunctionDesc();
    function.setExpression(FunctionDesc.FUNC_COUNT_DISTINCT);
    function.setParameter(parameterDesc);
    function.setReturnType("hllc12");

    MeasureDesc result = new MeasureDesc();
    result.setName(column + "_HLL");
    result.setFunction(function);
    return result;
}
 
Example #19
Source File: SegmentMemoryStoreTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
private Set<FunctionDesc> simulateMetrics() {
    List<FunctionDesc> functions = Lists.newArrayList();

    TblColRef gmvCol = cubeDesc.getModel().findColumn("STREAMING_V2_TABLE.GMV");
    FunctionDesc f1 = new FunctionDesc();
    f1.setExpression("SUM");
    ParameterDesc p1 = ParameterDesc.newInstance(gmvCol);
    f1.setParameter(p1);
    f1.setReturnType("decimal(19,6)");
    functions.add(f1);

    return Sets.newHashSet(functions);
}
 
Example #20
Source File: CubeDescCreator.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static MeasureDesc getMeasureMin(String column, String dataType) {
    ParameterDesc parameterDesc = new ParameterDesc();
    parameterDesc.setValue(column);
    parameterDesc.setType(FunctionDesc.PARAMETER_TYPE_COLUMN);

    FunctionDesc function = new FunctionDesc();
    function.setExpression(FunctionDesc.FUNC_MIN);
    function.setParameter(parameterDesc);
    function.setReturnType(dataType);

    MeasureDesc result = new MeasureDesc();
    result.setName(column + "_MIN");
    result.setFunction(function);
    return result;
}
 
Example #21
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 #22
Source File: TestHelper.java    From kylin with Apache License 2.0 5 votes vote down vote up
public FunctionDesc simulateCountMetric() {
    FunctionDesc f1 = new FunctionDesc();
    f1.setExpression("COUNT");
    ParameterDesc p1 = ParameterDesc.newInstance("1");
    f1.setParameter(p1);
    f1.setReturnType("bigint");
    return f1;
}
 
Example #23
Source File: CubeDescCreator.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static MeasureDesc getMeasureMax(String column, String dataType) {
    ParameterDesc parameterDesc = new ParameterDesc();
    parameterDesc.setValue(column);
    parameterDesc.setType(FunctionDesc.PARAMETER_TYPE_COLUMN);

    FunctionDesc function = new FunctionDesc();
    function.setExpression(FunctionDesc.FUNC_MAX);
    function.setParameter(parameterDesc);
    function.setReturnType(dataType);

    MeasureDesc result = new MeasureDesc();
    result.setName(column + "_MAX");
    result.setFunction(function);
    return result;
}
 
Example #24
Source File: BaseCuboidMapper.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private byte[] getValueBytes(SplittedBytes[] splitBuffers, int measureIdx) {
    MeasureDesc desc = cubeDesc.getMeasures().get(measureIdx);
    FunctionDesc func = desc.getFunction();
    ParameterDesc paramDesc = func.getParameter();
    int[] flatTableIdx = intermediateTableDesc.getMeasureColumnIndexes()[measureIdx];

    byte[] result = null;

    // constant
    if (flatTableIdx == null) {
        result = Bytes.toBytes(paramDesc.getValue());
    }
    // column values
    else {
        // for multiple columns, their values are joined
        for (int i = 0; i < flatTableIdx.length; i++) {
            SplittedBytes split = splitBuffers[flatTableIdx[i]];
            if (result == null) {
                result = Arrays.copyOf(split.value, split.length);
            } else {
                byte[] newResult = new byte[result.length + split.length];
                System.arraycopy(result, 0, newResult, 0, result.length);
                System.arraycopy(split.value, 0, newResult, result.length, split.length);
                result = newResult;
            }
        }
    }

    if (func.isCount() || func.isHolisticCountDistinct()) {
        // note for holistic count distinct, this value will be ignored
        result = ONE;
    }

    if (isNull(result)) {
        result = null;
    }

    return result;
}
 
Example #25
Source File: CubeDesc.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private void initMeasureColumns(Map<String, TableDesc> tables) {
    if (measures == null || measures.isEmpty()) {
        return;
    }

    TableDesc factTable = tables.get(getFactTable());
    for (MeasureDesc m : measures) {
        m.setName(m.getName().toUpperCase());

        if (m.getDependentMeasureRef() != null) {
            m.setDependentMeasureRef(m.getDependentMeasureRef().toUpperCase());
        }

        FunctionDesc f = m.getFunction();
        f.setExpression(f.getExpression().toUpperCase());
        f.setReturnDataType(DataType.getInstance(f.getReturnType()));

        ParameterDesc p = f.getParameter();
        p.normalizeColumnValue();

        if (p.isColumnType()) {
            ArrayList<TblColRef> colRefs = Lists.newArrayList();
            for (String cName : p.getValue().split("\\s*,\\s*")) {
                ColumnDesc sourceColumn = factTable.findColumnByName(cName);
                TblColRef colRef = new TblColRef(sourceColumn);
                colRefs.add(colRef);
                allColumns.add(colRef);
            }
            if (colRefs.isEmpty() == false)
                p.setColRefs(colRefs);
        }
    }
}
 
Example #26
Source File: CubeDesc.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private void initMeasureColumns(Map<String, TableDesc> tables) {
    if (measures == null || measures.isEmpty()) {
        return;
    }

    TableDesc factTable = tables.get(getFactTable());
    for (MeasureDesc m : measures) {
        m.setName(m.getName().toUpperCase());

        if (m.getDependentMeasureRef() != null) {
            m.setDependentMeasureRef(m.getDependentMeasureRef().toUpperCase());
        }
        
        FunctionDesc f = m.getFunction();
        f.setExpression(f.getExpression().toUpperCase());
        f.setReturnDataType(DataType.getInstance(f.getReturnType()));

        ParameterDesc p = f.getParameter();
        p.normalizeColumnValue();

        if (p.isColumnType()) {
            ArrayList<TblColRef> colRefs = Lists.newArrayList();
            for (String cName : p.getValue().split("\\s*,\\s*")) {
                ColumnDesc sourceColumn = factTable.findColumnByName(cName);
                TblColRef colRef = new TblColRef(sourceColumn);
                colRefs.add(colRef);
                allColumns.add(colRef);
            }
            if (colRefs.isEmpty() == false)
                p.setColRefs(colRefs);
        }
        
        // verify holistic count distinct as a dependent measure
        if (m.isHolisticCountDistinct() && StringUtils.isBlank(m.getDependentMeasureRef())) {
            throw new IllegalStateException(m + " is a holistic count distinct but it has no DependentMeasureRef defined!");
        }
    }
}
 
Example #27
Source File: CubeDescCreator.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static MeasureDesc getMeasureCount() {
    ParameterDesc parameterDesc = new ParameterDesc();
    parameterDesc.setValue("1");
    parameterDesc.setType(FunctionDesc.PARAMETER_TYPE_CONSTANT);

    FunctionDesc function = new FunctionDesc();
    function.setExpression(FunctionDesc.FUNC_COUNT);
    function.setParameter(parameterDesc);
    function.setReturnType(HiveTableCreator.HiveTypeEnum.HBIGINT.toString());

    MeasureDesc result = new MeasureDesc();
    result.setName("_COUNT_");
    result.setFunction(function);
    return result;
}
 
Example #28
Source File: CubeDescCreator.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static MeasureDesc getMeasurePercentile(String column) {
    ParameterDesc parameterDesc = new ParameterDesc();
    parameterDesc.setValue(column);
    parameterDesc.setType(FunctionDesc.PARAMETER_TYPE_COLUMN);

    FunctionDesc function = new FunctionDesc();
    function.setExpression(PercentileMeasureType.FUNC_PERCENTILE);
    function.setParameter(parameterDesc);
    function.setReturnType("percentile(100)");

    MeasureDesc result = new MeasureDesc();
    result.setName(column + "_PERCENTILE");
    result.setFunction(function);
    return result;
}
 
Example #29
Source File: KeyValueBuilder.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public String[] buildValueOf(int idxOfMeasure, String[] row) {
    MeasureDesc measure = cubeDesc.getMeasures().get(idxOfMeasure);
    FunctionDesc function = measure.getFunction();
    int[] colIdxOnFlatTable = flatDesc.getMeasureColumnIndexes()[idxOfMeasure];

    int paramCount = function.getParameterCount();
    List<String> inputToMeasure = Lists.newArrayListWithExpectedSize(paramCount);

    // pick up parameter values
    ParameterDesc param = function.getParameter();
    int colParamIdx = 0; // index among parameters of column type
    for (int i = 0; i < paramCount; i++, param = param.getNextParameter()) {
        String value;
        if (param.isColumnType()) {
            value = getCell(colIdxOnFlatTable[colParamIdx++], row);
            if (function.isCount() && value == null) {
                value = ZERO;
            } else if (function.isCount()) {
                value = ONE;
            }
        } else {
            value = param.getValue();
            if (function.isCount()) {
                value = ONE;
            }
        }
        inputToMeasure.add(value);
    }

    return inputToMeasure.toArray(new String[inputToMeasure.size()]);
}
 
Example #30
Source File: CubeDescCreator.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static MeasureDesc getMeasureHLL(String column) {
    ParameterDesc parameterDesc = new ParameterDesc();
    parameterDesc.setValue(column);
    parameterDesc.setType(FunctionDesc.PARAMETER_TYPE_COLUMN);

    FunctionDesc function = new FunctionDesc();
    function.setExpression(FunctionDesc.FUNC_COUNT_DISTINCT);
    function.setParameter(parameterDesc);
    function.setReturnType("hllc12");

    MeasureDesc result = new MeasureDesc();
    result.setName(column + "_HLL");
    result.setFunction(function);
    return result;
}