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

The following examples show how to use org.apache.kylin.metadata.model.FunctionDesc#getExpression() . 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: CuboidToGridTableMapping.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public String[] makeAggrFuncs(Collection<FunctionDesc> metrics) {

        //metrics are represented in ImmutableBitSet, which loses order information
        //sort the aggrFuns to align with metrics natural order 
        List<FunctionDesc> metricList = Lists.newArrayList(metrics);
        Collections.sort(metricList, new Comparator<FunctionDesc>() {
            @Override
            public int compare(FunctionDesc o1, FunctionDesc o2) {
                int a = getIndexOf(o1);
                int b = getIndexOf(o2);
                return a - b;
            }
        });

        String[] result = new String[metricList.size()];
        int i = 0;
        for (FunctionDesc metric : metricList) {
            result[i++] = metric.getExpression();
        }
        return result;
    }
 
Example 2
Source File: CuboidToGridTableMapping.java    From kylin with Apache License 2.0 6 votes vote down vote up
public String[] makeAggrFuncs(Collection<? extends FunctionDesc> metrics) {

        //metrics are represented in ImmutableBitSet, which loses order information
        //sort the aggrFuns to align with metrics natural order 
        List<FunctionDesc> metricList = Lists.newArrayList(metrics);
        Collections.sort(metricList, new Comparator<FunctionDesc>() {
            @Override
            public int compare(FunctionDesc o1, FunctionDesc o2) {
                int a = getIndexOf(o1);
                int b = getIndexOf(o2);
                return a - b;
            }
        });

        String[] result = new String[metricList.size()];
        int i = 0;
        for (FunctionDesc metric : metricList) {
            result[i++] = metric.getExpression();
        }
        return result;
    }
 
Example 3
Source File: FunctionRule.java    From Kylin with Apache License 2.0 6 votes vote down vote up
private void validateReturnType(ValidateContext context, CubeDesc cube, FunctionDesc funcDesc) {

        String func = funcDesc.getExpression();
        DataType rtype = funcDesc.getReturnDataType();

        if (funcDesc.isCount()) {
            if (rtype.isIntegerFamily() == false) {
                context.addResult(ResultLevel.ERROR, "Return type for function " + func + " must be one of " + DataType.INTEGER_FAMILY);
            }
        } else if (funcDesc.isCountDistinct()) {
            if (rtype.isHLLC() == false && funcDesc.isHolisticCountDistinct() == false) {
                context.addResult(ResultLevel.ERROR, "Return type for function " + func + " must be hllc(10), hllc(12) etc.");
            }
        } else if (funcDesc.isMax() || funcDesc.isMin() || funcDesc.isSum()) {
            if (rtype.isNumberFamily() == false) {
                context.addResult(ResultLevel.ERROR, "Return type for function " + func + " must be one of " + DataType.NUMBER_FAMILY);
            }
        } else {
            if (StringUtils.equalsIgnoreCase(KylinConfig.getInstanceFromEnv().getProperty(KEY_IGNORE_UNKNOWN_FUNC, "false"), "false")) {
                context.addResult(ResultLevel.ERROR, "Unrecognized function: [" + func + "]");
            }
        }

    }
 
Example 4
Source File: EndpointAggregators.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public static EndpointAggregators fromFunctions(TableRecordInfo tableInfo, List<FunctionDesc> metrics) {
    String[] funcNames = new String[metrics.size()];
    String[] dataTypes = new String[metrics.size()];
    MetricInfo[] metricInfos = new MetricInfo[metrics.size()];

    for (int i = 0; i < metrics.size(); i++) {
        FunctionDesc functionDesc = metrics.get(i);

        //TODO: what if funcionDesc's type is different from tablDesc? cause scale difference
        funcNames[i] = functionDesc.getExpression();
        dataTypes[i] = functionDesc.getReturnType();

        if (functionDesc.isCount()) {
            metricInfos[i] = new MetricInfo(MetricType.Count);
        } else if (functionDesc.isDimensionAsMetric()) {
            metricInfos[i] = new MetricInfo(MetricType.DimensionAsMetric);
        } else {
            int index = tableInfo.findFactTableColumn(functionDesc.getParameter().getValue());
            if (index < 0) {
                throw new IllegalStateException("Column " + functionDesc.getParameter().getValue() + " is not found in II");
            }

            if (functionDesc.isCountDistinct()) {
                metricInfos[i] = new MetricInfo(MetricType.DistinctCount, index, functionDesc.getReturnDataType().getPrecision());
            } else {
                metricInfos[i] = new MetricInfo(MetricType.Normal, index);
            }
        }
    }

    return new EndpointAggregators(funcNames, dataTypes, metricInfos, tableInfo.getDigest());
}