@Test public void testGoodDesc() throws IOException { FunctionRule rule = new FunctionRule(); File f = new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/ssb.json"); CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class); desc.init(config); ValidateContext vContext = new ValidateContext(); rule.validate(desc, vContext); vContext.print(System.out); assertTrue(vContext.getResults().length == 0); }
@Override public void validate(CubeDesc cube, ValidateContext context) { List<MeasureDesc> measures = cube.getMeasures(); if (validateMeasureNamesDuplicated(measures, context)) { return; } List<FunctionDesc> countStarFuncs = new ArrayList<FunctionDesc>(); Iterator<MeasureDesc> it = measures.iterator(); while (it.hasNext()) { MeasureDesc measure = it.next(); FunctionDesc func = measure.getFunction(); ParameterDesc parameter = func.getParameter(); if (parameter == null) { context.addResult(ResultLevel.ERROR, "Must define parameter for function " + func.getExpression() + " in " + measure.getName()); return; } String type = func.getParameter().getType(); String value = func.getParameter().getValue(); if (StringUtils.isEmpty(type)) { context.addResult(ResultLevel.ERROR, "Must define type for parameter type " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.isEmpty(value)) { context.addResult(ResultLevel.ERROR, "Must define type for parameter value " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.isEmpty(func.getReturnType())) { context.addResult(ResultLevel.ERROR, "Must define return type for function " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.equalsIgnoreCase(FunctionDesc.PARAMETER_TYPE_COLUMN, type)) { validateColumnParameter(context, cube, value); } else if (StringUtils.equals(FunctionDesc.PARAMETER_TYPE_CONSTANT, type)) { validateCostantParameter(context, cube, value); } try { func.getMeasureType().validate(func); } catch (IllegalArgumentException ex) { context.addResult(ResultLevel.ERROR, ex.getMessage()); } if (func.isCount() && func.getParameter().isConstant()) countStarFuncs.add(func); if (TopNMeasureType.FUNC_TOP_N.equalsIgnoreCase(func.getExpression())) { if (parameter.getNextParameter() == null) { context.addResult(ResultLevel.ERROR, "Must define at least 2 parameters for function " + func.getExpression() + " in " + measure.getName()); return; } ParameterDesc groupByCol = parameter.getNextParameter(); List<String> duplicatedCol = Lists.newArrayList(); while (groupByCol != null) { String embeded_groupby = groupByCol.getValue(); for (DimensionDesc dimensionDesc : cube.getDimensions()) { if (dimensionDesc.getColumn() != null && dimensionDesc.getColumn().equalsIgnoreCase(embeded_groupby)) { duplicatedCol.add(embeded_groupby); } } groupByCol = groupByCol.getNextParameter(); } } } if (countStarFuncs.size() != 1) { context.addResult(ResultLevel.ERROR, "Must define one and only one count(1) function, but there are " + countStarFuncs.size() + " -- " + countStarFuncs); } }
FunctionRule implements IValidatorRule<CubeDesc> { @Override public void validate(CubeDesc cube, ValidateContext context) { List<MeasureDesc> measures = cube.getMeasures(); if (validateMeasureNamesDuplicated(measures, context)) { return; } List<FunctionDesc> countStarFuncs = new ArrayList<FunctionDesc>(); Iterator<MeasureDesc> it = measures.iterator(); while (it.hasNext()) { MeasureDesc measure = it.next(); FunctionDesc func = measure.getFunction(); ParameterDesc parameter = func.getParameter(); if (parameter == null) { context.addResult(ResultLevel.ERROR, "Must define parameter for function " + func.getExpression() + " in " + measure.getName()); return; } String type = func.getParameter().getType(); String value = func.getParameter().getValue(); if (StringUtils.isEmpty(type)) { context.addResult(ResultLevel.ERROR, "Must define type for parameter type " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.isEmpty(value)) { context.addResult(ResultLevel.ERROR, "Must define type for parameter value " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.isEmpty(func.getReturnType())) { context.addResult(ResultLevel.ERROR, "Must define return type for function " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.equalsIgnoreCase(FunctionDesc.PARAMETER_TYPE_COLUMN, type)) { validateColumnParameter(context, cube, value); } else if (StringUtils.equals(FunctionDesc.PARAMETER_TYPE_CONSTANT, type)) { validateCostantParameter(context, cube, value); } try { func.getMeasureType().validate(func); } catch (IllegalArgumentException ex) { context.addResult(ResultLevel.ERROR, ex.getMessage()); } if (func.isCount() && func.getParameter().isConstant()) countStarFuncs.add(func); if (TopNMeasureType.FUNC_TOP_N.equalsIgnoreCase(func.getExpression())) { if (parameter.getNextParameter() == null) { context.addResult(ResultLevel.ERROR, "Must define at least 2 parameters for function " + func.getExpression() + " in " + measure.getName()); return; } ParameterDesc groupByCol = parameter.getNextParameter(); List<String> duplicatedCol = Lists.newArrayList(); while (groupByCol != null) { String embeded_groupby = groupByCol.getValue(); for (DimensionDesc dimensionDesc : cube.getDimensions()) { if (dimensionDesc.getColumn() != null && dimensionDesc.getColumn().equalsIgnoreCase(embeded_groupby)) { duplicatedCol.add(embeded_groupby); } } groupByCol = groupByCol.getNextParameter(); } } } if (countStarFuncs.size() != 1) { context.addResult(ResultLevel.ERROR, "Must define one and only one count(1) function, but there are " + countStarFuncs.size() + " -- " + countStarFuncs); } } }
FunctionRule implements IValidatorRule<CubeDesc> { @Override public void validate(CubeDesc cube, ValidateContext context) { List<MeasureDesc> measures = cube.getMeasures(); if (validateMeasureNamesDuplicated(measures, context)) { return; } List<FunctionDesc> countStarFuncs = new ArrayList<FunctionDesc>(); Iterator<MeasureDesc> it = measures.iterator(); while (it.hasNext()) { MeasureDesc measure = it.next(); FunctionDesc func = measure.getFunction(); ParameterDesc parameter = func.getParameter(); if (parameter == null) { context.addResult(ResultLevel.ERROR, "Must define parameter for function " + func.getExpression() + " in " + measure.getName()); return; } String type = func.getParameter().getType(); String value = func.getParameter().getValue(); if (StringUtils.isEmpty(type)) { context.addResult(ResultLevel.ERROR, "Must define type for parameter type " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.isEmpty(value)) { context.addResult(ResultLevel.ERROR, "Must define type for parameter value " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.isEmpty(func.getReturnType())) { context.addResult(ResultLevel.ERROR, "Must define return type for function " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.equalsIgnoreCase(FunctionDesc.PARAMETER_TYPE_COLUMN, type)) { validateColumnParameter(context, cube, value); } else if (StringUtils.equals(FunctionDesc.PARAMETER_TYPE_CONSTANT, type)) { validateCostantParameter(context, cube, value); } try { func.getMeasureType().validate(func); } catch (IllegalArgumentException ex) { context.addResult(ResultLevel.ERROR, ex.getMessage()); } if (func.isCount() && func.getParameter().isConstant()) countStarFuncs.add(func); if (TopNMeasureType.FUNC_TOP_N.equalsIgnoreCase(func.getExpression())) { if (parameter.getNextParameter() == null) { context.addResult(ResultLevel.ERROR, "Must define at least 2 parameters for function " + func.getExpression() + " in " + measure.getName()); return; } ParameterDesc groupByCol = parameter.getNextParameter(); List<String> duplicatedCol = Lists.newArrayList(); while (groupByCol != null) { String embeded_groupby = groupByCol.getValue(); for (DimensionDesc dimensionDesc : cube.getDimensions()) { if (dimensionDesc.getColumn() != null && dimensionDesc.getColumn().equalsIgnoreCase(embeded_groupby)) { duplicatedCol.add(embeded_groupby); } } groupByCol = groupByCol.getNextParameter(); } } } if (countStarFuncs.size() != 1) { context.addResult(ResultLevel.ERROR, "Must define one and only one count(1) function, but there are " + countStarFuncs.size() + " -- " + countStarFuncs); } }  }
FunctionRule implements IValidatorRule<CubeDesc> { @Override public void validate(CubeDesc cube, ValidateContext context) { List<MeasureDesc> measures = cube.getMeasures(); if (validateMeasureNamesDuplicated(measures, context)) { return; } List<FunctionDesc> countStarFuncs = new ArrayList<FunctionDesc>(); Iterator<MeasureDesc> it = measures.iterator(); while (it.hasNext()) { MeasureDesc measure = it.next(); FunctionDesc func = measure.getFunction(); ParameterDesc parameter = func.getParameter(); if (parameter == null) { context.addResult(ResultLevel.ERROR, "Must define parameter for function " + func.getExpression() + " in " + measure.getName()); return; } String type = func.getParameter().getType(); String value = func.getParameter().getValue(); if (StringUtils.isEmpty(type)) { context.addResult(ResultLevel.ERROR, "Must define type for parameter type " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.isEmpty(value)) { context.addResult(ResultLevel.ERROR, "Must define type for parameter value " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.isEmpty(func.getReturnType())) { context.addResult(ResultLevel.ERROR, "Must define return type for function " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.equalsIgnoreCase(FunctionDesc.PARAMETER_TYPE_COLUMN, type)) { validateColumnParameter(context, cube, value); } else if (StringUtils.equals(FunctionDesc.PARAMETER_TYPE_CONSTANT, type)) { validateCostantParameter(context, cube, value); } try { func.getMeasureType().validate(func); } catch (IllegalArgumentException ex) { context.addResult(ResultLevel.ERROR, ex.getMessage()); } if (func.isCount() && func.getParameter().isConstant()) countStarFuncs.add(func); if (TopNMeasureType.FUNC_TOP_N.equalsIgnoreCase(func.getExpression())) { if (parameter.getNextParameter() == null) { context.addResult(ResultLevel.ERROR, "Must define at least 2 parameters for function " + func.getExpression() + " in " + measure.getName()); return; } ParameterDesc groupByCol = parameter.getNextParameter(); List<String> duplicatedCol = Lists.newArrayList(); while (groupByCol != null) { String embeded_groupby = groupByCol.getValue(); for (DimensionDesc dimensionDesc : cube.getDimensions()) { if (dimensionDesc.getColumn() != null && dimensionDesc.getColumn().equalsIgnoreCase(embeded_groupby)) { duplicatedCol.add(embeded_groupby); } } groupByCol = groupByCol.getNextParameter(); } } } if (countStarFuncs.size() != 1) { context.addResult(ResultLevel.ERROR, "Must define one and only one count(1) function, but there are " + countStarFuncs.size() + " -- " + countStarFuncs); } }  @Override void validate(CubeDesc cube, ValidateContext context); }
FunctionRule implements IValidatorRule<CubeDesc> { @Override public void validate(CubeDesc cube, ValidateContext context) { List<MeasureDesc> measures = cube.getMeasures(); if (validateMeasureNamesDuplicated(measures, context)) { return; } List<FunctionDesc> countStarFuncs = new ArrayList<FunctionDesc>(); Iterator<MeasureDesc> it = measures.iterator(); while (it.hasNext()) { MeasureDesc measure = it.next(); FunctionDesc func = measure.getFunction(); ParameterDesc parameter = func.getParameter(); if (parameter == null) { context.addResult(ResultLevel.ERROR, "Must define parameter for function " + func.getExpression() + " in " + measure.getName()); return; } String type = func.getParameter().getType(); String value = func.getParameter().getValue(); if (StringUtils.isEmpty(type)) { context.addResult(ResultLevel.ERROR, "Must define type for parameter type " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.isEmpty(value)) { context.addResult(ResultLevel.ERROR, "Must define type for parameter value " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.isEmpty(func.getReturnType())) { context.addResult(ResultLevel.ERROR, "Must define return type for function " + func.getExpression() + " in " + measure.getName()); return; } if (StringUtils.equalsIgnoreCase(FunctionDesc.PARAMETER_TYPE_COLUMN, type)) { validateColumnParameter(context, cube, value); } else if (StringUtils.equals(FunctionDesc.PARAMETER_TYPE_CONSTANT, type)) { validateCostantParameter(context, cube, value); } try { func.getMeasureType().validate(func); } catch (IllegalArgumentException ex) { context.addResult(ResultLevel.ERROR, ex.getMessage()); } if (func.isCount() && func.getParameter().isConstant()) countStarFuncs.add(func); if (TopNMeasureType.FUNC_TOP_N.equalsIgnoreCase(func.getExpression())) { if (parameter.getNextParameter() == null) { context.addResult(ResultLevel.ERROR, "Must define at least 2 parameters for function " + func.getExpression() + " in " + measure.getName()); return; } ParameterDesc groupByCol = parameter.getNextParameter(); List<String> duplicatedCol = Lists.newArrayList(); while (groupByCol != null) { String embeded_groupby = groupByCol.getValue(); for (DimensionDesc dimensionDesc : cube.getDimensions()) { if (dimensionDesc.getColumn() != null && dimensionDesc.getColumn().equalsIgnoreCase(embeded_groupby)) { duplicatedCol.add(embeded_groupby); } } groupByCol = groupByCol.getNextParameter(); } } } if (countStarFuncs.size() != 1) { context.addResult(ResultLevel.ERROR, "Must define one and only one count(1) function, but there are " + countStarFuncs.size() + " -- " + countStarFuncs); } }  @Override void validate(CubeDesc cube, ValidateContext context);  }