EmmyMiao87 commented on code in PR #8861:
URL: https://github.com/apache/doris/pull/8861#discussion_r914490772


##########
fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeStmt.java:
##########
@@ -60,47 +60,50 @@
  *      properties: properties of statistics jobs
  */
 public class AnalyzeStmt extends DdlStmt {
-    private static final Logger LOG = LogManager.getLogger(AnalyzeStmt.class);
-
-    // time to wait for collect  statistics
+    /** time to wait for collect  statistics */
     public static final String CBO_STATISTICS_TASK_TIMEOUT_SEC = 
"cbo_statistics_task_timeout_sec";
 
     private static final ImmutableSet<String> PROPERTIES_SET = new 
ImmutableSet.Builder<String>()
             .add(CBO_STATISTICS_TASK_TIMEOUT_SEC)
             .build();
 
-    public static final Predicate<Long> DESIRED_TASK_TIMEOUT_SEC = (v) -> v > 
0L;
+    private static final Predicate<Long> DESIRED_TASK_TIMEOUT_SEC = (v) -> v > 
0L;
 
     private final TableName dbTableName;
+    private final PartitionNames partitionNames;
     private final List<String> columnNames;
     private final Map<String, String> properties;
 
     // after analyzed
     private long dbId;
     private final Set<Long> tblIds = Sets.newHashSet();
 
-    public AnalyzeStmt(TableName dbTableName, List<String> columns, 
Map<String, String> properties) {
+    public AnalyzeStmt(TableName dbTableName,
+            List<String> columns,
+            PartitionNames partitionNames,
+            Map<String, String> properties) {

Review Comment:
   By the way, if you want to analyze statistics for a given partition, how do 
you think the syntax should be designed?



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/ShowTableStatsStmt.java:
##########
@@ -89,4 +92,9 @@ public ShowResultSetMetaData getMetaData() {
         }
         return builder.build();
     }
+
+    public List<String> getPartitionNames() {

Review Comment:
   same as above



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeStmt.java:
##########
@@ -122,12 +125,40 @@ public List<Table> getTables() throws AnalysisException {
         return tables;
     }
 
+    public List<String> getPartitionNames() {
+        if (partitionNames == null) {
+            return Lists.newArrayList();
+        }
+        return partitionNames.getPartitionNames();
+    }
+
+    public Map<Long, List<String>> getTableIdToPartitionName() throws 
AnalysisException {
+        Preconditions.checkArgument(isAnalyzed(),
+                "The partitionIds must be obtained after the parsing is 
complete");
+        Map<Long, List<String>> tableIdToPartitionName = Maps.newHashMap();
+
+        for (Table table : getTables()) {
+            table.readLock();
+            try {
+                OlapTable olapTable = (OlapTable) table;
+                List<String> partitionNames = getPartitionNames();

Review Comment:
   If you allow users to specify partitions and allow users to specify multiple 
tables at the same time, the user-specified partitions and tables must 
correspond to each other. So you need a map structure to store related 
information, not a unified partitionnames



##########
fe/fe-core/src/main/java/org/apache/doris/catalog/Tablet.java:
##########
@@ -394,6 +394,18 @@ public long getDataSize(boolean singleReplica) {
         return singleReplica ? 
Double.valueOf(s.average().orElse(0)).longValue() : s.sum();
     }
 
+    /**
+     * Get the tablet row count.
+     *
+     * @param singleReplica whether to return the row count of all replicas
+     * @return the row count of tablet
+     */
+    public long getRowCount(boolean singleReplica) {

Review Comment:
   It looks like we don't need to get the rowcount sum of all partitions of the 
tablet. Because this value is meaningless.



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/ShowColumnStatsStmt.java:
##########
@@ -67,4 +70,9 @@ public ShowResultSetMetaData getMetaData() {
         }
         return builder.build();
     }
+
+    public List<String> getPartitionNames() {

Review Comment:
   I suggest that if the statistics setting function of partition table data 
has not been implemented at all, it is best to write todo directly, and the 
function `getPartitionNames` is not needed.
   Then you can directly add the syntax, constructor and get method together.



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStatsStmt.java:
##########
@@ -85,4 +87,9 @@ public TableName getTableName() {
     public Map<StatsType, String> getStatsTypeToValue() {
         return statsTypeToValue;
     }
+
+    public List<String> getPartitionNames() {

Review Comment:
   Same as above



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeStmt.java:
##########
@@ -60,47 +60,50 @@
  *      properties: properties of statistics jobs
  */
 public class AnalyzeStmt extends DdlStmt {
-    private static final Logger LOG = LogManager.getLogger(AnalyzeStmt.class);
-
-    // time to wait for collect  statistics
+    /** time to wait for collect  statistics */
     public static final String CBO_STATISTICS_TASK_TIMEOUT_SEC = 
"cbo_statistics_task_timeout_sec";
 
     private static final ImmutableSet<String> PROPERTIES_SET = new 
ImmutableSet.Builder<String>()
             .add(CBO_STATISTICS_TASK_TIMEOUT_SEC)
             .build();
 
-    public static final Predicate<Long> DESIRED_TASK_TIMEOUT_SEC = (v) -> v > 
0L;
+    private static final Predicate<Long> DESIRED_TASK_TIMEOUT_SEC = (v) -> v > 
0L;
 
     private final TableName dbTableName;
+    private final PartitionNames partitionNames;
     private final List<String> columnNames;
     private final Map<String, String> properties;
 
     // after analyzed
     private long dbId;
     private final Set<Long> tblIds = Sets.newHashSet();
 
-    public AnalyzeStmt(TableName dbTableName, List<String> columns, 
Map<String, String> properties) {
+    public AnalyzeStmt(TableName dbTableName,
+            List<String> columns,
+            PartitionNames partitionNames,

Review Comment:
   It is impossible to change only the constructor without changing the 
semantic parsing. 
   These two need to be modified together.



##########
fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeStmt.java:
##########
@@ -234,15 +272,42 @@ private void checkAnalyzePriv(String dbName, String 
tblName) throws AnalysisExce
     }
 
     private void checkProperties() throws UserException {
-        Optional<String> optional = this.properties.keySet().stream().filter(
+        Optional<String> optional = properties.keySet().stream().filter(
                 entity -> !PROPERTIES_SET.contains(entity)).findFirst();
         if (optional.isPresent()) {
             throw new AnalysisException(optional.get() + " is invalid 
property");
         }
 
-        long taskTimeout = ((Long) 
Util.getLongPropertyOrDefault(this.properties.get(CBO_STATISTICS_TASK_TIMEOUT_SEC),
+        long taskTimeout = ((Long) 
Util.getLongPropertyOrDefault(properties.get(CBO_STATISTICS_TASK_TIMEOUT_SEC),
                 Config.max_cbo_statistics_task_timeout_sec, 
DESIRED_TASK_TIMEOUT_SEC,
                 CBO_STATISTICS_TASK_TIMEOUT_SEC + " should > 0")).intValue();
-        this.properties.put(CBO_STATISTICS_TASK_TIMEOUT_SEC, 
String.valueOf(taskTimeout));
+        properties.put(CBO_STATISTICS_TASK_TIMEOUT_SEC, 
String.valueOf(taskTimeout));
+    }
+
+    @Override
+    public String toSql() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("ANALYZE");
+
+        if (dbTableName != null) {
+            sb.append(" ");
+            sb.append(dbTableName.toSql());
+        }
+
+        if (partitionNames != null) {
+            sb.append(" ");
+            sb.append(partitionNames.toSql());
+        }
+

Review Comment:
   Where is `columnNames` ?



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