[minor](stats) Add start/end time for analyze job, precise to seconds of TableStats update time #27123
This commit is contained in:
@ -60,6 +60,8 @@ public class ShowAnalyzeStmt extends ShowStmt {
|
||||
.add("state")
|
||||
.add("progress")
|
||||
.add("schedule_type")
|
||||
.add("start_time")
|
||||
.add("end_time")
|
||||
.build();
|
||||
|
||||
private long jobId;
|
||||
@ -208,15 +210,6 @@ public class ShowAnalyzeStmt extends ShowStmt {
|
||||
}
|
||||
}
|
||||
|
||||
private int analyzeColumn(String columnName) throws AnalysisException {
|
||||
for (String title : TITLE_NAMES) {
|
||||
if (title.equalsIgnoreCase(columnName)) {
|
||||
return TITLE_NAMES.indexOf(title);
|
||||
}
|
||||
}
|
||||
throw new AnalysisException("Title name[" + columnName + "] does not exist");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSql() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@ -37,7 +37,9 @@ import org.apache.doris.statistics.TableStatsMeta;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -131,6 +133,7 @@ public class ShowTableStatsStmt extends ShowStmt {
|
||||
}
|
||||
|
||||
public ShowResultSet constructResultSet(TableStatsMeta tableStatistic) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
if (tableStatistic == null) {
|
||||
return new ShowResultSet(getMetaData(), new ArrayList<>());
|
||||
}
|
||||
@ -139,7 +142,11 @@ public class ShowTableStatsStmt extends ShowStmt {
|
||||
row.add(String.valueOf(tableStatistic.updatedRows));
|
||||
row.add(String.valueOf(tableStatistic.queriedTimes.get()));
|
||||
row.add(String.valueOf(tableStatistic.rowCount));
|
||||
row.add(new Date(tableStatistic.updatedTime).toString());
|
||||
LocalDateTime dateTime =
|
||||
LocalDateTime.ofInstant(Instant.ofEpochMilli(tableStatistic.updatedTime),
|
||||
java.time.ZoneId.systemDefault());
|
||||
String formattedDateTime = dateTime.format(formatter);
|
||||
row.add(formattedDateTime);
|
||||
row.add(tableStatistic.analyzeColumns().toString());
|
||||
row.add(tableStatistic.jobType.toString());
|
||||
result.add(row);
|
||||
|
||||
@ -229,6 +229,7 @@ import java.net.URLConnection;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -2629,6 +2630,7 @@ public class ShowExecutor {
|
||||
List<AnalysisInfo> results = Env.getCurrentEnv().getAnalysisManager()
|
||||
.showAnalysisJob(showStmt);
|
||||
List<List<String>> resultRows = Lists.newArrayList();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
for (AnalysisInfo analysisInfo : results) {
|
||||
List<String> row = new ArrayList<>();
|
||||
row.add(String.valueOf(analysisInfo.jobId));
|
||||
@ -2659,6 +2661,14 @@ public class ShowExecutor {
|
||||
LOG.warn("Failed to get progress for job: {}", analysisInfo, e);
|
||||
}
|
||||
row.add(analysisInfo.scheduleType.toString());
|
||||
LocalDateTime startTime =
|
||||
LocalDateTime.ofInstant(Instant.ofEpochMilli(analysisInfo.createTime),
|
||||
java.time.ZoneId.systemDefault());
|
||||
LocalDateTime endTime =
|
||||
LocalDateTime.ofInstant(Instant.ofEpochMilli(analysisInfo.endTime),
|
||||
java.time.ZoneId.systemDefault());
|
||||
row.add(startTime.format(formatter));
|
||||
row.add(endTime.format(formatter));
|
||||
resultRows.add(row);
|
||||
}
|
||||
resultSet = new ShowResultSet(showStmt.getMetaData(), resultRows);
|
||||
|
||||
@ -182,6 +182,12 @@ public class AnalysisInfo implements Writable {
|
||||
@SerializedName("usingSqlForPartitionColumn")
|
||||
public final boolean usingSqlForPartitionColumn;
|
||||
|
||||
@SerializedName("createTime")
|
||||
public final long createTime = System.currentTimeMillis();
|
||||
|
||||
@SerializedName("endTime")
|
||||
public long endTime;
|
||||
|
||||
public AnalysisInfo(long jobId, long taskId, List<Long> taskIds, long catalogId, long dbId, long tblId,
|
||||
Map<String, Set<String>> colToPartitions, Set<String> partitionNames, String colName, Long indexId,
|
||||
JobType jobType, AnalysisMode analysisMode, AnalysisMethod analysisMethod, AnalysisType analysisType,
|
||||
@ -316,4 +322,14 @@ public class AnalysisInfo implements Writable {
|
||||
}
|
||||
return analysisInfo;
|
||||
}
|
||||
|
||||
public void markFinished() {
|
||||
state = AnalysisState.FINISHED;
|
||||
endTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void markFailed() {
|
||||
state = AnalysisState.FAILED;
|
||||
endTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,9 +175,9 @@ public class AnalysisManager implements Writable {
|
||||
}
|
||||
if (allFinished) {
|
||||
if (hasFailure) {
|
||||
job.state = AnalysisState.FAILED;
|
||||
job.markFailed();
|
||||
} else {
|
||||
job.state = AnalysisState.FINISHED;
|
||||
job.markFinished();
|
||||
try {
|
||||
updateTableStats(job);
|
||||
} catch (Throwable e) {
|
||||
@ -224,9 +224,9 @@ public class AnalysisManager implements Writable {
|
||||
taskMap.size() - failedCount, failedCount, 0, taskMap.size());
|
||||
if (failedCount > 0) {
|
||||
job.message = reason.toString();
|
||||
job.state = AnalysisState.FAILED;
|
||||
job.markFailed();
|
||||
} else {
|
||||
job.state = AnalysisState.FINISHED;
|
||||
job.markFinished();
|
||||
}
|
||||
autoJobs.offer(job);
|
||||
systemJobInfoMap.remove(info.jobId);
|
||||
|
||||
Reference in New Issue
Block a user