weizhengte commented on code in PR #8858:
URL: https://github.com/apache/incubator-doris/pull/8858#discussion_r843924870


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsJob.java:
##########
@@ -18,62 +18,187 @@
 package org.apache.doris.statistics;
 
 import org.apache.doris.analysis.AnalyzeStmt;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.common.UserException;
 
+import com.clearspring.analytics.util.Lists;
+import com.google.common.base.Strings;
 import com.google.common.collect.Maps;
 
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
 import org.glassfish.jersey.internal.guava.Sets;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import com.clearspring.analytics.util.Lists;
-
 /*
 Used to store statistics job info,
 including job status, progress, etc.
  */
 public class StatisticsJob {
+    private static final Logger LOG = 
LogManager.getLogger(StatisticsJob.class);
 
     public enum JobState {
         PENDING,
         SCHEDULING,
         RUNNING,
         FINISHED,
-        CANCELLED
+        CANCELLED,
+        FAILED
     }
 
-    private long id = -1;
+    private final long id = Catalog.getCurrentCatalog().getNextId();
+
+    /**
+     * to be collected database stats.
+     */
+    private final long dbId;
+
+    /**
+     * to be collected table stats.
+     */
+    private final List<Long> tableIds;
+
+    /**
+     * to be collected column stats.
+     */
+    private final Map<Long, List<String>> tableIdToColumnName;
+
+    private final Map<String, String> properties;
+
+    /**
+     * to be executed tasks.
+     */
+    private List<StatisticsTask> tasks = Lists.newArrayList();
+
     private JobState jobState = JobState.PENDING;
-    // optional
-    // to be collected table stats
-    private List<Long> tableId = Lists.newArrayList();
-    // to be collected column stats
-    private Map<Long, List<String>> tableIdToColumnName = Maps.newHashMap();
-    private Map<String, String> properties;
-    // end
 
-    private List<StatisticsTask> taskList = Lists.newArrayList();
+    private final long createTime = System.currentTimeMillis();
+    private long scheduleTime = -1L;
+    private long finishTime = -1L;
+    private int progress = 0;
+
+    public StatisticsJob(Long dbId,
+                         List<Long> tableIdList,
+                         Map<Long, List<String>> tableIdToColumnName,
+                         Map<String, String> properties) {
+        this.dbId = dbId;
+        this.tableIds = tableIdList;
+        this.tableIdToColumnName = tableIdToColumnName;
+        this.properties = properties;
+    }
 
     public long getId() {
-        return id;
+        return this.id;
+    }
+
+    public long getDbId() {
+        return this.dbId;
+    }
+
+    public List<Long> getTableIds() {
+        return this.tableIds;
+    }
+
+    public Map<Long, List<String>> getTableIdToColumnName() {
+        return this.tableIdToColumnName;
+    }
+
+    public Map<String, String> getProperties() {
+        return this.properties;
+    }
+
+    public List<StatisticsTask> getTasks() {
+        return this.tasks;
+    }
+
+    public void setTasks(List<StatisticsTask> tasks) {
+        this.tasks = tasks;
+    }
+
+    public JobState getJobState() {
+        return this.jobState;
+    }
+
+    public void setJobState(JobState jobState) {
+        this.jobState = jobState;
+    }
+
+    public long getCreateTime() {
+        return this.createTime;
+    }
+
+    public long getScheduleTime() {
+        return this.scheduleTime;
+    }
+
+    public void setScheduleTime(long scheduleTime) {
+        this.scheduleTime = scheduleTime;
     }
 
-    /*
-        AnalyzeStmt: Analyze t1(c1), t2
-        StatisticsJob:
-          tableId [t1, t2]
-          tableIdToColumnName <t1, [c1]> <t2, [c1,c2,c3]>
-         */
-    public static StatisticsJob fromAnalyzeStmt(AnalyzeStmt analyzeStmt) {
-        // TODO
-        return new StatisticsJob();
+    public long getFinishTime() {
+        return this.finishTime;
+    }
+
+    public void setFinishTime(long finishTime) {
+        this.finishTime = finishTime;
+    }
+
+    public int getProgress() {
+        return this.progress;
+    }
+
+    public void setProgress(int progress) {
+        this.progress = progress;
+    }
+
+    /**
+     * get statisticsJob from analyzeStmt.
+     * AnalyzeStmt: analyze t1(c1,c2,c3)
+     * tableId: [t1]
+     * tableIdToColumnName <t1, [c1,c2,c3]>
+     */
+    public static StatisticsJob fromAnalyzeStmt(AnalyzeStmt analyzeStmt) 
throws UserException {
+        List<Long> tableIdList = Lists.newArrayList();
+        Map<Long, List<String>> tableIdToColumnName = Maps.newHashMap();
+        List<String> columnNames = analyzeStmt.getColumnNames();
+
+        String dbName = analyzeStmt.getDbName();
+        String tblName = analyzeStmt.getTblName();
+        Database db = Catalog.getCurrentCatalog().getDbOrDdlException(dbName);
+
+        if (Strings.isNullOrEmpty(tblName)) {

Review Comment:
   It is a good suggestion, I will refactor this part of the code



-- 
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

Reply via email to