org.apache.kylin.metadata.project.RealizationEntry Java Examples

The following examples show how to use org.apache.kylin.metadata.project.RealizationEntry. 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: CubeService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
protected boolean isCubeInProject(String projectName, CubeInstance target) {
    ProjectManager projectManager = getProjectManager();
    ProjectInstance project = projectManager.getProject(projectName);
    if (project == null) {
        return false;
    }
    for (RealizationEntry projectDataModel : project.getRealizationEntries()) {
        if (projectDataModel.getType() == RealizationType.CUBE) {
            CubeInstance cube = getCubeManager().getCube(projectDataModel.getRealization());
            if (cube == null) {
                logger.error("Project " + projectName + " contains realization " + projectDataModel.getRealization()
                        + " which is not found by CubeManager");
                continue;
            }
            if (cube.equals(target)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #2
Source File: CubeService.java    From kylin with Apache License 2.0 6 votes vote down vote up
protected boolean isCubeInProject(String projectName, CubeInstance target) {
    ProjectManager projectManager = getProjectManager();
    ProjectInstance project = projectManager.getProject(projectName);
    if (project == null) {
        return false;
    }
    for (RealizationEntry projectDataModel : project.getRealizationEntries()) {
        if (projectDataModel.getType() == RealizationType.CUBE) {
            CubeInstance cube = getCubeManager().getCube(projectDataModel.getRealization());
            if (cube == null) {
                logger.error("Project " + projectName + " contains realization " + projectDataModel.getRealization()
                        + " which is not found by CubeManager");
                continue;
            }
            if (cube.equals(target)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #3
Source File: CubeService.java    From kylin with Apache License 2.0 6 votes vote down vote up
public List<CubeInstance> listAllCubes(String projectName) {
    ProjectManager projectManager = getProjectManager();
    ProjectInstance project = projectManager.getProject(projectName);
    if (project == null) {
        return Collections.emptyList();
    }
    ArrayList<CubeInstance> result = new ArrayList<CubeInstance>();
    for (RealizationEntry projectDataModel : project.getRealizationEntries()) {
        if (projectDataModel.getType() == RealizationType.CUBE) {
            CubeInstance cube = getCubeManager().getCube(projectDataModel.getRealization());
            if (cube != null)
                result.add(cube);
            else
                logger.error("Cube instance " + projectDataModel.getRealization() + " is failed to load");
        }
    }
    return result;
}
 
Example #4
Source File: HybridCubeCLI.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void checkSegmentOffset(List<RealizationEntry> realizationEntries) {
    List<SegmentRange> segmentRanges = Lists.newArrayList();

    for (RealizationEntry entry : realizationEntries) {
        if (entry.getType() != RealizationType.CUBE) {
            throw new IllegalArgumentException("Wrong realization type: " + entry.getType() + ", only cube supported. ");
        }

        CubeInstance cubeInstance = cubeManager.getCube(entry.getRealization());
        Segments<CubeSegment> segments = cubeInstance.getSegments();

        for (CubeSegment segment : segments) {
            segmentRanges.add(segment.getSegRange());
        }
    }

    if (segmentRanges.size() >= 2) {
        Collections.sort(segmentRanges);

        for (int i = 0; i < segmentRanges.size() - 1; i++) {
            if (segmentRanges.get(i).overlaps(segmentRanges.get(i + 1))) {
                throw new IllegalArgumentException("Segments has overlap, could not hybrid. First Segment Range: [" + segmentRanges.get(i).start.v + "," + segmentRanges.get(i).end.v + "], Second Segment Range: [" + segmentRanges.get(i + 1).start.v + "," + segmentRanges.get(i + 1).end.v + "]");
            }
        }
    }
}
 
Example #5
Source File: CubeService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public List<CubeInstance> listAllCubes(String projectName) {
    ProjectManager projectManager = getProjectManager();
    ProjectInstance project = projectManager.getProject(projectName);
    if (project == null) {
        return Collections.emptyList();
    }
    ArrayList<CubeInstance> result = new ArrayList<CubeInstance>();
    for (RealizationEntry projectDataModel : project.getRealizationEntries()) {
        if (projectDataModel.getType() == RealizationType.CUBE) {
            CubeInstance cube = getCubeManager().getCube(projectDataModel.getRealization());
            if (cube != null)
                result.add(cube);
            else
                logger.error("Cube instance " + projectDataModel.getRealization() + " is failed to load");
        }
    }
    return result;
}
 
Example #6
Source File: HybridCubeCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void checkSegmentOffset(List<RealizationEntry> realizationEntries) {
    List<SegmentRange> segmentRanges = Lists.newArrayList();

    for (RealizationEntry entry : realizationEntries) {
        if (entry.getType() != RealizationType.CUBE) {
            throw new IllegalArgumentException("Wrong realization type: " + entry.getType() + ", only cube supported. ");
        }

        CubeInstance cubeInstance = cubeManager.getCube(entry.getRealization());
        Segments<CubeSegment> segments = cubeInstance.getSegments();

        for (CubeSegment segment : segments) {
            segmentRanges.add(segment.getSegRange());
        }
    }

    if (segmentRanges.size() >= 2) {
        Collections.sort(segmentRanges);

        for (int i = 0; i < segmentRanges.size() - 1; i++) {
            if (segmentRanges.get(i).overlaps(segmentRanges.get(i + 1))) {
                throw new IllegalArgumentException("Segments has overlap, could not hybrid. First Segment Range: [" + segmentRanges.get(i).start.v + "," + segmentRanges.get(i).end.v + "], Second Segment Range: [" + segmentRanges.get(i + 1).start.v + "," + segmentRanges.get(i + 1).end.v + "]");
            }
        }
    }
}
 
Example #7
Source File: DeployCoprocessorCLI.java    From kylin with Apache License 2.0 6 votes vote down vote up
private static List<String> filterByProjects(List<String> allTableNames, List<String> projectNames) {
    ProjectManager projectManager = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv());
    CubeManager cubeManager = CubeManager.getInstance(KylinConfig.getInstanceFromEnv());

    List<String> result = Lists.newArrayList();
    for (String p : projectNames) {
        p = p.trim();
        if (p.endsWith(",")) {
            p = p.substring(0, p.length() - 1);
        }

        ProjectInstance projectInstance = projectManager.getProject(p);
        List<RealizationEntry> cubeList = projectInstance.getRealizationEntries(RealizationType.CUBE);
        for (RealizationEntry cube : cubeList) {
            CubeInstance cubeInstance = cubeManager.getCube(cube.getRealization());
            for (CubeSegment segment : cubeInstance.getSegments()) {
                String tableName = segment.getStorageLocationIdentifier();
                if (allTableNames.contains(tableName)) {
                    result.add(tableName);
                }
            }
        }
    }
    return result;
}
 
Example #8
Source File: HybridManager.java    From kylin with Apache License 2.0 6 votes vote down vote up
public List<HybridInstance> getHybridInstancesByChild(RealizationType type, String realizationName) {
    try (AutoLock l = lock.lockForRead()) {
        List<HybridInstance> result = Lists.newArrayList();
        for (HybridInstance hybridInstance : hybridMap.values()) {
            for (RealizationEntry realizationEntry : hybridInstance.getRealizationEntries()) {
                if (realizationEntry.getType() == type
                        && realizationEntry.getRealization().equalsIgnoreCase(realizationName)) {
                    result.add(hybridInstance);
                }
            }

        }

        return result;
    }
}
 
Example #9
Source File: HybridManager.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public List<HybridInstance> getHybridInstancesByChild(RealizationType type, String realizationName) {
    try (AutoLock l = lock.lockForRead()) {
        List<HybridInstance> result = Lists.newArrayList();
        for (HybridInstance hybridInstance : hybridMap.values()) {
            for (RealizationEntry realizationEntry : hybridInstance.getRealizationEntries()) {
                if (realizationEntry.getType() == type
                        && realizationEntry.getRealization().equalsIgnoreCase(realizationName)) {
                    result.add(hybridInstance);
                }
            }

        }

        return result;
    }
}
 
Example #10
Source File: DeployCoprocessorCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private static List<String> filterByProjects(List<String> allTableNames, List<String> projectNames) {
    ProjectManager projectManager = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv());
    CubeManager cubeManager = CubeManager.getInstance(KylinConfig.getInstanceFromEnv());

    List<String> result = Lists.newArrayList();
    for (String p : projectNames) {
        p = p.trim();
        if (p.endsWith(",")) {
            p = p.substring(0, p.length() - 1);
        }

        ProjectInstance projectInstance = projectManager.getProject(p);
        List<RealizationEntry> cubeList = projectInstance.getRealizationEntries(RealizationType.CUBE);
        for (RealizationEntry cube : cubeList) {
            CubeInstance cubeInstance = cubeManager.getCube(cube.getRealization());
            for (CubeSegment segment : cubeInstance.getSegments()) {
                String tableName = segment.getStorageLocationIdentifier();
                if (allTableNames.contains(tableName)) {
                    result.add(tableName);
                }
            }
        }
    }
    return result;
}
 
Example #11
Source File: DashboardService.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private List<CubeInstance> getCubeByHybrid(HybridInstance hybridInstance) {
    List<CubeInstance> cubeInstances = Lists.newArrayList();
    List<RealizationEntry> realizationEntries = hybridInstance.getRealizationEntries();
    for (RealizationEntry realizationEntry : realizationEntries) {
        String reName = realizationEntry.getRealization();
        if (RealizationType.CUBE == realizationEntry.getType()) {
            CubeInstance cubeInstance = getCubeManager().getCube(reName);
            cubeInstances.add(cubeInstance);
        } else if (RealizationType.HYBRID == realizationEntry.getType()) {
            HybridInstance innerHybridInstance = getHybridManager().getHybridInstance(reName);
            cubeInstances.addAll(getCubeByHybrid(innerHybridInstance));
        }
    }
    return cubeInstances;
}
 
Example #12
Source File: HBaseUsageExtractor.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeExtract(OptionsHelper optionsHelper, File exportDir) throws Exception {
    if (cachedHMasterUrl == null) {
        return;
    }
    kylinConfig = KylinConfig.getInstanceFromEnv();
    cubeManager = CubeManager.getInstance(kylinConfig);
    realizationRegistry = RealizationRegistry.getInstance(kylinConfig);
    projectManager = ProjectManager.getInstance(kylinConfig);

    if (optionsHelper.hasOption(OPTION_PROJECT)) {
        String projectNames = optionsHelper.getOptionValue(OPTION_PROJECT);
        for (String projectName : StringUtil.splitByComma(projectNames)) {
            ProjectInstance projectInstance = projectManager.getProject(projectName);
            if (projectInstance == null) {
                throw new IllegalArgumentException("Project " + projectName + " does not exist");
            }
            List<RealizationEntry> realizationEntries = projectInstance.getRealizationEntries();
            for (RealizationEntry realizationEntry : realizationEntries) {
                retrieveResourcePath(getRealization(realizationEntry));
            }
        }
    } else if (optionsHelper.hasOption(OPTION_CUBE)) {
        String cubeNames = optionsHelper.getOptionValue(OPTION_CUBE);
        for (String cubeName : StringUtil.splitByComma(cubeNames)) {
            IRealization realization = cubeManager.getRealization(cubeName);
            if (realization != null) {
                retrieveResourcePath(realization);
            } else {
                throw new IllegalArgumentException("No cube found with name of " + cubeName);
            }
        }
    }

    extractCommonInfo(exportDir, kylinConfig);
    extractHTables(exportDir);
}
 
Example #13
Source File: HBaseUsageExtractor.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeExtract(OptionsHelper optionsHelper, File exportDir) throws Exception {
    if (cachedHMasterUrl == null) {
        return;
    }
    kylinConfig = KylinConfig.getInstanceFromEnv();
    cubeManager = CubeManager.getInstance(kylinConfig);
    realizationRegistry = RealizationRegistry.getInstance(kylinConfig);
    projectManager = ProjectManager.getInstance(kylinConfig);

    if (optionsHelper.hasOption(OPTION_PROJECT)) {
        String projectNames = optionsHelper.getOptionValue(OPTION_PROJECT);
        for (String projectName : StringUtil.splitByComma(projectNames)) {
            ProjectInstance projectInstance = projectManager.getProject(projectName);
            if (projectInstance == null) {
                throw new IllegalArgumentException("Project " + projectName + " does not exist");
            }
            List<RealizationEntry> realizationEntries = projectInstance.getRealizationEntries();
            for (RealizationEntry realizationEntry : realizationEntries) {
                retrieveResourcePath(getRealization(realizationEntry));
            }
        }
    } else if (optionsHelper.hasOption(OPTION_CUBE)) {
        String cubeNames = optionsHelper.getOptionValue(OPTION_CUBE);
        for (String cubeName : StringUtil.splitByComma(cubeNames)) {
            IRealization realization = cubeManager.getRealization(cubeName);
            if (realization != null) {
                retrieveResourcePath(realization);
            } else {
                throw new IllegalArgumentException("No cube found with name of " + cubeName);
            }
        }
    }

    extractCommonInfo(exportDir, kylinConfig);
    extractHTables(exportDir);
}
 
Example #14
Source File: CubeMetaExtractor.java    From kylin with Apache License 2.0 5 votes vote down vote up
private void requireProject(ProjectInstance projectInstance) throws IOException {
    addRequired(projectInstance.getResourcePath());
    List<RealizationEntry> realizationEntries = projectInstance.getRealizationEntries();
    for (RealizationEntry realizationEntry : realizationEntries) {
        retrieveResourcePath(getRealization(realizationEntry));
    }
    List<DataModelDesc> modelDescs = metadataManager.getModels(projectInstance.getName());
    for (DataModelDesc modelDesc : modelDescs) {
        addRequired(DataModelDesc.concatResourcePath(modelDesc.getName()));
    }
    addOptional(badQueryHistoryManager.getBadQueriesForProject(projectInstance.getName()).getResourcePath());
}
 
Example #15
Source File: CubeMetaIngesterTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testHappyIngest() {
    String srcPath = Thread.currentThread().getContextClassLoader().getResource("cloned_cube_and_model.zip").getPath();
    CubeMetaIngester.main(new String[] { "-project", "default", "-srcPath", srcPath });

    ProjectInstance project = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv()).getProject("default");
    Assert.assertEquals(1, Collections.frequency(project.getTables(), "DEFAULT.TEST_KYLIN_FACT"));
    Assert.assertTrue(project.getModels().contains("cloned_model"));
    Assert.assertTrue(project.getRealizationEntries().contains(RealizationEntry.create(RealizationType.CUBE, "cloned_cube")));

    getTestConfig().clearManagers();
    CubeInstance instance = CubeManager.getInstance(KylinConfig.getInstanceFromEnv()).getCube("cloned_cube");
    Assert.assertTrue(instance != null);
}
 
Example #16
Source File: CubeMetaIngesterTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testHappyIngest2() {
    String srcPath = Thread.currentThread().getContextClassLoader().getResource("benchmark_meta.zip").getPath();
    CubeMetaIngester.main(new String[] { "-project", "default", "-srcPath", srcPath, "-overwriteTables", "true" });

    ProjectInstance project = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv()).getProject("default");
    Assert.assertEquals(1, Collections.frequency(project.getTables(), "SSB.CUSTOMER"));
    Assert.assertTrue(project.getModels().contains("benchmark_model"));
    Assert.assertTrue(project.getRealizationEntries().contains(RealizationEntry.create(RealizationType.CUBE, "benchmark_cube")));

    getTestConfig().clearManagers();
    CubeInstance instance = CubeManager.getInstance(KylinConfig.getInstanceFromEnv()).getCube("benchmark_cube");
    Assert.assertTrue(instance != null);
}
 
Example #17
Source File: HybridInstance.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static HybridInstance create(KylinConfig config, String name, List<RealizationEntry> realizationEntries) {
    HybridInstance hybridInstance = new HybridInstance();

    hybridInstance.setConfig(config);
    hybridInstance.setName(name);
    hybridInstance.setRealizationEntries(realizationEntries);
    hybridInstance.updateRandomUuid();

    return hybridInstance;
}
 
Example #18
Source File: CubeManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * To keep "select * from LOOKUP_TABLE" has consistent and latest result, we manually choose
 * CubeInstance here to answer such query.
 */
public CubeInstance findLatestSnapshot(List<RealizationEntry> realizationEntries, String lookupTableName,
        CubeInstance cubeInstance) {
    CubeInstance cube = null;
    try {
        if (!realizationEntries.isEmpty()) {
            long maxBuildTime = Long.MIN_VALUE;
            RealizationRegistry registry = RealizationRegistry.getInstance(config);
            for (RealizationEntry entry : realizationEntries) {
                IRealization realization = registry.getRealization(entry.getType(), entry.getRealization());
                if (realization != null && realization.isReady() && realization instanceof CubeInstance) {
                    CubeInstance current = (CubeInstance) realization;
                    if (current.getDescriptor().findDimensionByTable(lookupTableName) != null) {
                        CubeSegment segment = current.getLatestReadySegment();
                        if (segment != null) {
                            long latestBuildTime = segment.getLastBuildTime();
                            if (latestBuildTime > maxBuildTime) {
                                maxBuildTime = latestBuildTime;
                                cube = current;
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.info("Unexpected error.", e);
        throw e;
    }
    if (!cubeInstance.equals(cube)) {
        logger.debug("Picked cube {} over {} as it provides a more recent snapshot of the lookup table {}", cube,
                cubeInstance, lookupTableName);
    }
    return cube == null ? cubeInstance : cube;
}
 
Example #19
Source File: HybridCubeCLI.java    From kylin with Apache License 2.0 5 votes vote down vote up
private HybridInstance create(String hybridName, List<RealizationEntry> realizationEntries, String projectName, String owner) throws IOException {
    checkSegmentOffset(realizationEntries);
    HybridInstance hybridInstance = HybridInstance.create(kylinConfig, hybridName, realizationEntries);
    store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
    ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
    hybridManager.reloadHybridInstance(hybridName);
    logger.info("HybridInstance was created at: " + hybridInstance.getResourcePath());
    return hybridInstance;
}
 
Example #20
Source File: HybridCubeCLI.java    From kylin with Apache License 2.0 5 votes vote down vote up
private void update(HybridInstance hybridInstance, List<RealizationEntry> realizationEntries, String projectName, String owner, boolean checkCubeSize) throws IOException {
    if (checkCubeSize)
        checkSegmentOffset(realizationEntries);
    hybridInstance.setRealizationEntries(realizationEntries);
    store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
    ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
    hybridManager.reloadHybridInstance(hybridInstance.getName());
    logger.info("HybridInstance was updated at: " + hybridInstance.getResourcePath());
}
 
Example #21
Source File: DashboardService.java    From kylin with Apache License 2.0 5 votes vote down vote up
private List<CubeInstance> getCubeByHybrid(HybridInstance hybridInstance) {
    List<CubeInstance> cubeInstances = Lists.newArrayList();
    List<RealizationEntry> realizationEntries = hybridInstance.getRealizationEntries();
    for (RealizationEntry realizationEntry : realizationEntries) {
        String reName = realizationEntry.getRealization();
        if (RealizationType.CUBE == realizationEntry.getType()) {
            CubeInstance cubeInstance = getCubeManager().getCube(reName);
            cubeInstances.add(cubeInstance);
        } else if (RealizationType.HYBRID == realizationEntry.getType()) {
            HybridInstance innerHybridInstance = getHybridManager().getHybridInstance(reName);
            cubeInstances.addAll(getCubeByHybrid(innerHybridInstance));
        }
    }
    return cubeInstances;
}
 
Example #22
Source File: RangerKylinAuthorizerTest.java    From ranger with Apache License 2.0 5 votes vote down vote up
/**
 * Help function: get specific project instance for test
 */
private static ProjectInstance getProjectInstance(String name) {
	String owner = null;
	String description = null;
	LinkedHashMap<String, String> overrideProps = null;
	List<RealizationEntry> realizationEntries = null;
	List<String> models = null;

	return ProjectInstance.create(name, owner, description, overrideProps, realizationEntries, models);
}
 
Example #23
Source File: HybridCubeCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void update(HybridInstance hybridInstance, List<RealizationEntry> realizationEntries, String projectName, String owner, boolean checkCubeSize) throws IOException {
    if (checkCubeSize)
        checkSegmentOffset(realizationEntries);
    hybridInstance.setRealizationEntries(realizationEntries);
    store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
    ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
    hybridManager.reloadHybridInstance(hybridInstance.getName());
    logger.info("HybridInstance was updated at: " + hybridInstance.getResourcePath());
}
 
Example #24
Source File: HybridCubeCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private HybridInstance create(String hybridName, List<RealizationEntry> realizationEntries, String projectName, String owner) throws IOException {
    checkSegmentOffset(realizationEntries);
    HybridInstance hybridInstance = HybridInstance.create(kylinConfig, hybridName, realizationEntries);
    store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
    ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
    hybridManager.reloadHybridInstance(hybridName);
    logger.info("HybridInstance was created at: " + hybridInstance.getResourcePath());
    return hybridInstance;
}
 
Example #25
Source File: CubeMetaExtractor.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void requireProject(ProjectInstance projectInstance) throws IOException {
    addRequired(projectInstance.getResourcePath());
    List<RealizationEntry> realizationEntries = projectInstance.getRealizationEntries();
    for (RealizationEntry realizationEntry : realizationEntries) {
        retrieveResourcePath(getRealization(realizationEntry));
    }
    List<DataModelDesc> modelDescs = metadataManager.getModels(projectInstance.getName());
    for (DataModelDesc modelDesc : modelDescs) {
        addRequired(DataModelDesc.concatResourcePath(modelDesc.getName()));
    }
    addOptional(badQueryHistoryManager.getBadQueriesForProject(projectInstance.getName()).getResourcePath());
}
 
Example #26
Source File: CubeManager.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * To keep "select * from LOOKUP_TABLE" has consistent and latest result, we manually choose
 * CubeInstance here to answer such query.
 */
public CubeInstance findLatestSnapshot(List<RealizationEntry> realizationEntries, String lookupTableName,
        CubeInstance cubeInstance) {
    CubeInstance cube = null;
    try {
        if (!realizationEntries.isEmpty()) {
            long maxBuildTime = Long.MIN_VALUE;
            RealizationRegistry registry = RealizationRegistry.getInstance(config);
            for (RealizationEntry entry : realizationEntries) {
                IRealization realization = registry.getRealization(entry.getType(), entry.getRealization());
                if (realization != null && realization.isReady() && realization instanceof CubeInstance) {
                    CubeInstance current = (CubeInstance) realization;
                    if (checkMeetSnapshotTable(current, lookupTableName)) {
                        CubeSegment segment = current.getLatestReadySegment();
                        if (segment != null) {
                            long latestBuildTime = segment.getLastBuildTime();
                            if (latestBuildTime > maxBuildTime) {
                                maxBuildTime = latestBuildTime;
                                cube = current;
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.info("Unexpected error.", e);
    }
    if (!cubeInstance.equals(cube)) {
        logger.debug("Picked cube {} over {} as it provides a more recent snapshot of the lookup table {}", cube,
                cubeInstance, lookupTableName);
    }
    return cube == null ? cubeInstance : cube;
}
 
Example #27
Source File: CubeMetaIngesterTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testHappyIngest() {
    String srcPath = Thread.currentThread().getContextClassLoader().getResource("cloned_cube_and_model.zip").getPath();
    CubeMetaIngester.main(new String[] { "-project", "default", "-srcPath", srcPath });

    ProjectInstance project = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv()).getProject("default");
    Assert.assertEquals(1, Collections.frequency(project.getTables(), "DEFAULT.TEST_KYLIN_FACT"));
    Assert.assertTrue(project.getModels().contains("cloned_model"));
    Assert.assertTrue(project.getRealizationEntries().contains(RealizationEntry.create(RealizationType.CUBE, "cloned_cube")));

    getTestConfig().clearManagers();
    CubeInstance instance = CubeManager.getInstance(KylinConfig.getInstanceFromEnv()).getCube("cloned_cube");
    Assert.assertTrue(instance != null);
}
 
Example #28
Source File: CubeMetaIngesterTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testHappyIngest2() {
    String srcPath = Thread.currentThread().getContextClassLoader().getResource("benchmark_meta.zip").getPath();
    CubeMetaIngester.main(new String[] { "-project", "default", "-srcPath", srcPath, "-overwriteTables", "true" });

    ProjectInstance project = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv()).getProject("default");
    Assert.assertEquals(1, Collections.frequency(project.getTables(), "SSB.CUSTOMER"));
    Assert.assertTrue(project.getModels().contains("benchmark_model"));
    Assert.assertTrue(project.getRealizationEntries().contains(RealizationEntry.create(RealizationType.CUBE, "benchmark_cube")));

    getTestConfig().clearManagers();
    CubeInstance instance = CubeManager.getInstance(KylinConfig.getInstanceFromEnv()).getCube("benchmark_cube");
    Assert.assertTrue(instance != null);
}
 
Example #29
Source File: HybridInstance.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static HybridInstance create(KylinConfig config, String name, List<RealizationEntry> realizationEntries) {
    HybridInstance hybridInstance = new HybridInstance();

    hybridInstance.setConfig(config);
    hybridInstance.setName(name);
    hybridInstance.setRealizationEntries(realizationEntries);
    hybridInstance.updateRandomUuid();

    return hybridInstance;
}
 
Example #30
Source File: HybridInstance.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public void setRealizationEntries(List<RealizationEntry> realizationEntries) {
    this.realizationEntries = realizationEntries;
}