zddr commented on code in PR #31812:
URL: https://github.com/apache/doris/pull/31812#discussion_r1597816207


##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRelatedPartitionDescRollUpGenerator.java:
##########
@@ -0,0 +1,140 @@
+// 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.mtmv;
+
+import org.apache.doris.analysis.PartitionKeyDesc;
+import org.apache.doris.analysis.PartitionValue;
+import org.apache.doris.catalog.PartitionType;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.mtmv.MTMVPartitionInfo.MTMVPartitionType;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * Roll up some partitions into one partition
+ */
+public class MTMVRelatedPartitionDescRollUpGenerator implements 
MTMVRelatedPartitionDescGeneratorService {
+
+    @Override
+    public void apply(MTMVPartitionInfo mvPartitionInfo, Map<String, String> 
mvProperties,
+            RelatedPartitionDescResult lastResult) throws AnalysisException {
+        if (mvPartitionInfo.getPartitionType() != MTMVPartitionType.EXPR) {
+            return;
+        }
+        MTMVRelatedTableIf relatedTable = mvPartitionInfo.getRelatedTable();
+        PartitionType partitionType = relatedTable.getPartitionType();
+        if (partitionType == PartitionType.RANGE) {
+            lastResult.setDescs(rollUpRange(lastResult.getDescs(), 
mvPartitionInfo));
+        } else if (partitionType == PartitionType.LIST) {
+            lastResult.setDescs(rollUpList(lastResult.getDescs(), 
mvPartitionInfo, mvProperties));
+        } else {
+            throw new AnalysisException("only RANGE/LIST partition support 
roll up");
+        }
+    }
+
+    /**
+     * when related table has 3 partitions:(20200101),(20200102),(20200201)
+     * <p>
+     * if expr is `date_trunc(month)`
+     * then,MTMV will have 2 partitions (20200101,20200102),(20200201)
+     * <p>
+     * if expr is `date_trunc(year)`
+     * then,MTMV will have 1 partitions (20200101,20200102,20200201)
+     *
+     * @param relatedPartitionDescs
+     * @param mvPartitionInfo
+     * @return
+     * @throws AnalysisException
+     */
+    public Map<PartitionKeyDesc, Set<Long>> rollUpList(Map<PartitionKeyDesc, 
Set<Long>> relatedPartitionDescs,
+            MTMVPartitionInfo mvPartitionInfo, Map<String, String> 
mvProperties) throws AnalysisException {
+        Map<String, Set<String>> identityToValues = Maps.newHashMap();
+        Map<String, Set<Long>> identityToPartitionIds = Maps.newHashMap();
+        MTMVPartitionExprService exprSerice = 
MTMVPartitionExprFactory.getExprSerice(mvPartitionInfo.getExpr());
+
+        for (Entry<PartitionKeyDesc, Set<Long>> entry : 
relatedPartitionDescs.entrySet()) {
+            String rollUpIdentity = 
exprSerice.getRollUpIdentity(entry.getKey(), mvProperties);

Review Comment:
   According to the existing logic, it won't be null. Are you worried about 
supporting more expressions in the future?



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