Kikyou1997 commented on code in PR #13883:
URL: https://github.com/apache/doris/pull/13883#discussion_r1018097504


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisJob.java:
##########
@@ -0,0 +1,202 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.statistics;
+
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.Partition;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.datasource.CatalogIf;
+import org.apache.doris.persist.AnalysisJobScheduler;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+import org.apache.doris.statistics.AnalysisJobInfo.JobState;
+
+import org.apache.commons.text.StringSubstitutor;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class AnalysisJob {
+
+    private final AnalysisJobScheduler analysisJobScheduler;
+
+    private final AnalysisJobInfo info;
+
+    private CatalogIf catalog;
+
+    private Database db;
+
+    private Table tbl;
+
+    private Column col;
+
+    private StmtExecutor stmtExecutor;
+
+    public AnalysisJob(AnalysisJobScheduler analysisJobScheduler, 
AnalysisJobInfo info) {
+        this.analysisJobScheduler = analysisJobScheduler;
+        this.info = info;
+        init(info);
+    }
+
+    private void init(AnalysisJobInfo info) {
+        catalog = 
Env.getCurrentEnv().getCatalogMgr().getCatalog(info.catalogName);
+        if (catalog == null) {
+            analysisJobScheduler.updateJobStatus(info.jobId, JobState.FAILED,
+                    String.format("Catalog with name: %s not exists", 
info.dbName), System.currentTimeMillis());
+            return;
+        }
+        db = 
Env.getCurrentEnv().getInternalCatalog().getDb(info.dbName).orElse(null);
+        if (db == null) {
+            analysisJobScheduler.updateJobStatus(info.jobId, JobState.FAILED,
+                    String.format("DB with name %s not exists", info.dbName), 
System.currentTimeMillis());
+            return;
+        }
+        tbl = db.getTable(info.tblName).orElse(null);
+        if (tbl == null) {
+            analysisJobScheduler.updateJobStatus(
+                    info.jobId, JobState.FAILED,
+                    String.format("Table with name %s not exists", 
info.tblName), System.currentTimeMillis());
+        }
+        col = tbl.getColumn(info.colName);
+        if (col == null) {
+            analysisJobScheduler.updateJobStatus(
+                    info.jobId, JobState.FAILED, String.format("Column with 
name %s not exists", info.tblName),
+                    System.currentTimeMillis());
+        }
+    }
+
+    private static final String ANALYZE_PARTITION_SQL_TEMPLATE = "INSERT INTO "
+            + "${internalDB}.${columnStatTbl}"
+            + " SELECT "
+            + "CONCAT(${tblId}, '-', '${colId}', '-', ${partId}) AS id, "
+            + "${catalogId} AS catalog_id, "
+            + "${dbId} AS db_id, "
+            + "${tblId} AS tbl_id, "
+            + "'${colId}' AS col_id, "
+            + "${partId} AS part_id, "
+            + "COUNT(1) AS row_count, "
+            + "NDV(${colName}) AS ndv, "
+            + "SUM(CASE WHEN ${colName} IS NULL THEN 1 ELSE 0 END) AS 
null_count, "
+            + "MIN(${colName}) AS min, "
+            + "MAX(${colName}) AS max, "
+            + "${dataSizeFunction} AS data_size, "
+            + "NOW()"
+            + "FROM `${dbName}`.`${tblName}` "
+            + "PARTITION ${partName}";
+
+    private static final String ANALYZE_COLUMN_SQL_TEMPLATE = "INSERT INTO "
+            + "${internalDB}.${columnStatTbl}"
+            + "    SELECT id, catalog_id, db_id, tbl_id, col_id, part_id, 
row_count, "
+            + "        ndv, null_count, min, max, data_size, update_time\n"

Review Comment:
   I'll do this later



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