morningman commented on a change in pull request #2828: [Temp Partition] 
Support add/drop/replace temp partitions
URL: https://github.com/apache/incubator-doris/pull/2828#discussion_r386069171
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/catalog/TempPartitions.java
 ##########
 @@ -0,0 +1,149 @@
+// 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.catalog;
+
+import org.apache.doris.catalog.MaterializedIndex.IndexExtState;
+import org.apache.doris.common.io.Writable;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+// This class saved all temp partitions of a table.
+// temp partition is used to implement the overwrite load.
+// user can load data into some of the temp partitions,
+// and then replace the formal partitions with these temp partitions
+// to make a overwrite load.
+public class TempPartitions implements Writable {
+    private Map<Long, Partition> idToPartition = Maps.newHashMap();
+    private Map<String, Partition> nameToPartition = Maps.newHashMap();
+    private RangePartitionInfo partitionInfo;
+
+    public TempPartitions() {
+    }
+
+    public TempPartitions(List<Column> partCols) {
+        partitionInfo = new RangePartitionInfo(partCols);
+    }
+
+    public RangePartitionInfo getPartitionInfo() {
+        return partitionInfo;
+    }
+
+    public void addPartition(Partition partition) {
+        idToPartition.put(partition.getId(), partition);
+        nameToPartition.put(partition.getName(), partition);
+    }
+
+    /*
+     * Drop temp partitions.
+     * If needDropTablet is true, also drop the tablet from tablet inverted 
index.
+     */
+    public void dropPartition(String partitionName, boolean needDropTablet) {
+        Partition partition = nameToPartition.get(partitionName);
+        if (partition != null) {
+            idToPartition.remove(partition.getId());
+            nameToPartition.remove(partitionName);
+
+            Preconditions.checkState(partitionInfo.getType() == 
PartitionType.RANGE);
+            RangePartitionInfo rangePartitionInfo = (RangePartitionInfo) 
partitionInfo;
+            // drop partition info
+            rangePartitionInfo.dropPartition(partition.getId());
+
+            if (!Catalog.isCheckpointThread() && needDropTablet) {
+                TabletInvertedIndex invertedIndex = 
Catalog.getCurrentInvertedIndex();
+                for (MaterializedIndex index : 
partition.getMaterializedIndices(IndexExtState.ALL)) {
+                    for (Tablet tablet : index.getTablets()) {
+                        invertedIndex.deleteTablet(tablet.getId());
+                    }
+                }
+            }
+        }
+    }
+
+    public Partition getPartition(long partitionId) {
+        return idToPartition.get(partitionId);
+    }
+
+    public Partition getPartition(String partitionName) {
+        return nameToPartition.get(partitionName);
+    }
+
+    public List<Partition> getAllPartitions() {
+        return Lists.newArrayList(idToPartition.values());
+    }
+
+    public boolean hasPartition(String partName) {
+        if (partName == null) {
+            return !idToPartition.isEmpty();
 
 Review comment:
   `if (partName == null)` is removed

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to