You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/05/24 12:00:05 UTC

[GitHub] [incubator-doris] jackwener commented on a diff in pull request #8861: [feature-wip](statistics) step4: collect statistics by implementing statistics tasks

jackwener commented on code in PR #8861:
URL: https://github.com/apache/incubator-doris/pull/8861#discussion_r880414867


##########
fe/fe-core/src/main/java/org/apache/doris/statistics/PartitionStats.java:
##########
@@ -0,0 +1,129 @@
+// 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.Type;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.util.Util;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.Predicate;
+
+
+/**
+ * There are the statistics of partition.
+ * The partition stats are mainly used to provide input for the Optimizer's cost model.
+ * The description of partition stats are following:
+ *     - @rowCount: The row count of partition.
+ *     - @dataSize: The data size of partition.
+ *     - @nameToColumnStats: <@String columnName, @ColumnStats columnStats>
+ *
+ * <p>Each column in the Table will have corresponding @ColumnStats.
+ * Those @ColumnStats are recorded in @nameToColumnStats form of MAP.
+ * This facilitates the optimizer to quickly find the corresponding:
+ *     - @ColumnStats: based on the column name.
+ *     - @rowCount: The row count of partition.
+ *     - @dataSize: The data size of partition.
+ *
+ * <p>The granularity of the statistics is whole partition.
+ * For example: "@rowCount = 1000" means that the row count is 1000 in the whole partition.
+ */
+public class PartitionStats {
+
+    public static final StatsType DATA_SIZE = StatsType.DATA_SIZE;
+    public static final StatsType ROW_COUNT = StatsType.ROW_COUNT;
+
+    private static final Predicate<Long> DESIRED_ROW_COUNT_PRED = (v) -> v >= -1L;
+    private static final Predicate<Long> DESIRED_DATA_SIZE_PRED = (v) -> v >= -1L;
+
+    private long rowCount = -1;
+    private long dataSize = -1;
+    private final Map<String, ColumnStats> nameToColumnStats = Maps.newConcurrentMap();
+
+    /**
+     * Update the partition stats.
+     *
+     * @param statsTypeToValue the map of stats type to value
+     * @throws AnalysisException if the stats value is not valid
+     */
+    public void updatePartitionStats(Map<StatsType, String> statsTypeToValue) throws AnalysisException {
+        for (Map.Entry<StatsType, String> entry : statsTypeToValue.entrySet()) {

Review Comment:
   I suggest use `statsTypeToValue.entrySet().forEach()` which is easier to read



-- 
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-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org