Java Code Examples for org.apache.kylin.metadata.model.DataModelDesc#getMetrics()

The following examples show how to use org.apache.kylin.metadata.model.DataModelDesc#getMetrics() . 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: ModelServiceTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testRevisableModelInCaseOfDeleteMeasure() throws IOException {
    List<DataModelDesc> dataModelDescs = modelService.listAllModels("ci_left_join_model", "default", true);
    Assert.assertTrue(dataModelDescs.size() == 1);

    DataModelDesc revisableModel = dataModelDescs.get(0);

    String[] originM = revisableModel.getMetrics();
    String[] reviseM = cutItems(originM, 1);

    revisableModel.setMetrics(reviseM);

    expectedEx.expect(org.apache.kylin.rest.exception.BadRequestException.class);
    expectedEx.expectMessage(
            "Measure: TEST_KYLIN_FACT.ITEM_COUNT can't be removed, It is referred in Cubes: [ci_left_join_cube]");
    modelService.updateModelToResourceStore(revisableModel, "default");
}
 
Example 2
Source File: ModelServiceTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testRevisableModelInCaseOfMoveMeasureToDim() throws IOException {
    List<DataModelDesc> dataModelDescs = modelService.listAllModels("ci_left_join_model", "default", true);
    Assert.assertTrue(dataModelDescs.size() == 1);

    DataModelDesc revisableModel = dataModelDescs.get(0);

    String[] originM = revisableModel.getMetrics();
    String[] reviseM = cutItems(originM, 1);
    revisableModel.setMetrics(reviseM);

    String col = originM[originM.length - 1];
    col = col.substring(col.indexOf('.') + 1);

    List<ModelDimensionDesc> originDims = revisableModel.getDimensions();
    String[] reviseDims = addItems(originDims.get(0).getColumns(), col);
    originDims.get(0).setColumns(reviseDims);
    revisableModel.setDimensions(originDims);
    modelService.updateModelToResourceStore(revisableModel, "default");
    //It should pass without any exceptions.
}
 
Example 3
Source File: TableSchemaUpdateChecker.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private Set<ColumnDesc> findUsedColumnsInFactTable(DataModelDesc usedModel, TableDesc factTable) {
    Set<ColumnDesc> usedColumns = Sets.newHashSet();
    // column in dimension
    for (ModelDimensionDesc dim : usedModel.getDimensions()) {
        if (dim.getTable().equalsIgnoreCase(factTable.getName())) {
            for (String col : dim.getColumns()) {
                usedColumns.add(mustGetColumnDesc(factTable, col));
            }
        }
    }

    // column in measure
    for (String columnInMeasure : usedModel.getMetrics()) {
        if (factTable.getName().equalsIgnoreCase(getTableName(columnInMeasure))) {
            usedColumns.add(mustGetColumnDesc(factTable, columnInMeasure));
        }
    }

    return usedColumns;
}
 
Example 4
Source File: ModelServiceTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testRevisableModelInCaseOfDeleteMeasure() throws IOException {
    List<DataModelDesc> dataModelDescs = modelService.listAllModels("ci_left_join_model", "default", true);
    Assert.assertTrue(dataModelDescs.size() == 1);

    DataModelDesc revisableModel = dataModelDescs.get(0);

    String[] originM = revisableModel.getMetrics();
    String[] reviseM = cutItems(originM, 1);

    revisableModel.setMetrics(reviseM);

    expectedEx.expect(org.apache.kylin.rest.exception.BadRequestException.class);
    expectedEx.expectMessage(
            "Measure: TEST_KYLIN_FACT.ITEM_COUNT can't be removed, It is referred in Cubes: [ci_left_join_cube]");
    modelService.updateModelToResourceStore(revisableModel, "default");
}
 
Example 5
Source File: ModelServiceTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testRevisableModelInCaseOfMoveMeasureToDim() throws IOException {
    List<DataModelDesc> dataModelDescs = modelService.listAllModels("ci_left_join_model", "default", true);
    Assert.assertTrue(dataModelDescs.size() == 1);

    DataModelDesc revisableModel = dataModelDescs.get(0);

    String[] originM = revisableModel.getMetrics();
    String[] reviseM = cutItems(originM, 1);
    revisableModel.setMetrics(reviseM);

    String col = originM[originM.length - 1];
    col = col.substring(col.indexOf('.') + 1);

    List<ModelDimensionDesc> originDims = revisableModel.getDimensions();
    String[] reviseDims = addItems(originDims.get(0).getColumns(), col);
    originDims.get(0).setColumns(reviseDims);
    revisableModel.setDimensions(originDims);
    modelService.updateModelToResourceStore(revisableModel, "default");
    //It should pass without any exceptions.
}
 
Example 6
Source File: TableSchemaUpdateChecker.java    From kylin with Apache License 2.0 6 votes vote down vote up
private Set<ColumnDesc> findUsedColumnsInFactTable(DataModelDesc usedModel, TableDesc factTable) {
    Set<ColumnDesc> usedColumns = Sets.newHashSet();
    // column in dimension
    for (ModelDimensionDesc dim : usedModel.getDimensions()) {
        if (dim.getTable().equalsIgnoreCase(factTable.getName())) {
            for (String col : dim.getColumns()) {
                usedColumns.add(mustGetColumnDesc(factTable, col));
            }
        }
    }

    // column in measure
    for (String columnInMeasure : usedModel.getMetrics()) {
        if (factTable.getName().equalsIgnoreCase(getTableName(columnInMeasure))) {
            usedColumns.add(mustGetColumnDesc(factTable, columnInMeasure));
        }
    }

    return usedColumns;
}
 
Example 7
Source File: ModelService.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private List<String> getModelMeasures(DataModelDesc model) {
    List<String> measures = new ArrayList<String>();

    for (String s : model.getMetrics()) {
        measures.add(s);
    }
    return measures;
}
 
Example 8
Source File: ModelService.java    From kylin with Apache License 2.0 5 votes vote down vote up
private List<String> getModelMeasures(DataModelDesc model) {
    List<String> measures = new ArrayList<String>();

    for (String s : model.getMetrics()) {
        measures.add(s);
    }
    return measures;
}