@Test public void testGoodDesc() throws IOException { DictionaryRule rule = new DictionaryRule(); for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/").listFiles()) { if (!f.getName().endsWith("json")) { continue; } CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class); desc.init(config); ValidateContext vContext = new ValidateContext(); rule.validate(desc, vContext); assertTrue(vContext.getResults().length == 0); } }
@Override public void validate(CubeDesc cubeDesc, ValidateContext context) { List<DictionaryDesc> dictDescs = cubeDesc.getDictionaries(); Set<TblColRef> dimensionColumns = cubeDesc.listDimensionColumnsIncludingDerived(); RowKeyDesc rowKeyDesc = cubeDesc.getRowkey(); if (dictDescs == null || dictDescs.isEmpty()) { return; } Set<TblColRef> allDictCols = new HashSet<>(); Set<TblColRef> baseCols = new HashSet<>(); List<DictionaryDesc> reuseDictionaries = new ArrayList<>(); for (DictionaryDesc dictDesc : dictDescs) { TblColRef dictCol = dictDesc.getColumnRef(); TblColRef reuseCol = dictDesc.getResuseColumnRef(); String builderClass = dictDesc.getBuilderClass(); if (!allDictCols.add(dictCol)) { context.addResult(ResultLevel.ERROR, ERROR_DUPLICATE_DICTIONARY_COLUMN + dictCol); return; } if (reuseCol != null && StringUtils.isNotEmpty(builderClass)) { context.addResult(ResultLevel.ERROR, ERROR_REUSE_BUILDER_BOTH_SET + dictCol); return; } if (reuseCol == null && StringUtils.isEmpty(builderClass)) { if(dictDesc.isDomain()) { logger.info("() is tiretree global domain dic", dictCol); }else{ context.addResult(ResultLevel.ERROR, ERROR_REUSE_BUILDER_BOTH_EMPTY + dictCol); return; } } if (StringUtils.isNotEmpty(builderClass) && builderClass.equalsIgnoreCase(GlobalDictionaryBuilder.class.getName()) && dimensionColumns.contains(dictCol) && rowKeyDesc.isUseDictionary(dictCol)) { context.addResult(ResultLevel.ERROR, ERROR_GLOBAL_DICTIONNARY_ONLY_MEASURE + dictCol); return; } if (reuseCol != null) { reuseDictionaries.add(dictDesc); } else { baseCols.add(dictCol); } } for (DictionaryDesc dictDesc : reuseDictionaries) { if (!baseCols.contains(dictDesc.getResuseColumnRef())) { context.addResult(ResultLevel.ERROR, ERROR_TRANSITIVE_REUSE + dictDesc.getColumnRef()); return; } } }
DictionaryRule implements IValidatorRule<CubeDesc> { @Override public void validate(CubeDesc cubeDesc, ValidateContext context) { List<DictionaryDesc> dictDescs = cubeDesc.getDictionaries(); Set<TblColRef> dimensionColumns = cubeDesc.listDimensionColumnsIncludingDerived(); RowKeyDesc rowKeyDesc = cubeDesc.getRowkey(); if (dictDescs == null || dictDescs.isEmpty()) { return; } Set<TblColRef> allDictCols = new HashSet<>(); Set<TblColRef> baseCols = new HashSet<>(); List<DictionaryDesc> reuseDictionaries = new ArrayList<>(); for (DictionaryDesc dictDesc : dictDescs) { TblColRef dictCol = dictDesc.getColumnRef(); TblColRef reuseCol = dictDesc.getResuseColumnRef(); String builderClass = dictDesc.getBuilderClass(); if (!allDictCols.add(dictCol)) { context.addResult(ResultLevel.ERROR, ERROR_DUPLICATE_DICTIONARY_COLUMN + dictCol); return; } if (reuseCol != null && StringUtils.isNotEmpty(builderClass)) { context.addResult(ResultLevel.ERROR, ERROR_REUSE_BUILDER_BOTH_SET + dictCol); return; } if (reuseCol == null && StringUtils.isEmpty(builderClass)) { if(dictDesc.isDomain()) { logger.info("() is tiretree global domain dic", dictCol); }else{ context.addResult(ResultLevel.ERROR, ERROR_REUSE_BUILDER_BOTH_EMPTY + dictCol); return; } } if (StringUtils.isNotEmpty(builderClass) && builderClass.equalsIgnoreCase(GlobalDictionaryBuilder.class.getName()) && dimensionColumns.contains(dictCol) && rowKeyDesc.isUseDictionary(dictCol)) { context.addResult(ResultLevel.ERROR, ERROR_GLOBAL_DICTIONNARY_ONLY_MEASURE + dictCol); return; } if (reuseCol != null) { reuseDictionaries.add(dictDesc); } else { baseCols.add(dictCol); } } for (DictionaryDesc dictDesc : reuseDictionaries) { if (!baseCols.contains(dictDesc.getResuseColumnRef())) { context.addResult(ResultLevel.ERROR, ERROR_TRANSITIVE_REUSE + dictDesc.getColumnRef()); return; } } } }
DictionaryRule implements IValidatorRule<CubeDesc> { @Override public void validate(CubeDesc cubeDesc, ValidateContext context) { List<DictionaryDesc> dictDescs = cubeDesc.getDictionaries(); Set<TblColRef> dimensionColumns = cubeDesc.listDimensionColumnsIncludingDerived(); RowKeyDesc rowKeyDesc = cubeDesc.getRowkey(); if (dictDescs == null || dictDescs.isEmpty()) { return; } Set<TblColRef> allDictCols = new HashSet<>(); Set<TblColRef> baseCols = new HashSet<>(); List<DictionaryDesc> reuseDictionaries = new ArrayList<>(); for (DictionaryDesc dictDesc : dictDescs) { TblColRef dictCol = dictDesc.getColumnRef(); TblColRef reuseCol = dictDesc.getResuseColumnRef(); String builderClass = dictDesc.getBuilderClass(); if (!allDictCols.add(dictCol)) { context.addResult(ResultLevel.ERROR, ERROR_DUPLICATE_DICTIONARY_COLUMN + dictCol); return; } if (reuseCol != null && StringUtils.isNotEmpty(builderClass)) { context.addResult(ResultLevel.ERROR, ERROR_REUSE_BUILDER_BOTH_SET + dictCol); return; } if (reuseCol == null && StringUtils.isEmpty(builderClass)) { if(dictDesc.isDomain()) { logger.info("() is tiretree global domain dic", dictCol); }else{ context.addResult(ResultLevel.ERROR, ERROR_REUSE_BUILDER_BOTH_EMPTY + dictCol); return; } } if (StringUtils.isNotEmpty(builderClass) && builderClass.equalsIgnoreCase(GlobalDictionaryBuilder.class.getName()) && dimensionColumns.contains(dictCol) && rowKeyDesc.isUseDictionary(dictCol)) { context.addResult(ResultLevel.ERROR, ERROR_GLOBAL_DICTIONNARY_ONLY_MEASURE + dictCol); return; } if (reuseCol != null) { reuseDictionaries.add(dictDesc); } else { baseCols.add(dictCol); } } for (DictionaryDesc dictDesc : reuseDictionaries) { if (!baseCols.contains(dictDesc.getResuseColumnRef())) { context.addResult(ResultLevel.ERROR, ERROR_TRANSITIVE_REUSE + dictDesc.getColumnRef()); return; } } }  }
DictionaryRule implements IValidatorRule<CubeDesc> { @Override public void validate(CubeDesc cubeDesc, ValidateContext context) { List<DictionaryDesc> dictDescs = cubeDesc.getDictionaries(); Set<TblColRef> dimensionColumns = cubeDesc.listDimensionColumnsIncludingDerived(); RowKeyDesc rowKeyDesc = cubeDesc.getRowkey(); if (dictDescs == null || dictDescs.isEmpty()) { return; } Set<TblColRef> allDictCols = new HashSet<>(); Set<TblColRef> baseCols = new HashSet<>(); List<DictionaryDesc> reuseDictionaries = new ArrayList<>(); for (DictionaryDesc dictDesc : dictDescs) { TblColRef dictCol = dictDesc.getColumnRef(); TblColRef reuseCol = dictDesc.getResuseColumnRef(); String builderClass = dictDesc.getBuilderClass(); if (!allDictCols.add(dictCol)) { context.addResult(ResultLevel.ERROR, ERROR_DUPLICATE_DICTIONARY_COLUMN + dictCol); return; } if (reuseCol != null && StringUtils.isNotEmpty(builderClass)) { context.addResult(ResultLevel.ERROR, ERROR_REUSE_BUILDER_BOTH_SET + dictCol); return; } if (reuseCol == null && StringUtils.isEmpty(builderClass)) { if(dictDesc.isDomain()) { logger.info("() is tiretree global domain dic", dictCol); }else{ context.addResult(ResultLevel.ERROR, ERROR_REUSE_BUILDER_BOTH_EMPTY + dictCol); return; } } if (StringUtils.isNotEmpty(builderClass) && builderClass.equalsIgnoreCase(GlobalDictionaryBuilder.class.getName()) && dimensionColumns.contains(dictCol) && rowKeyDesc.isUseDictionary(dictCol)) { context.addResult(ResultLevel.ERROR, ERROR_GLOBAL_DICTIONNARY_ONLY_MEASURE + dictCol); return; } if (reuseCol != null) { reuseDictionaries.add(dictDesc); } else { baseCols.add(dictCol); } } for (DictionaryDesc dictDesc : reuseDictionaries) { if (!baseCols.contains(dictDesc.getResuseColumnRef())) { context.addResult(ResultLevel.ERROR, ERROR_TRANSITIVE_REUSE + dictDesc.getColumnRef()); return; } } }  @Override void validate(CubeDesc cubeDesc, ValidateContext context); }
DictionaryRule implements IValidatorRule<CubeDesc> { @Override public void validate(CubeDesc cubeDesc, ValidateContext context) { List<DictionaryDesc> dictDescs = cubeDesc.getDictionaries(); Set<TblColRef> dimensionColumns = cubeDesc.listDimensionColumnsIncludingDerived(); RowKeyDesc rowKeyDesc = cubeDesc.getRowkey(); if (dictDescs == null || dictDescs.isEmpty()) { return; } Set<TblColRef> allDictCols = new HashSet<>(); Set<TblColRef> baseCols = new HashSet<>(); List<DictionaryDesc> reuseDictionaries = new ArrayList<>(); for (DictionaryDesc dictDesc : dictDescs) { TblColRef dictCol = dictDesc.getColumnRef(); TblColRef reuseCol = dictDesc.getResuseColumnRef(); String builderClass = dictDesc.getBuilderClass(); if (!allDictCols.add(dictCol)) { context.addResult(ResultLevel.ERROR, ERROR_DUPLICATE_DICTIONARY_COLUMN + dictCol); return; } if (reuseCol != null && StringUtils.isNotEmpty(builderClass)) { context.addResult(ResultLevel.ERROR, ERROR_REUSE_BUILDER_BOTH_SET + dictCol); return; } if (reuseCol == null && StringUtils.isEmpty(builderClass)) { if(dictDesc.isDomain()) { logger.info("() is tiretree global domain dic", dictCol); }else{ context.addResult(ResultLevel.ERROR, ERROR_REUSE_BUILDER_BOTH_EMPTY + dictCol); return; } } if (StringUtils.isNotEmpty(builderClass) && builderClass.equalsIgnoreCase(GlobalDictionaryBuilder.class.getName()) && dimensionColumns.contains(dictCol) && rowKeyDesc.isUseDictionary(dictCol)) { context.addResult(ResultLevel.ERROR, ERROR_GLOBAL_DICTIONNARY_ONLY_MEASURE + dictCol); return; } if (reuseCol != null) { reuseDictionaries.add(dictDesc); } else { baseCols.add(dictCol); } } for (DictionaryDesc dictDesc : reuseDictionaries) { if (!baseCols.contains(dictDesc.getResuseColumnRef())) { context.addResult(ResultLevel.ERROR, ERROR_TRANSITIVE_REUSE + dictDesc.getColumnRef()); return; } } }  @Override void validate(CubeDesc cubeDesc, ValidateContext context);  }