Java Code Examples for org.apache.kylin.cube.CubeInstance#getCuboidScheduler()
The following examples show how to use
org.apache.kylin.cube.CubeInstance#getCuboidScheduler() .
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: CubeController.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/{cubeName}/cuboids/current", method = RequestMethod.GET) @ResponseBody public CuboidTreeResponse getCurrentCuboids(@PathVariable String cubeName) { checkCubeExists(cubeName); CubeInstance cube = cubeService.getCubeManager().getCube(cubeName); // The cuboid tree displayed should be consistent with the current one CuboidScheduler cuboidScheduler = cube.getCuboidScheduler(); Map<Long, Long> cuboidStatsMap = cube.getCuboids(); if (cuboidStatsMap == null) { cuboidStatsMap = CuboidStatsReaderUtil.readCuboidStatsFromCube(cuboidScheduler.getAllCuboidIds(), cube); } Map<Long, Long> hitFrequencyMap = null; Map<Long, Long> queryMatchMap = null; try { hitFrequencyMap = getTargetCuboidHitFrequency(cubeName); queryMatchMap = cubeService.getCuboidQueryMatchCount(cubeName); } catch (Exception e) { logger.warn("Fail to query on system cube due to " + e); } Set<Long> currentCuboidSet = cube.getCuboidScheduler().getAllCuboidIds(); return cubeService.getCuboidTreeResponse(cuboidScheduler, cuboidStatsMap, hitFrequencyMap, queryMatchMap, currentCuboidSet); }
Example 2
Source File: CubeController.java From kylin with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/{cubeName}/cuboids/current", method = RequestMethod.GET) @ResponseBody public CuboidTreeResponse getCurrentCuboids(@PathVariable String cubeName) { checkCubeExists(cubeName); CubeInstance cube = cubeService.getCubeManager().getCube(cubeName); // The cuboid tree displayed should be consistent with the current one CuboidScheduler cuboidScheduler = cube.getCuboidScheduler(); Map<Long, Long> cuboidStatsMap = cube.getCuboids(); if (cuboidStatsMap == null) { cuboidStatsMap = CuboidStatsReaderUtil.readCuboidStatsFromCube(cuboidScheduler.getAllCuboidIds(), cube); } Map<Long, Long> hitFrequencyMap = null; Map<Long, Long> queryMatchMap = null; try { hitFrequencyMap = getTargetCuboidHitFrequency(cubeName); queryMatchMap = cubeService.getCuboidQueryMatchCount(cubeName); } catch (Exception e) { logger.warn("Fail to query on system cube due to " + e); } Set<Long> currentCuboidSet = cube.getCuboidScheduler().getAllCuboidIds(); return cubeService.getCuboidTreeResponse(cuboidScheduler, cuboidStatsMap, hitFrequencyMap, queryMatchMap, currentCuboidSet); }
Example 3
Source File: BuildCubeWithEngine.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
private Set<Long> mockRecommendCuboids(CubeInstance cubeInstance, double maxRatio, int maxNumber) { Preconditions.checkArgument(maxRatio > 0.0 && maxRatio < 1.0); Preconditions.checkArgument(maxNumber > 0); Set<Long> cuboidsRecommend; Random rnd = new Random(); // add some mandatory cuboids which are for other unit test // - org.apache.kylin.query.ITCombinationTest.testLimitEnabled // - org.apache.kylin.query.ITFailfastQueryTest.testPartitionNotExceedMaxScanBytes // - org.apache.kylin.query.ITFailfastQueryTest.testQueryNotExceedMaxScanBytes List<Set<String>> mandatoryDimensionSetList = Lists.newLinkedList(); mandatoryDimensionSetList.add(Sets.newHashSet("CAL_DT")); mandatoryDimensionSetList.add(Sets.newHashSet("seller_id", "CAL_DT")); mandatoryDimensionSetList.add(Sets.newHashSet("LSTG_FORMAT_NAME", "slr_segment_cd")); Set<Long> mandatoryCuboids = cubeInstance.getDescriptor().generateMandatoryCuboids(mandatoryDimensionSetList); CuboidScheduler cuboidScheduler = cubeInstance.getCuboidScheduler(); Set<Long> cuboidsCurrent = cuboidScheduler.getAllCuboidIds(); long baseCuboid = cuboidScheduler.getBaseCuboidId(); do { cuboidsRecommend = Sets.newHashSet(); cuboidsRecommend.add(baseCuboid); cuboidsRecommend.addAll(mandatoryCuboids); for (long i = 1; i < baseCuboid; i++) { if (rnd.nextDouble() < maxRatio) { // add 5% cuboids cuboidsRecommend.add(i); } if (cuboidsRecommend.size() > maxNumber) { break; } } } while (cuboidsRecommend.equals(cuboidsCurrent)); return cuboidsRecommend; }
Example 4
Source File: CuboidRecommenderUtil.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
/** Trigger cube planner phase two for optimization */ public static Map<Long, Long> getRecommendCuboidList(CubeInstance cube, Map<Long, Long> hitFrequencyMap, Map<Long, Map<Long, Pair<Long, Long>>> rollingUpCountSourceMap) throws IOException { CuboidScheduler cuboidScheduler = cube.getCuboidScheduler(); Set<Long> currentCuboids = cuboidScheduler.getAllCuboidIds(); Pair<Map<Long, Long>, Map<Long, Double>> statsPair = CuboidStatsReaderUtil .readCuboidStatsAndSizeFromCube(currentCuboids, cube); long baseCuboid = cuboidScheduler.getBaseCuboidId(); if (statsPair.getFirst().get(baseCuboid) == null || statsPair.getFirst().get(baseCuboid) == 0L) { logger.info(BASE_CUBOID_COUNT_IN_CUBOID_STATISTICS_IS_ZERO); return null; } KylinConfig config = cube.getConfig(); String key = cube.getName(); double queryUncertaintyRatio = config.getCubePlannerQueryUncertaintyRatio(); double bpusMinBenefitRatio = config.getCubePlannerBPUSMinBenefitRatio(); CuboidStats cuboidStats = new CuboidStats.Builder(key, baseCuboid, statsPair.getFirst(), statsPair.getSecond()) { @Override public Map<Long, Double> estimateCuboidsSize(Map<Long, Long> statistics) { try { return CuboidStatsReaderUtil.readCuboidSizeFromCube(statistics, cube); } catch (IOException e) { logger.warn("Fail to get cuboid size from cube due to ", e); return null; } } }.setQueryUncertaintyRatio(queryUncertaintyRatio) // .setBPUSMinBenefitRatio(bpusMinBenefitRatio) // .setHitFrequencyMap(hitFrequencyMap) // .setRollingUpCountSourceMap(rollingUpCountSourceMap) // .build(); return CuboidRecommender.getInstance().getRecommendCuboidList(cuboidStats, config); }
Example 5
Source File: CubingJob.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
public List<Double> findEstimateRatio(CubeSegment seg, KylinConfig config) { CubeInstance cubeInstance = seg.getCubeInstance(); CuboidScheduler cuboidScheduler = cubeInstance.getCuboidScheduler(); List<List<Long>> layeredCuboids = cuboidScheduler.getCuboidsByLayer(); int totalLevels = cuboidScheduler.getBuildLevel(); List<Double> result = Lists.newArrayList(); Map<Long, Double> estimatedSizeMap; String cuboidRootPath = getCuboidRootPath(seg, config); try { estimatedSizeMap = new CubeStatsReader(seg, config).getCuboidSizeMap(true); } catch (IOException e) { logger.warn("Cannot get segment {} estimated size map", seg.getName()); return null; } for (int level = 0; level <= totalLevels; level++) { double levelEstimatedSize = 0; for (Long cuboidId : layeredCuboids.get(level)) { levelEstimatedSize += estimatedSizeMap.get(cuboidId) == null ? 0.0 : estimatedSizeMap.get(cuboidId); } double levelRealSize = getRealSizeByLevel(cuboidRootPath, level); if (levelEstimatedSize == 0.0 || levelRealSize == 0.0){ result.add(level, -1.0); } else { result.add(level, levelRealSize / levelEstimatedSize); } } return result; }
Example 6
Source File: BuildCubeWithEngine.java From kylin with Apache License 2.0 | 5 votes |
private Set<Long> mockRecommendCuboids(CubeInstance cubeInstance, double maxRatio, int maxNumber) { Preconditions.checkArgument(maxRatio > 0.0 && maxRatio < 1.0); Preconditions.checkArgument(maxNumber > 0); Set<Long> cuboidsRecommend; Random rnd = new Random(); // add some mandatory cuboids which are for other unit test // - org.apache.kylin.query.ITCombinationTest.testLimitEnabled // - org.apache.kylin.query.ITFailfastQueryTest.testPartitionNotExceedMaxScanBytes // - org.apache.kylin.query.ITFailfastQueryTest.testQueryNotExceedMaxScanBytes List<Set<String>> mandatoryDimensionSetList = Lists.newLinkedList(); mandatoryDimensionSetList.add(Sets.newHashSet("CAL_DT")); mandatoryDimensionSetList.add(Sets.newHashSet("seller_id", "CAL_DT")); mandatoryDimensionSetList.add(Sets.newHashSet("LSTG_FORMAT_NAME", "slr_segment_cd")); Set<Long> mandatoryCuboids = cubeInstance.getDescriptor().generateMandatoryCuboids(mandatoryDimensionSetList); CuboidScheduler cuboidScheduler = cubeInstance.getCuboidScheduler(); Set<Long> cuboidsCurrent = cuboidScheduler.getAllCuboidIds(); long baseCuboid = cuboidScheduler.getBaseCuboidId(); do { cuboidsRecommend = Sets.newHashSet(); cuboidsRecommend.add(baseCuboid); cuboidsRecommend.addAll(mandatoryCuboids); for (long i = 1; i < baseCuboid; i++) { if (rnd.nextDouble() < maxRatio) { // add 5% cuboids cuboidsRecommend.add(i); } if (cuboidsRecommend.size() > maxNumber) { break; } } } while (cuboidsRecommend.equals(cuboidsCurrent)); return cuboidsRecommend; }
Example 7
Source File: CuboidRecommenderUtil.java From kylin with Apache License 2.0 | 5 votes |
/** Trigger cube planner phase two for optimization */ public static Map<Long, Long> getRecommendCuboidList(CubeInstance cube, Map<Long, Long> hitFrequencyMap, Map<Long, Map<Long, Pair<Long, Long>>> rollingUpCountSourceMap) throws IOException { CuboidScheduler cuboidScheduler = cube.getCuboidScheduler(); Set<Long> currentCuboids = cuboidScheduler.getAllCuboidIds(); Pair<Map<Long, Long>, Map<Long, Double>> statsPair = CuboidStatsReaderUtil .readCuboidStatsAndSizeFromCube(currentCuboids, cube); long baseCuboid = cuboidScheduler.getBaseCuboidId(); if (statsPair.getFirst().get(baseCuboid) == null || statsPair.getFirst().get(baseCuboid) == 0L) { logger.info(BASE_CUBOID_COUNT_IN_CUBOID_STATISTICS_IS_ZERO); return null; } KylinConfig config = cube.getConfig(); String key = cube.getName(); double queryUncertaintyRatio = config.getCubePlannerQueryUncertaintyRatio(); double bpusMinBenefitRatio = config.getCubePlannerBPUSMinBenefitRatio(); CuboidStats cuboidStats = new CuboidStats.Builder(key, baseCuboid, statsPair.getFirst(), statsPair.getSecond()) { @Override public Map<Long, Double> estimateCuboidsSize(Map<Long, Long> statistics) { try { return CuboidStatsReaderUtil.readCuboidSizeFromCube(statistics, cube); } catch (IOException e) { logger.warn("Fail to get cuboid size from cube due to ", e); return null; } } }.setQueryUncertaintyRatio(queryUncertaintyRatio) // .setBPUSMinBenefitRatio(bpusMinBenefitRatio) // .setHitFrequencyMap(hitFrequencyMap) // .setRollingUpCountSourceMap(rollingUpCountSourceMap) // .build(); return CuboidRecommender.getInstance().getRecommendCuboidList(cuboidStats, config); }
Example 8
Source File: CubingJob.java From kylin with Apache License 2.0 | 5 votes |
public List<Double> findEstimateRatio(CubeSegment seg, KylinConfig config) { CubeInstance cubeInstance = seg.getCubeInstance(); CuboidScheduler cuboidScheduler = cubeInstance.getCuboidScheduler(); List<List<Long>> layeredCuboids = cuboidScheduler.getCuboidsByLayer(); int totalLevels = cuboidScheduler.getBuildLevel(); List<Double> result = Lists.newArrayList(); Map<Long, Double> estimatedSizeMap; String cuboidRootPath = getCuboidRootPath(seg, config); try { estimatedSizeMap = new CubeStatsReader(seg, config).getCuboidSizeMap(true); } catch (IOException e) { logger.warn("Cannot get segment {} estimated size map", seg.getName()); return null; } for (int level = 0; level <= totalLevels; level++) { double levelEstimatedSize = 0; for (Long cuboidId : layeredCuboids.get(level)) { levelEstimatedSize += estimatedSizeMap.get(cuboidId) == null ? 0.0 : estimatedSizeMap.get(cuboidId); } double levelRealSize = getRealSizeByLevel(cuboidRootPath, level); if (levelEstimatedSize == 0.0 || levelRealSize == 0.0){ result.add(level, -1.0); } else { result.add(level, levelRealSize / levelEstimatedSize); } } return result; }