org.apache.kylin.cube.model.validation.ValidateContext Java Examples

The following examples show how to use org.apache.kylin.cube.model.validation.ValidateContext. 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: RowKeyAttrRule.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public void validate(CubeDesc cube, ValidateContext context) {
    RowKeyDesc row = cube.getRowkey();
    if (row == null) {
        context.addResult(ResultLevel.ERROR, "Rowkey does not exist");
        return;
    }

    RowKeyColDesc[] rcd = row.getRowKeyColumns();
    if (rcd == null || rcd.length == 0) {
        context.addResult(ResultLevel.ERROR, "Rowkey columns do not exist");
        return;
    }

    for (int i = 0; i < rcd.length; i++) {
        RowKeyColDesc rd = rcd[i];
        if (rd.getColumn() == null || rd.getColumn().length() == 0) {
            context.addResult(ResultLevel.ERROR, "Rowkey column empty");
        }

    }

}
 
Example #2
Source File: AggregationGroupRuleTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGoodDesc() throws IOException {
    AggregationGroupRule rule = getAggregationGroupRule();

    for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/").listFiles()) {
        if (!f.getName().endsWith("json")) {
            continue;
        }
        CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
        desc.init(getTestConfig());
        ValidateContext vContext = new ValidateContext();
        rule.validate(desc, vContext);
        //vContext.print(System.out);
        assertTrue(vContext.getResults().length == 0);
    }
}
 
Example #3
Source File: AggregationGroupRuleTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGoodBecomeBadDesc() throws IOException {
    AggregationGroupRule rule = new AggregationGroupRule() {
        @Override
        protected long getMaxCombinations(CubeDesc cubeDesc) {
            return 2;
        }
    };

    for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/").listFiles()) {
        System.out.println(f.getName());
        CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
        try {
            desc.init(getTestConfig());
        } catch (Exception e) {
            // Ignore any exception here, validation may fail for bad json
        }
        ValidateContext vContext = new ValidateContext();
        rule.validate(desc, vContext);
        //vContext.print(System.out);
        assertTrue(vContext.getResults().length > 0);
        assertTrue(vContext.getResults()[0].getMessage().startsWith("Aggregation group 1 has too many combinations"));
    }
}
 
Example #4
Source File: RowKeyAttrRule.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Override
public void validate(CubeDesc cube, ValidateContext context) {
    RowKeyDesc row = cube.getRowkey();
    if (row == null) {
        context.addResult(ResultLevel.ERROR, "Rowkey does not exist");
        return;
    }

    RowKeyColDesc[] rcd = row.getRowKeyColumns();
    if (rcd == null || rcd.length == 0) {
        context.addResult(ResultLevel.ERROR, "Rowkey columns do not exist");
        return;
    }

    for (int i = 0; i < rcd.length; i++) {
        RowKeyColDesc rd = rcd[i];
        if (rd.getColumn() == null || rd.getColumn().length() == 0) {
            context.addResult(ResultLevel.ERROR, "Rowkey column empty");
        }

    }

}
 
Example #5
Source File: AggregationGroupRuleTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testCombinationIntOverflow() throws IOException {
    for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/").listFiles()) {
        if (f.getName().endsWith("bad")) {
            String path = f.getPath();
            f.renameTo(new File(path.substring(0, path.length() - 4)));
        }
    }

    ValidateContext vContext = new ValidateContext();
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/ut_cube_desc_combination_int_overflow.json"), CubeDesc.class);

    IValidatorRule<CubeDesc> rule = getAggregationGroupRule();
    try {
        desc.init(getTestConfig());
    } catch (Exception ex) {
        // as it's a failure case, it should throw exception
    }
    rule.validate(desc, vContext);
    assertEquals(1, vContext.getResults().length);
}
 
Example #6
Source File: DictionaryRuleTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void testDictionaryDesc(String expectMessage, DictionaryDesc... descs) throws IOException {
    DictionaryRule rule = new DictionaryRule();
    File f = new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/test_kylin_cube_without_slr_left_join_desc.json");
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);

    List<DictionaryDesc> newDicts = Lists.newArrayList(desc.getDictionaries());
    for (DictionaryDesc dictDesc : descs) {
        newDicts.add(dictDesc);
    }
    desc.setDictionaries(newDicts);

    desc.init(config);
    ValidateContext vContext = new ValidateContext();
    rule.validate(desc, vContext);

    if (expectMessage == null) {
        assertTrue(vContext.getResults().length == 0);
    } else {
        assertTrue(vContext.getResults().length == 1);
        String actualMessage = vContext.getResults()[0].getMessage();
        assertTrue(actualMessage.startsWith(expectMessage));
    }
}
 
Example #7
Source File: DictionaryRuleTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void testDictionaryDesc(String expectMessage, DictionaryDesc... descs) throws IOException {
    DictionaryRule rule = new DictionaryRule();
    File f = new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/test_kylin_cube_without_slr_left_join_desc.json");
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);

    List<DictionaryDesc> newDicts = Lists.newArrayList(desc.getDictionaries());
    for (DictionaryDesc dictDesc : descs) {
        newDicts.add(dictDesc);
    }
    desc.setDictionaries(newDicts);

    desc.init(config);
    ValidateContext vContext = new ValidateContext();
    rule.validate(desc, vContext);

    if (expectMessage == null) {
        assertTrue(vContext.getResults().length == 0);
    } else {
        assertTrue(vContext.getResults().length == 1);
        String actualMessage = vContext.getResults()[0].getMessage();
        assertTrue(actualMessage.startsWith(expectMessage));
    }
}
 
Example #8
Source File: AggregationGroupRuleTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testCombinationIntOverflow() throws IOException {
    for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/").listFiles()) {
        if (f.getName().endsWith("bad")) {
            String path = f.getPath();
            f.renameTo(new File(path.substring(0, path.length() - 4)));
        }
    }

    ValidateContext vContext = new ValidateContext();
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/ut_cube_desc_combination_int_overflow.json"), CubeDesc.class);

    IValidatorRule<CubeDesc> rule = getAggregationGroupRule();
    try {
        desc.init(getTestConfig());
    } catch (Exception ex) {
        // as it's a failure case, it should throw exception
    }
    rule.validate(desc, vContext);
    assertEquals(1, vContext.getResults().length);
}
 
Example #9
Source File: AggregationGroupRuleTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGoodBecomeBadDesc() throws IOException {
    AggregationGroupRule rule = new AggregationGroupRule() {
        @Override
        protected long getMaxCombinations(CubeDesc cubeDesc) {
            return 2;
        }
    };

    for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/").listFiles()) {
        System.out.println(f.getName());
        CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
        try {
            desc.init(getTestConfig());
        } catch (Exception e) {
            // Ignore any exception here, validation may fail for bad json
        }
        ValidateContext vContext = new ValidateContext();
        rule.validate(desc, vContext);
        //vContext.print(System.out);
        assertTrue(vContext.getResults().length > 0);
        assertTrue(vContext.getResults()[0].getMessage().startsWith("Aggregation group 1 has too many combinations"));
    }
}
 
Example #10
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 #11
Source File: AggregationGroupRuleTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGoodDesc() throws IOException {
    AggregationGroupRule rule = getAggregationGroupRule();

    for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/").listFiles()) {
        if (!f.getName().endsWith("json")) {
            continue;
        }
        CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
        desc.init(getTestConfig());
        ValidateContext vContext = new ValidateContext();
        rule.validate(desc, vContext);
        //vContext.print(System.out);
        assertTrue(vContext.getResults().length == 0);
    }
}
 
Example #12
Source File: DictionaryRuleTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #13
Source File: CubeDescManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new CubeDesc
 */
public CubeDesc createCubeDesc(CubeDesc cubeDesc) throws IOException {
    try (AutoLock lock = descMapLock.lockForWrite()) {
        if (cubeDesc.getUuid() == null || cubeDesc.getName() == null)
            throw new IllegalArgumentException();
        if (cubeDescMap.containsKey(cubeDesc.getName()))
            throw new IllegalArgumentException("CubeDesc '" + cubeDesc.getName() + "' already exists");
        if (cubeDesc.isDraft())
            throw new IllegalArgumentException(String.format(Locale.ROOT, CUBE_SHOULD_NOT_BE_DRAFT_MSG, cubeDesc.getName()));

        try {
            cubeDesc.init(config);
        } catch (Exception e) {
            logger.warn("Broken cube desc " + cubeDesc, e);
            cubeDesc.addError(e.toString());
        }
        
        postProcessCubeDesc(cubeDesc);
        // Check base validation
        if (cubeDesc.isBroken()) {
            return cubeDesc;
        }
        // Semantic validation
        CubeMetadataValidator validator = new CubeMetadataValidator(config);
        ValidateContext context = validator.validate(cubeDesc);
        if (!context.ifPass()) {
            return cubeDesc;
        }

        cubeDesc.setSignature(cubeDesc.calculateSignature());

        // save resource
        crud.save(cubeDesc);
        
        return cubeDesc;
    }
}
 
Example #14
Source File: CubeDescManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Update CubeDesc with the input. Broadcast the event into cluster
 */
public CubeDesc updateCubeDesc(CubeDesc desc) throws IOException {
    try (AutoLock lock = descMapLock.lockForWrite()) {
        // Validate CubeDesc
        if (desc.getUuid() == null || desc.getName() == null)
            throw new IllegalArgumentException();
        String name = desc.getName();
        if (!cubeDescMap.containsKey(name))
            throw new IllegalArgumentException("CubeDesc '" + name + "' does not exist.");
        if (desc.isDraft())
            throw new IllegalArgumentException(String.format(Locale.ROOT, CUBE_SHOULD_NOT_BE_DRAFT_MSG, desc.getName()));

        try {
            desc.init(config);
        } catch (Exception e) {
            logger.warn("Broken cube desc " + desc, e);
            desc.addError(e.toString());
            return desc;
        }

        postProcessCubeDesc(desc);
        // Semantic validation
        CubeMetadataValidator validator = new CubeMetadataValidator(config);
        ValidateContext context = validator.validate(desc);
        if (!context.ifPass()) {
            return desc;
        }

        desc.setSignature(desc.calculateSignature());

        // save resource
        crud.save(desc);

        return desc;
    }
}
 
Example #15
Source File: CubeDescManager.java    From Kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new CubeDesc
 * 
 * @param cubeDesc
 * @return
 * @throws IOException
 */
public CubeDesc createCubeDesc(CubeDesc cubeDesc) throws IOException {
    if (cubeDesc.getUuid() == null || cubeDesc.getName() == null)
        throw new IllegalArgumentException();
    if (cubeDescMap.containsKey(cubeDesc.getName()))
        throw new IllegalArgumentException("CubeDesc '" + cubeDesc.getName() + "' already exists");

    try {
        cubeDesc.init(config, getMetadataManager().getAllTablesMap());
    } catch (IllegalStateException e) {
        cubeDesc.addError(e.getMessage(), true);
    }
    // Check base validation
    if (!cubeDesc.getError().isEmpty()) {
        return cubeDesc;
    }
    // Semantic validation
    CubeMetadataValidator validator = new CubeMetadataValidator();
    ValidateContext context = validator.validate(cubeDesc, true);
    if (!context.ifPass()) {
        return cubeDesc;
    }

    cubeDesc.setSignature(cubeDesc.calculateSignature());

    String path = cubeDesc.getResourcePath();
    getStore().putResource(path, cubeDesc, CUBE_DESC_SERIALIZER);
    cubeDescMap.put(cubeDesc.getName(), cubeDesc);

    return cubeDesc;
}
 
Example #16
Source File: StreamingCubeRule.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(CubeDesc cube, ValidateContext context) {
    DataModelDesc model = cube.getModel();
    
    if (model.getRootFactTable().getTableDesc().getSourceType() != ISourceAware.ID_STREAMING
            && !model.getRootFactTable().getTableDesc().isStreamingTable()) {
        return;
    }

    if (model.getPartitionDesc() == null || model.getPartitionDesc().getPartitionDateColumn() == null) {
        context.addResult(ResultLevel.ERROR, "Must define a partition column.");
        return;
    }

    final TblColRef partitionCol = model.getPartitionDesc().getPartitionDateColumnRef();
    boolean found = false;
    for (DimensionDesc dimensionDesc : cube.getDimensions()) {
        for (TblColRef dimCol : dimensionDesc.getColumnRefs()) {
            if (dimCol.equals(partitionCol)) {
                found = true;
                break;
            }
        }
    }

    if (found == false) {
        context.addResult(ResultLevel.ERROR, "Partition column '" + partitionCol + "' isn't in dimension list.");
        return;
    }

}
 
Example #17
Source File: AggregationGroupRuleTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGoodDesc2() throws IOException {

    ValidateContext vContext = new ValidateContext();
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/test_kylin_cube_with_slr_desc.json"), CubeDesc.class);
    desc.getAggregationGroups().get(0).getSelectRule().jointDims = new String[][] { //
            new String[] { "lstg_format_name", "lstg_site_id", "slr_segment_cd", "CATEG_LVL2_NAME" } };

    IValidatorRule<CubeDesc> rule = getAggregationGroupRule();
    rule.validate(desc, vContext);
    //vContext.print(System.out);
    assertEquals(1, vContext.getResults().length);
}
 
Example #18
Source File: FunctionRule.java    From Kylin with Apache License 2.0 5 votes vote down vote up
/**
 * @param context
 * @param cube
 * @param value
 */
private void validateColumnParameter(ValidateContext context, CubeDesc cube, String value) {
    String factTable = cube.getFactTable();
    if (StringUtils.isEmpty(factTable)) {
        context.addResult(ResultLevel.ERROR, "Fact table can not be null.");
        return;
    }
    TableDesc table = MetadataManager.getInstance(cube.getConfig()).getTableDesc(factTable);
    if (table == null) {
        context.addResult(ResultLevel.ERROR, "Fact table can not be found: " + cube);
        return;
    }
    // Prepare column set
    Set<String> set = new HashSet<String>();
    ColumnDesc[] cdesc = table.getColumns();
    for (int i = 0; i < cdesc.length; i++) {
        ColumnDesc columnDesc = cdesc[i];
        set.add(columnDesc.getName());
    }

    String[] items = value.split(",");
    for (int i = 0; i < items.length; i++) {
        String item = items[i].trim();
        if (StringUtils.isEmpty(item)) {
            continue;
        }
        if (!set.contains(item)) {
            context.addResult(ResultLevel.ERROR, "Column [" + item + "] does not exist in factable table" + factTable);
        }
    }

}
 
Example #19
Source File: AggregationGroupRuleTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadDesc1() throws IOException {

    ValidateContext vContext = new ValidateContext();
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/test_kylin_cube_with_slr_desc.json"), CubeDesc.class);
    String[] temp = Arrays.asList(desc.getAggregationGroups().get(0).getIncludes()).subList(0, 3).toArray(new String[3]);

    desc.getAggregationGroups().get(0).setIncludes(temp);
    IValidatorRule<CubeDesc> rule = getAggregationGroupRule();
    rule.validate(desc, vContext);
    //vContext.print(System.out);
    assertEquals(1, vContext.getResults().length);
    assertEquals("Aggregation group 1 'includes' dimensions not include all the dimensions:[seller_id, META_CATEG_NAME, lstg_format_name, lstg_site_id, slr_segment_cd]", (vContext.getResults()[0].getMessage()));
}
 
Example #20
Source File: AggregationGroupRuleTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadDesc2() throws IOException {

    ValidateContext vContext = new ValidateContext();
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/test_kylin_cube_with_slr_desc.json"), CubeDesc.class);
    desc.getAggregationGroups().get(0).getSelectRule().jointDims = new String[][] { //
            new String[] { "lstg_format_name", "lstg_site_id", "slr_segment_cd", "META_CATEG_NAME", "CATEG_LVL2_NAME" } };

    IValidatorRule<CubeDesc> rule = getAggregationGroupRule();
    rule.validate(desc, vContext);
    //vContext.print(System.out);
    assertEquals(2, vContext.getResults().length);
    assertEquals("Aggregation group 1 joint dimensions has overlap with more than 1 dimensions in same hierarchy: [CATEG_LVL2_NAME, META_CATEG_NAME]", (vContext.getResults()[0].getMessage()));
}
 
Example #21
Source File: FunctionRule.java    From Kylin with Apache License 2.0 5 votes vote down vote up
/**
 * @param context
 * @param cube
 * @param value
 */
private void validateCostantParameter(ValidateContext context, CubeDesc cube, String value) {
    try {
        Integer.parseInt(value);
    } catch (Exception e) {
        context.addResult(ResultLevel.ERROR, "Parameter value must be number, but it is " + value);
    }
}
 
Example #22
Source File: MandatoryColumnRule.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(CubeDesc cube, ValidateContext context) {
    Set<String> mands = new HashSet<String>();
    RowKeyColDesc[] cols = cube.getRowkey().getRowKeyColumns();
    if (cols == null || cols.length == 0) {
        return;
    }
    for (int i = 0; i < cols.length; i++) {
        RowKeyColDesc rowKeyColDesc = cols[i];
        if (rowKeyColDesc.isMandatory()) {
            mands.add(rowKeyColDesc.getColumn());
        }
    }
    if (mands.isEmpty()) {
        return;
    }
    String[][] groups = cube.getRowkey().getAggregationGroups();
    for (int i = 0; i < groups.length; i++) {
        String[] group = groups[i];
        for (int j = 0; j < group.length; j++) {
            String col = group[j];
            if (mands.contains(col)) {
                context.addResult(ResultLevel.ERROR, "mandatory column " + col + " must not be in aggregation group [" + ArrayUtils.toString(group) + "]");
            }
        }
    }

}
 
Example #23
Source File: FunctionRuleTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: RowKeyAttrRule.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(CubeDesc cube, ValidateContext context) {
    RowKeyDesc row = cube.getRowkey();
    if (row == null) {
        context.addResult(ResultLevel.ERROR, "Rowkey does not exist");
        return;
    }

    RowKeyColDesc[] rcd = row.getRowKeyColumns();
    if (rcd == null) {
        context.addResult(ResultLevel.ERROR, "Rowkey columns do not exist");
        return;
    }
    if(rcd.length == 0){
        context.addResult(ResultLevel.ERROR, "Rowkey columns is empty");
        return;       	
    }

    for (int i = 0; i < rcd.length; i++) {
        RowKeyColDesc rd = rcd[i];
        if (rd.getLength() != 0 && (!StringUtils.isEmpty(rd.getDictionary())&&!rd.getDictionary().equals("false"))) {
            context.addResult(ResultLevel.ERROR, "Rowkey column " + rd.getColumn() + " must not have both 'length' and 'dictionary' attribute");
        }
        if (rd.getLength() == 0 && (StringUtils.isEmpty(rd.getDictionary())||rd.getDictionary().equals("false"))) {
            context.addResult(ResultLevel.ERROR, "Rowkey column " + rd.getColumn() + " must not have both 'length' and 'dictionary' empty");
        }
    }

}
 
Example #25
Source File: CuboidSchedulerTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testTooLargeCube() {
    CubeDesc cubeDesc = getFiftyDimFiveCapCubeDesc();
    AggregationGroupRule rule = new AggregationGroupRule();
    ValidateContext context = new ValidateContext();
    rule.validate(cubeDesc, context);
    assertFalse(context.ifPass());
    assertEquals(1, context.getResults().length);

    try {
        cubeDesc.getInitialCuboidScheduler();
        Assert.fail();
    } catch (RuntimeException e) {
    }
}
 
Example #26
Source File: RowKeyAttrRuleTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGoodDesc() throws IOException {
    for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/").listFiles()) {
        CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class);
        ValidateContext vContext = new ValidateContext();
        IValidatorRule<CubeDesc> rule = new RowKeyAttrRule();
        rule.validate(desc, vContext);
        vContext.print(System.out);
        assertTrue(vContext.getResults().length == 0);
    }
}
 
Example #27
Source File: RowKeyAttrRuleTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadDesc() throws IOException {
    ValidateContext vContext = new ValidateContext();
    CubeDesc desc = JsonUtil.readValue(new FileInputStream(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/test_kylin_cube_with_slr_desc.json"), CubeDesc.class);
    desc.getRowkey().getRowKeyColumns()[2].setColumn("");
    IValidatorRule<CubeDesc> rule = new RowKeyAttrRule();
    rule.validate(desc, vContext);
    vContext.print(System.out);
    assertTrue(vContext.getResults().length == 1);
    assertTrue("Rowkey column empty".equalsIgnoreCase(vContext.getResults()[0].getMessage()));
}
 
Example #28
Source File: AggregationGroupSizeRule.java    From Kylin with Apache License 2.0 5 votes vote down vote up
/**
 * @param cube
 * @param context
 */
private void innerValidateMaxSize(CubeDesc cube, ValidateContext context) {
    int maxSize = getMaxAgrGroupSize();
    String[][] groups = cube.getRowkey().getAggregationGroups();
    for (int i = 0; i < groups.length; i++) {
        String[] group = groups[i];
        if (group.length >= maxSize) {
            context.addResult(ResultLevel.ERROR, "Length of the number " + i + " aggregation group's length should be less than " + maxSize);
        }
    }
}
 
Example #29
Source File: FunctionRule.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * @param context
 * @param cube
 * @param value
 */
private void validateColumnParameter(ValidateContext context, CubeDesc cube, String value) {
    DataModelDesc model = cube.getModel();
    try {
        model.findColumn(value);
    } catch (IllegalArgumentException e) {
        context.addResult(ResultLevel.ERROR, e.getMessage());
    }
}
 
Example #30
Source File: FunctionRule.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * @param context
 * @param cube
 * @param value
 */
private void validateCostantParameter(ValidateContext context, CubeDesc cube, String value) {
    try {
        Integer.parseInt(value);
    } catch (Exception e) {
        context.addResult(ResultLevel.ERROR, "Parameter value must be number, but it is " + value);
    }
}