Skip to content

Commit

Permalink
[minor](stats) Add start/end time for analyze job, precise to second…
Browse files Browse the repository at this point in the history
…s of TableStats update time apache#27123 (apache#27185)
  • Loading branch information
Kikyou1997 authored and gnehil committed Dec 4, 2023
1 parent 9eef4b9 commit d0ab3fa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -208,15 +210,6 @@ private void analyzeSubPredicate(Expr subExpr) throws AnalysisException {
}
}

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
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;

Expand Down Expand Up @@ -131,6 +133,7 @@ public long getPartitionId() {
}

public ShowResultSet constructResultSet(TableStatsMeta tableStatistic) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
if (tableStatistic == null) {
return new ShowResultSet(getMetaData(), new ArrayList<>());
}
Expand All @@ -139,7 +142,11 @@ public ShowResultSet constructResultSet(TableStatsMeta tableStatistic) {
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);
Expand Down
10 changes: 10 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
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;
Expand Down Expand Up @@ -2587,6 +2588,7 @@ private void handleShowAnalyze() {
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));
Expand All @@ -2610,6 +2612,14 @@ private void handleShowAnalyze() {
row.add(analysisInfo.state.toString());
row.add(Env.getCurrentEnv().getAnalysisManager().getJobProgress(analysisInfo.jobId));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ public enum ScheduleType {
*/
public final long tblUpdateTime;

@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,
Expand Down Expand Up @@ -322,4 +328,14 @@ public static AnalysisInfo read(DataInput dataInput) throws IOException {
}
return analysisInfo;
}

public void markFinished() {
state = AnalysisState.FINISHED;
endTime = System.currentTimeMillis();
}

public void markFailed() {
state = AnalysisState.FAILED;
endTime = System.currentTimeMillis();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,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) {
Expand Down Expand Up @@ -223,9 +223,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);
Expand Down

0 comments on commit d0ab3fa

Please sign in to comment.