weizhengte commented on code in PR #8862: URL: https://github.com/apache/doris/pull/8862#discussion_r935850716
########## fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsJobManager.java: ########## @@ -140,4 +150,84 @@ private void checkRestrict(long dbId, Set<Long> tableIds) throws AnalysisExcepti + Config.cbo_max_statistics_job_num); } } + + public List<List<String>> getAnalyzeJobInfos(ShowAnalyzeStmt showStmt) throws AnalysisException { + List<List<Comparable>> results = Lists.newArrayList(); + + String stateValue = showStmt.getStateValue(); + StatisticsJob.JobState jobState = null; + if (!Strings.isNullOrEmpty(stateValue)) { + jobState = StatisticsJob.JobState.valueOf(stateValue); + } + + // step 1: get job infos + List<Long> jobIds = showStmt.getJobIds(); + if (jobIds != null && !jobIds.isEmpty()) { + for (Long jobId : jobIds) { + StatisticsJob statisticsJob = idToStatisticsJob.get(jobId); + if (statisticsJob == null) { + throw new AnalysisException("No such job id: " + jobId); + } + if (jobState == null || jobState == statisticsJob.getJobState()) { + List<Comparable> showInfo = statisticsJob.getShowInfo(null); + results.add(showInfo); + } + } + } else { + long dbId = showStmt.getDbId(); + Set<Long> tblIds = showStmt.getTblIds(); + for (StatisticsJob statisticsJob : idToStatisticsJob.values()) { + long jobDbId = statisticsJob.getDbId(); + if (jobDbId == dbId) { + // check the state + if (jobState == null || jobState == statisticsJob.getJobState()) { + Set<Long> jobTblIds = statisticsJob.getTblIds(); + // get the intersection of two sets + Set<Long> set = Sets.newHashSet(); + set.addAll(jobTblIds); + set.retainAll(tblIds); + for (long tblId : set) { + List<Comparable> showInfo = statisticsJob.getShowInfo(tblId); + results.add(showInfo); + } + } + } + } + } + + // step2: order the result Review Comment: the where condition is mainly to filter the job status(see jobState), which has been processed above. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org