You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/02/28 05:51:00 UTC

[doris] branch branch-1.2-lts updated (7c58c966f0 -> 54cc744981)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a change to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git


    from 7c58c966f0 [cherry-pick](session-variable)add a use_fix_replica session variable to fix query replica (#17217)
     new 79352679d8 [test](regression) add some regression cases on constant evaluation. (#16599)
     new c2cf3a447e [fix](planner)fix multi partition support datetime column #16759
     new b5fb28ee81 [enhancement](memory) reduce memory usage for failed broker loads (#16974)
     new 10be08cece [fix](stream_load) can abort 2pc stream load when table dropped #17088
     new fc2959b597 [fix](load) fix add broken tablet core dump (#17104)
     new 73c3d7f09f [fix](delete) fix delete from bug which can get wrong result (#17146)
     new 785107d771 [Fix](multi catalog)Support hive default partition. (#17179)
     new 54cc744981 [test](test_multi_partition) add multi partition by datetime test (#17068)

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 be/src/olap/delete_handler.cpp                     |  35 ++-
 be/src/olap/delete_handler.h                       |   2 +-
 be/src/olap/iterators.h                            |   2 +-
 be/src/olap/rowset/beta_rowset_reader.cpp          |   6 +-
 be/src/olap/rowset/segment_v2/segment.cpp          |   2 +-
 be/src/olap/rowset/segment_v2/segment_iterator.cpp |   4 +-
 be/src/runtime/tablets_channel.cpp                 |  16 +-
 be/src/runtime/tablets_channel.h                   |   5 +
 .../apache/doris/analysis/MultiPartitionDesc.java  |  28 +-
 .../org/apache/doris/analysis/PartitionValue.java  |  13 +
 .../org/apache/doris/common/util/BrokerUtil.java   |   5 +-
 .../doris/datasource/hive/HiveMetaStoreCache.java  |   3 +-
 .../apache/doris/load/loadv2/LoadLoadingTask.java  |   5 +-
 .../doris/planner/ListPartitionPrunerV2.java       |  18 ++
 .../doris/planner/PartitionPrunerV2Base.java       |  14 +
 .../doris/planner/RangePartitionPrunerV2.java      |   5 +
 .../doris/planner/external/HiveScanProvider.java   |   3 +-
 .../main/java/org/apache/doris/qe/Coordinator.java |   6 +-
 .../apache/doris/service/FrontendServiceImpl.java  |  10 +-
 .../data/delete_p0/test_zone_map_delete.out        | 286 +++++++++++++++++++++
 .../hive/test_hive_default_partition.out           | 135 ++++++++++
 .../data/query_p0/subquery/test_subquery.out       |   9 +
 .../suites/delete_p0/test_zone_map_delete.groovy   |  97 +++++++
 .../hive/test_hive_default_partition.groovy        |  85 ++++++
 .../multi_partition/test_multi_partition.groovy    | 104 +++++++-
 .../suites/query_p0/subquery/test_subquery.groovy  |  10 +
 26 files changed, 852 insertions(+), 56 deletions(-)
 create mode 100644 regression-test/data/external_table_emr_p2/hive/test_hive_default_partition.out
 create mode 100644 regression-test/suites/external_table_emr_p2/hive/test_hive_default_partition.groovy


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


[doris] 05/08: [fix](load) fix add broken tablet core dump (#17104)

Posted by mo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit fc2959b597ae91682ae4affbeda705d57ea0be43
Author: Xin Liao <li...@126.com>
AuthorDate: Fri Feb 24 23:59:03 2023 +0800

    [fix](load) fix add broken tablet core dump (#17104)
---
 be/src/runtime/tablets_channel.cpp | 16 +++++++++++++---
 be/src/runtime/tablets_channel.h   |  5 +++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/be/src/runtime/tablets_channel.cpp b/be/src/runtime/tablets_channel.cpp
index 36c5430e9f..d780e17eb1 100644
--- a/be/src/runtime/tablets_channel.cpp
+++ b/be/src/runtime/tablets_channel.cpp
@@ -127,7 +127,7 @@ Status TabletsChannel::close(
                 // to make sure tablet writer in `_broken_tablets` won't call `close_wait` method.
                 // `close_wait` might create the rowset and commit txn directly, and the subsequent
                 // publish version task will success, which can cause the replica inconsistency.
-                if (_broken_tablets.find(it.second->tablet_id()) != _broken_tablets.end()) {
+                if (_is_broken_tablet(it.second->tablet_id())) {
                     LOG(WARNING) << "SHOULD NOT HAPPEN, tablet writer is broken but not cancelled"
                                  << ", tablet_id=" << it.first << ", transaction_id=" << _txn_id;
                     continue;
@@ -455,7 +455,7 @@ Status TabletsChannel::add_batch(const TabletWriterAddRequest& request,
     std::unordered_map<int64_t /* tablet_id */, std::vector<int> /* row index */> tablet_to_rowidxs;
     for (int i = 0; i < request.tablet_ids_size(); ++i) {
         int64_t tablet_id = request.tablet_ids(i);
-        if (_broken_tablets.find(tablet_id) != _broken_tablets.end()) {
+        if (_is_broken_tablet(tablet_id)) {
             // skip broken tablets
             VLOG_PROGRESS << "skip broken tablet tablet=" << tablet_id;
             continue;
@@ -498,7 +498,7 @@ Status TabletsChannel::add_batch(const TabletWriterAddRequest& request,
             error->set_tablet_id(tablet_to_rowidxs_it.first);
             error->set_msg(err_msg);
             tablet_writer_it->second->cancel_with_status(st);
-            _broken_tablets.insert(tablet_to_rowidxs_it.first);
+            _add_broken_tablet(tablet_to_rowidxs_it.first);
             // continue write to other tablet.
             // the error will return back to sender.
         }
@@ -511,6 +511,16 @@ Status TabletsChannel::add_batch(const TabletWriterAddRequest& request,
     return Status::OK();
 }
 
+void TabletsChannel::_add_broken_tablet(int64_t tablet_id) {
+    std::unique_lock<std::shared_mutex> wlock(_broken_tablets_lock);
+    _broken_tablets.insert(tablet_id);
+}
+
+bool TabletsChannel::_is_broken_tablet(int64_t tablet_id) {
+    std::shared_lock<std::shared_mutex> rlock(_broken_tablets_lock);
+    return _broken_tablets.find(tablet_id) != _broken_tablets.end();
+}
+
 template Status
 TabletsChannel::add_batch<PTabletWriterAddBatchRequest, PTabletWriterAddBatchResult>(
         PTabletWriterAddBatchRequest const&, PTabletWriterAddBatchResult*);
diff --git a/be/src/runtime/tablets_channel.h b/be/src/runtime/tablets_channel.h
index 524a66fb70..c55f7e1b82 100644
--- a/be/src/runtime/tablets_channel.h
+++ b/be/src/runtime/tablets_channel.h
@@ -111,6 +111,9 @@ private:
                      google::protobuf::RepeatedPtrField<PTabletError>* tablet_error,
                      PSlaveTabletNodes slave_tablet_nodes, const bool write_single_replica);
 
+    void _add_broken_tablet(int64_t tablet_id);
+    bool _is_broken_tablet(int64_t tablet_id);
+
     // id of this load channel
     TabletsChannelKey _key;
 
@@ -158,6 +161,8 @@ private:
     // it will wait on this condition variable.
     std::condition_variable _reduce_memory_cond;
 
+    std::shared_mutex _broken_tablets_lock;
+
     std::unordered_set<int64_t> _partition_ids;
 
     static std::atomic<uint64_t> _s_tablet_writer_count;


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


[doris] 02/08: [fix](planner)fix multi partition support datetime column #16759

Posted by mo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit c2cf3a447e5c44e2efc44713ef841337c6c3c80a
Author: catpineapple <42...@users.noreply.github.com>
AuthorDate: Wed Feb 22 19:38:42 2023 +0800

    [fix](planner)fix multi partition support datetime column #16759
---
 .../apache/doris/analysis/MultiPartitionDesc.java  | 28 +++++++++-------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/MultiPartitionDesc.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/MultiPartitionDesc.java
index f3a04cbd6c..803123fcb6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/MultiPartitionDesc.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/MultiPartitionDesc.java
@@ -34,7 +34,6 @@ import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoField;
 import java.time.temporal.WeekFields;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -131,7 +130,9 @@ public class MultiPartitionDesc implements AllPartitionDesc {
         }
         WeekFields weekFields = WeekFields.of(DayOfWeek.of(startDayOfWeek), 1);
         while (startTime.isBefore(this.endTime)) {
-            PartitionValue lowerPartitionValue = new PartitionValue(startTime.format(dateTypeFormat()));
+            PartitionValue lowerPartitionValue = new PartitionValue(
+                    startTime.format(dateTypeFormat(partitionKeyDesc.getLowerValues().get(0).getStringValue()))
+            );
             switch (this.timeUnitType) {
                 case HOUR:
                     partitionName = partitionPrefix + startTime.format(DateTimeFormatter.ofPattern(HOURS_FORMAT));
@@ -167,7 +168,9 @@ public class MultiPartitionDesc implements AllPartitionDesc {
             if (this.timeUnitType != TimestampArithmeticExpr.TimeUnit.DAY && startTime.isAfter(this.endTime)) {
                 startTime = this.endTime;
             }
-            PartitionValue upperPartitionValue = new PartitionValue(startTime.format(dateTypeFormat()));
+            PartitionValue upperPartitionValue = new PartitionValue(
+                    startTime.format(dateTypeFormat(partitionKeyDesc.getUpperValues().get(0).getStringValue()))
+            );
             PartitionKeyDesc partitionKeyDesc = PartitionKeyDesc.createFixed(
                     Lists.newArrayList(lowerPartitionValue),
                     Lists.newArrayList(upperPartitionValue)
@@ -295,21 +298,12 @@ public class MultiPartitionDesc implements AllPartitionDesc {
         return res;
     }
 
-    private DateTimeFormatter dateTypeFormat() {
-        return DateTimeFormatter.ofPattern(this.timeUnitType.equals(TimeUnit.HOUR) ? DATETIME_FORMAT : DATE_FORMAT);
-    }
-
-
-    private List<AllPartitionDesc> aaa(int ii) throws AnalysisException {
-        List<AllPartitionDesc> res = new ArrayList<>();
-        for (int i = 0; i < ii; i++) {
-            if (ii % 2 == 1) {
-                res.add(new MultiPartitionDesc(null, null));
-            } else {
-                res.add(new SinglePartitionDesc(true, "-", null, null));
-            }
+    private DateTimeFormatter dateTypeFormat(String dateTimeStr) {
+        String s = DATE_FORMAT;
+        if (this.timeUnitType.equals(TimeUnit.HOUR) || dateTimeStr.length() == 19) {
+            s = DATETIME_FORMAT;
         }
-        return res;
+        return DateTimeFormatter.ofPattern(s);
     }
 
 }


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


[doris] 01/08: [test](regression) add some regression cases on constant evaluation. (#16599)

Posted by mo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 79352679d874ce43b1db4bef945e57914ceeab02
Author: luozenglin <37...@users.noreply.github.com>
AuthorDate: Tue Feb 28 10:57:37 2023 +0800

    [test](regression) add some regression cases on constant evaluation. (#16599)
---
 regression-test/data/query_p0/subquery/test_subquery.out      |  9 +++++++++
 regression-test/suites/query_p0/subquery/test_subquery.groovy | 10 ++++++++++
 2 files changed, 19 insertions(+)

diff --git a/regression-test/data/query_p0/subquery/test_subquery.out b/regression-test/data/query_p0/subquery/test_subquery.out
index b9941ebf23..0af57d6613 100644
--- a/regression-test/data/query_p0/subquery/test_subquery.out
+++ b/regression-test/data/query_p0/subquery/test_subquery.out
@@ -15,3 +15,12 @@
 -- !sql4 --
 1
 
+-- !sql6 --
+
+-- !sql7 --
+1	-1
+2	-1
+3	-1
+
+-- !sql8 --
+
diff --git a/regression-test/suites/query_p0/subquery/test_subquery.groovy b/regression-test/suites/query_p0/subquery/test_subquery.groovy
index 1044259929..2fdbe8dd54 100644
--- a/regression-test/suites/query_p0/subquery/test_subquery.groovy
+++ b/regression-test/suites/query_p0/subquery/test_subquery.groovy
@@ -41,4 +41,14 @@ suite("test_subquery") {
         select /*+SET_VAR(enable_projection=false) */
         count() from (select k2, k1 from test_query_db.baseall order by k1 limit 1) a;
         """
+
+        qt_sql6 "select k1 from (select k1, -1 as c from test_query_db.test) t where t.c = 1;"
+
+        qt_sql7 "select * from (select k1, -1 as c from test_query_db.test) t where t.c < 0 order by 1;"
+
+        qt_sql8 """
+        select * from (select k1, -1 as c from test_query_db.test union all select k1, -2 as c from test_query_db.baseall) t 
+        where t.c > 0;
+        """
 }
+


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


[doris] 07/08: [Fix](multi catalog)Support hive default partition. (#17179)

Posted by mo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 785107d7714c16049e815fec189b82368fc4a2e9
Author: Jibing-Li <64...@users.noreply.github.com>
AuthorDate: Tue Feb 28 00:08:29 2023 +0800

    [Fix](multi catalog)Support hive default partition. (#17179)
    
    Hive store all the data without partition columns to a default partition named __HIVE_DEFAULT_PARTITION__.
    Doris will fail to get the this partition when the partition column type is INT or something else that
    __HIVE_DEFAULT_PARTITION__ couldn't convert to.
    This pr is to support hive default partition, set the column value to NULL for the missing partition columns.
---
 .../org/apache/doris/analysis/PartitionValue.java  |  13 ++
 .../org/apache/doris/common/util/BrokerUtil.java   |   5 +-
 .../doris/datasource/hive/HiveMetaStoreCache.java  |   3 +-
 .../doris/planner/ListPartitionPrunerV2.java       |  18 +++
 .../doris/planner/PartitionPrunerV2Base.java       |  14 +++
 .../doris/planner/RangePartitionPrunerV2.java      |   5 +
 .../doris/planner/external/HiveScanProvider.java   |   3 +-
 .../hive/test_hive_default_partition.out           | 135 +++++++++++++++++++++
 .../hive/test_hive_default_partition.groovy        |  85 +++++++++++++
 9 files changed, 278 insertions(+), 3 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionValue.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionValue.java
index f61c4be669..b273b798a3 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionValue.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionValue.java
@@ -24,6 +24,7 @@ public class PartitionValue {
     public static final PartitionValue MAX_VALUE = new PartitionValue();
 
     private String value;
+    private boolean isHiveDefaultPartition;
 
     private PartitionValue() {
 
@@ -33,7 +34,15 @@ public class PartitionValue {
         this.value = value;
     }
 
+    public PartitionValue(String value, boolean isHiveDefaultPartition) {
+        this.value = value;
+        this.isHiveDefaultPartition = isHiveDefaultPartition;
+    }
+
     public LiteralExpr getValue(Type type) throws AnalysisException {
+        if (isHiveDefaultPartition) {
+            return new StringLiteral(value);
+        }
         if (isMax()) {
             return LiteralExpr.createInfinity(type, true);
         } else {
@@ -52,4 +61,8 @@ public class PartitionValue {
             return value;
         }
     }
+
+    public boolean isHiveDefaultPartition() {
+        return isHiveDefaultPartition;
+    }
 }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/BrokerUtil.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/BrokerUtil.java
index f11c5fe29d..b41c16e6ba 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/util/BrokerUtil.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/BrokerUtil.java
@@ -26,8 +26,10 @@ import org.apache.doris.catalog.FsBroker;
 import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.ClientPool;
 import org.apache.doris.common.Config;
+import org.apache.doris.common.FeConstants;
 import org.apache.doris.common.Pair;
 import org.apache.doris.common.UserException;
+import org.apache.doris.datasource.hive.HiveMetaStoreCache;
 import org.apache.doris.service.FrontendOptions;
 import org.apache.doris.thrift.TBrokerCheckPathExistRequest;
 import org.apache.doris.thrift.TBrokerCheckPathExistResponse;
@@ -151,7 +153,8 @@ public class BrokerUtil {
             if (index == -1) {
                 continue;
             }
-            columns[index] = pair[1];
+            columns[index] = HiveMetaStoreCache.HIVE_DEFAULT_PARTITION.equals(pair[1])
+                ? FeConstants.null_string : pair[1];
             size++;
             if (size >= columnsFromPath.size()) {
                 break;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetaStoreCache.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetaStoreCache.java
index a1ab3cc92f..31b8d2f3b4 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetaStoreCache.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/hive/HiveMetaStoreCache.java
@@ -80,6 +80,7 @@ import java.util.stream.Stream;
 public class HiveMetaStoreCache {
     private static final Logger LOG = LogManager.getLogger(HiveMetaStoreCache.class);
     private static final int MIN_BATCH_FETCH_PARTITION_NUM = 50;
+    public static final String HIVE_DEFAULT_PARTITION = "__HIVE_DEFAULT_PARTITION__";
 
     private HMSExternalCatalog catalog;
 
@@ -207,7 +208,7 @@ public class HiveMetaStoreCache {
         for (String part : parts) {
             String[] kv = part.split("=");
             Preconditions.checkState(kv.length == 2, partitionName);
-            values.add(new PartitionValue(kv[1]));
+            values.add(new PartitionValue(kv[1], HIVE_DEFAULT_PARTITION.equals(kv[1])));
         }
         try {
             PartitionKey key = PartitionKey.createListPartitionKeyWithTypes(values, types);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/ListPartitionPrunerV2.java b/fe/fe-core/src/main/java/org/apache/doris/planner/ListPartitionPrunerV2.java
index fcae3c4ecd..5b8ec54b3a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/ListPartitionPrunerV2.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/ListPartitionPrunerV2.java
@@ -79,6 +79,19 @@ public class ListPartitionPrunerV2 extends PartitionPrunerV2Base {
         this.rangeToId = rangeToId;
     }
 
+    // For hive partition table.
+    public ListPartitionPrunerV2(Map<Long, PartitionItem> idToPartitionItem,
+                                 List<Column> partitionColumns,
+                                 Map<String, ColumnRange> columnNameToRange,
+                                 Map<UniqueId, Range<PartitionKey>> uidToPartitionRange,
+                                 Map<Range<PartitionKey>, UniqueId> rangeToId,
+                                 RangeMap<ColumnBound, UniqueId> singleColumnRangeMap,
+                                 boolean isHive) {
+        super(idToPartitionItem, partitionColumns, columnNameToRange, singleColumnRangeMap, isHive);
+        this.uidToPartitionRange = uidToPartitionRange;
+        this.rangeToId = rangeToId;
+    }
+
     public static Map<UniqueId, Range<PartitionKey>> genUidToPartitionRange(
             Map<Long, PartitionItem> idToPartitionItem, Map<Long, List<UniqueId>> idToUniqueIdsMap) {
         Map<UniqueId, Range<PartitionKey>> uidToPartitionRange = Maps.newHashMap();
@@ -147,6 +160,11 @@ public class ListPartitionPrunerV2 extends PartitionPrunerV2Base {
 
         Optional<RangeSet<ColumnBound>> rangeSetOpt = columnRange.getRangeSet();
         if (columnRange.hasConjunctiveIsNull() || !rangeSetOpt.isPresent()) {
+            // For Hive external table, partition column could be null.
+            // In which case, the data will be put to a default partition __HIVE_DEFAULT_PARTITION__
+            if (isHive) {
+                return FinalFilters.noFilters();
+            }
             return FinalFilters.constantFalseFilters();
         } else {
             RangeSet<ColumnBound> rangeSet = rangeSetOpt.get();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/PartitionPrunerV2Base.java b/fe/fe-core/src/main/java/org/apache/doris/planner/PartitionPrunerV2Base.java
index e1772509ee..ea24f01a87 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/PartitionPrunerV2Base.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/PartitionPrunerV2Base.java
@@ -43,6 +43,8 @@ public abstract class PartitionPrunerV2Base implements PartitionPruner {
     protected final Map<String, ColumnRange> columnNameToRange;
     // used for single column partition
     protected RangeMap<ColumnBound, UniqueId> singleColumnRangeMap = null;
+    // Flag to indicate if this pruner is for hive partition or not.
+    protected boolean isHive = false;
 
     public PartitionPrunerV2Base(Map<Long, PartitionItem> idToPartitionItem,
             List<Column> partitionColumns,
@@ -63,6 +65,18 @@ public abstract class PartitionPrunerV2Base implements PartitionPruner {
         this.singleColumnRangeMap = singleColumnRangeMap;
     }
 
+    public PartitionPrunerV2Base(Map<Long, PartitionItem> idToPartitionItem,
+                                 List<Column> partitionColumns,
+                                 Map<String, ColumnRange> columnNameToRange,
+                                 RangeMap<ColumnBound, UniqueId> singleColumnRangeMap,
+                                 boolean isHive) {
+        this.idToPartitionItem = idToPartitionItem;
+        this.partitionColumns = partitionColumns;
+        this.columnNameToRange = columnNameToRange;
+        this.singleColumnRangeMap = singleColumnRangeMap;
+        this.isHive = isHive;
+    }
+
     @Override
     public Collection<Long> prune() throws AnalysisException {
         Map<Column, FinalFilters> columnToFilters = Maps.newHashMap();
diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/RangePartitionPrunerV2.java b/fe/fe-core/src/main/java/org/apache/doris/planner/RangePartitionPrunerV2.java
index 4aa3ee41a5..8acba72f15 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/RangePartitionPrunerV2.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/RangePartitionPrunerV2.java
@@ -86,6 +86,11 @@ public class RangePartitionPrunerV2 extends PartitionPrunerV2Base {
         Optional<RangeSet<ColumnBound>> rangeSetOpt = columnRange.getRangeSet();
         if (columnRange.hasConjunctiveIsNull()) {
             if (!rangeSetOpt.isPresent()) {
+                // For Hive external table, partition column could be null.
+                // In which case, the data will be put to a default partition __HIVE_DEFAULT_PARTITION__
+                if (isHive) {
+                    return FinalFilters.noFilters();
+                }
                 // Only has conjunctive `is null` predicate.
                 return FinalFilters.create(Sets.newHashSet(getMinInfinityRange(column)));
             } else {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/external/HiveScanProvider.java b/fe/fe-core/src/main/java/org/apache/doris/planner/external/HiveScanProvider.java
index e69f9788d0..f538bf3c3e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/external/HiveScanProvider.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/external/HiveScanProvider.java
@@ -161,7 +161,8 @@ public class HiveScanProvider extends HMSTableScanProvider {
                         hmsTable.getPartitionColumns(), columnNameToRange,
                         hivePartitionValues.getUidToPartitionRange(),
                         hivePartitionValues.getRangeToId(),
-                        hivePartitionValues.getSingleColumnRangeMap());
+                        hivePartitionValues.getSingleColumnRangeMap(),
+                        true);
                 Collection<Long> filteredPartitionIds = pruner.prune();
                 this.readPartitionNum = filteredPartitionIds.size();
                 LOG.debug("hive partition fetch and prune for table {}.{} cost: {} ms",
diff --git a/regression-test/data/external_table_emr_p2/hive/test_hive_default_partition.out b/regression-test/data/external_table_emr_p2/hive/test_hive_default_partition.out
new file mode 100644
index 0000000000..3737fbc7f6
--- /dev/null
+++ b/regression-test/data/external_table_emr_p2/hive/test_hive_default_partition.out
@@ -0,0 +1,135 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !one_partition1 --
+1	1
+2	1
+3	2
+4	2
+5	\N
+6	\N
+
+-- !one_partition2 --
+5	\N
+6	\N
+
+-- !one_partition3 --
+1
+2
+3
+4
+
+-- !one_partition4 --
+1
+1
+2
+2
+
+-- !one_partition5 --
+4	2
+5	\N
+6	\N
+
+-- !two_partition1 --
+1	\N	one
+2	\N	one
+3	2	\N
+4	2	\N
+5	3	three
+6	3	three
+7	\N	\N
+8	\N	\N
+
+-- !two_partition2 --
+1	\N	one
+2	\N	one
+7	\N	\N
+8	\N	\N
+
+-- !two_partition3 --
+3	2	\N
+4	2	\N
+5	3	three
+6	3	three
+
+-- !two_partition4 --
+3	2	\N
+4	2	\N
+7	\N	\N
+8	\N	\N
+
+-- !two_partition5 --
+1	\N	one
+2	\N	one
+5	3	three
+6	3	three
+
+-- !two_partition6 --
+5	3	three
+6	3	three
+
+-- !two_partition7 --
+1	\N	one
+2	\N	one
+
+-- !two_partition8 --
+3	2	\N
+4	2	\N
+
+-- !two_partition9 --
+7	\N	\N
+8	\N	\N
+
+-- !two_partition10 --
+1	\N	one
+2	\N	one
+3	2	\N
+4	2	\N
+5	3	three
+6	3	three
+
+-- !two_partition11 --
+1	\N	one
+2	\N	one
+5	3	three
+6	3	three
+7	\N	\N
+8	\N	\N
+
+-- !two_partition12 --
+3	2	\N
+4	2	\N
+5	3	three
+6	3	three
+7	\N	\N
+8	\N	\N
+
+-- !two_partition13 --
+1	\N	one
+2	\N	one
+3	2	\N
+4	2	\N
+7	\N	\N
+8	\N	\N
+
+-- !two_partition14 --
+1	\N	one
+2	\N	one
+3	2	\N
+4	2	\N
+5	3	three
+6	3	three
+
+-- !two_partition15 --
+6	3	three
+7	\N	\N
+8	\N	\N
+
+-- !two_partition16 --
+3	2	\N
+4	2	\N
+5	3	three
+6	3	three
+
+-- !two_partition17 --
+1	\N	one
+2	\N	one
+
diff --git a/regression-test/suites/external_table_emr_p2/hive/test_hive_default_partition.groovy b/regression-test/suites/external_table_emr_p2/hive/test_hive_default_partition.groovy
new file mode 100644
index 0000000000..2deddb9d2d
--- /dev/null
+++ b/regression-test/suites/external_table_emr_p2/hive/test_hive_default_partition.groovy
@@ -0,0 +1,85 @@
+// 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.
+
+suite("test_hive_default_partition", "p2") {
+    def one_partition1 = """select * from one_partition order by id;"""
+    def one_partition2 = """select id, part1 from one_partition where part1 is null order by id;"""
+    def one_partition3 = """select id from one_partition where part1 is not null order by id;"""
+    def one_partition4 = """select part1 from one_partition where part1>0 order by id;"""
+    def one_partition5 = """select id, part1 from one_partition where part1 is null or id>3 order by id;"""
+
+    def two_partition1 = """select * from two_partition order by id;"""
+    def two_partition2 = """select id, part1, part2 from two_partition where part1 is null order by id;"""
+    def two_partition3 = """select id, part1, part2 from two_partition where part1 is not null order by id;"""
+    def two_partition4 = """select id, part1, part2 from two_partition where part2 is null order by id;"""
+    def two_partition5 = """select id, part1, part2 from two_partition where part2 is not null order by id;"""
+    def two_partition6 = """select id, part1, part2 from two_partition where part1 is not null and part2 is not null order by id;"""
+    def two_partition7 = """select id, part1, part2 from two_partition where part1 is null and part2 is not null order by id;"""
+    def two_partition8 = """select id, part1, part2 from two_partition where part1 is not null and part2 is null order by id;"""
+    def two_partition9 = """select id, part1, part2 from two_partition where part1 is null and part2 is null order by id;"""
+    def two_partition10 = """select id, part1, part2 from two_partition where part1 is not null or part2 is not null order by id;"""
+    def two_partition11 = """select id, part1, part2 from two_partition where part1 is null or part2 is not null order by id;"""
+    def two_partition12 = """select id, part1, part2 from two_partition where part1 is not null or part2 is null order by id;"""
+    def two_partition13 = """select id, part1, part2 from two_partition where part1 is null or part2 is null order by id;"""
+    def two_partition14 = """select id, part1, part2 from two_partition where part1 is not null or part2 is not null order by id;"""
+    def two_partition15 = """select id, part1, part2 from two_partition where id > 5 order by id;"""
+    def two_partition16 = """select id, part1, part2 from two_partition where part1>0 order by id;"""
+    def two_partition17 = """select id, part1, part2 from two_partition where part2 = 'one' order by id;"""
+
+    String enabled = context.config.otherConfigs.get("enableExternalHiveTest")
+    if (enabled != null && enabled.equalsIgnoreCase("true")) {
+        String extHiveHmsHost = context.config.otherConfigs.get("extHiveHmsHost")
+        String extHiveHmsPort = context.config.otherConfigs.get("extHiveHmsPort")
+        String catalog_name = "hive_default_partition"
+        sql """drop catalog if exists ${catalog_name};"""
+        sql """
+            create catalog if not exists ${catalog_name} properties (
+                'type'='hms',
+                'hive.metastore.uris' = 'thrift://${extHiveHmsHost}:${extHiveHmsPort}'
+            );
+        """
+        logger.info("catalog " + catalog_name + " created")
+        sql """switch ${catalog_name};"""
+        logger.info("switched to catalog " + catalog_name)
+        sql """use multi_catalog;"""
+        qt_one_partition1 one_partition1
+        qt_one_partition2 one_partition2
+        qt_one_partition3 one_partition3
+        qt_one_partition4 one_partition4
+        qt_one_partition5 one_partition5
+
+        qt_two_partition1 two_partition1
+        qt_two_partition2 two_partition2
+        qt_two_partition3 two_partition3
+        qt_two_partition4 two_partition4
+        qt_two_partition5 two_partition5
+        qt_two_partition6 two_partition6
+        qt_two_partition7 two_partition7
+        qt_two_partition8 two_partition8
+        qt_two_partition9 two_partition9
+        qt_two_partition10 two_partition10
+        qt_two_partition11 two_partition11
+        qt_two_partition12 two_partition12
+        qt_two_partition13 two_partition13
+        qt_two_partition14 two_partition14
+        qt_two_partition15 two_partition15
+        qt_two_partition16 two_partition16
+        qt_two_partition17 two_partition17
+
+    }
+}
+


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


[doris] 08/08: [test](test_multi_partition) add multi partition by datetime test (#17068)

Posted by mo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 54cc744981d83b7d7a37443a94b0b2d6650284f0
Author: yongkang.zhong <zh...@qq.com>
AuthorDate: Tue Feb 28 12:10:24 2023 +0800

    [test](test_multi_partition) add multi partition by datetime test (#17068)
    
    add multi partition by datetime test , This feature was created by @catpineapple
---
 be/src/olap/rowset/beta_rowset_reader.cpp          |   2 +-
 .../main/java/org/apache/doris/qe/Coordinator.java |   1 +
 .../multi_partition/test_multi_partition.groovy    | 104 ++++++++++++++++++++-
 3 files changed, 105 insertions(+), 2 deletions(-)

diff --git a/be/src/olap/rowset/beta_rowset_reader.cpp b/be/src/olap/rowset/beta_rowset_reader.cpp
index df90d9ee03..3b52b110b1 100644
--- a/be/src/olap/rowset/beta_rowset_reader.cpp
+++ b/be/src/olap/rowset/beta_rowset_reader.cpp
@@ -76,7 +76,7 @@ Status BetaRowsetReader::get_segment_iterators(RowsetReaderContext* read_context
                 _rowset->end_version(), _read_options.delete_condition_predicates.get(),
                 &_read_options.del_predicates_for_zone_map);
         // if del cond is not empty, schema may be different in multiple rowset
-        _can_reuse_schema = _read_options.col_id_to_del_predicates.empty();
+        _can_reuse_schema = _read_options.del_predicates_for_zone_map.empty();
     }
     // In vertical compaction, every column group need new schema
     if (read_context->is_vertical_compaction) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java b/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java
index 0542b96c70..31a392e3bf 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java
@@ -135,6 +135,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
+import java.util.stream.Collectors;
 
 public class Coordinator {
     private static final Logger LOG = LogManager.getLogger(Coordinator.class);
diff --git a/regression-test/suites/partition_p0/multi_partition/test_multi_partition.groovy b/regression-test/suites/partition_p0/multi_partition/test_multi_partition.groovy
index 3f775143de..2717f372d6 100644
--- a/regression-test/suites/partition_p0/multi_partition/test_multi_partition.groovy
+++ b/regression-test/suites/partition_p0/multi_partition/test_multi_partition.groovy
@@ -219,4 +219,106 @@ suite("test_multi_partition") {
     logger.info("${result2}")
     assertEquals(result2.size(), 48)
     sql "drop table multi_par5"
-}
+
+
+    sql "drop table if exists multi_par6"
+    sql """
+        CREATE TABLE IF NOT EXISTS multi_par6 (
+            k1 tinyint NOT NULL,
+            k2 smallint NOT NULL,
+            k3 int NOT NULL,
+            k4 bigint NOT NULL,
+            k5 decimal(9, 3) NOT NULL,
+            k6 char(5) NOT NULL,
+            k10 date NOT NULL,
+            k11 datetime NOT NULL,
+            k12 datev2 NOT NULL,
+            k13 datetimev2 NOT NULL,
+            k14 datetimev2(3) NOT NULL,
+            k15 datetimev2(6) NOT NULL,
+            k7 varchar(20) NOT NULL,
+            k8 double max NOT NULL,
+            k9 float sum NOT NULL )
+        AGGREGATE KEY(k1,k2,k3,k4,k5,k6,k10,k11,k12,k13,k14,k15,k7)
+        PARTITION BY RANGE(k11) (
+            FROM ("2022-11-02 00:00:00") TO ("2022-12-02 00:00:00") INTERVAL 1 DAY
+            )
+        DISTRIBUTED BY HASH(k1) BUCKETS 5 properties("replication_num" = "1")
+        """
+    result1  = sql "show tables like 'multi_par6'"
+    logger.info("${result1}")
+    assertEquals(result1.size(), 1)
+    result2  = sql "show partitions from multi_par6"
+    logger.info("${result2}")
+    assertEquals(result2.size(), 30)
+    sql "drop table multi_par6"
+
+
+    sql "drop table if exists multi_par7"
+    sql """
+        CREATE TABLE IF NOT EXISTS multi_par7 (
+            k1 tinyint NOT NULL,
+            k2 smallint NOT NULL,
+            k3 int NOT NULL,
+            k4 bigint NOT NULL,
+            k5 decimal(9, 3) NOT NULL,
+            k6 char(5) NOT NULL,
+            k10 date NOT NULL,
+            k11 datetime NOT NULL,
+            k12 datev2 NOT NULL,
+            k13 datetimev2 NOT NULL,
+            k14 datetimev2(3) NOT NULL,
+            k15 datetimev2(6) NOT NULL,
+            k7 varchar(20) NOT NULL,
+            k8 double max NOT NULL,
+            k9 float sum NOT NULL )
+        AGGREGATE KEY(k1,k2,k3,k4,k5,k6,k10,k11,k12,k13,k14,k15,k7)
+        PARTITION BY RANGE(k13) (
+            FROM ("2022-11-02 00:00:00") TO ("2022-12-02 00:00:00") INTERVAL 1 DAY
+            )
+        DISTRIBUTED BY HASH(k1) BUCKETS 5 properties("replication_num" = "1")
+        """
+    result1  = sql "show tables like 'multi_par7'"
+    logger.info("${result1}")
+    assertEquals(result1.size(), 1)
+    result2  = sql "show partitions from multi_par7"
+    logger.info("${result2}")
+    assertEquals(result2.size(), 30)
+    sql "drop table multi_par7"
+
+
+
+
+    sql "drop table if exists multi_par8"
+    sql """
+        CREATE TABLE IF NOT EXISTS multi_par8 (
+            k1 tinyint NOT NULL,
+            k2 smallint NOT NULL,
+            k3 int NOT NULL,
+            k4 bigint NOT NULL,
+            k5 decimal(9, 3) NOT NULL,
+            k6 char(5) NOT NULL,
+            k10 date NOT NULL,
+            k11 datetime NOT NULL,
+            k12 datev2 NOT NULL,
+            k13 datetimev2 NOT NULL,
+            k14 datetimev2(3) NOT NULL,
+            k15 datetimev2(6) NOT NULL,
+            k7 varchar(20) NOT NULL,
+            k8 double max NOT NULL,
+            k9 float sum NOT NULL )
+        AGGREGATE KEY(k1,k2,k3,k4,k5,k6,k10,k11,k12,k13,k14,k15,k7)
+        PARTITION BY RANGE(k10) (
+            FROM ("2022-11-02") TO ("2022-12-03") INTERVAL 2 DAY
+            )
+        DISTRIBUTED BY HASH(k1) BUCKETS 5 properties("replication_num" = "1")
+        """
+    result1  = sql "show tables like 'multi_par8'"
+    logger.info("${result1}")
+    assertEquals(result1.size(), 1)
+    result2  = sql "show partitions from multi_par8"
+    logger.info("${result2}")
+    assertEquals(result2.size(), 16)
+    sql "drop table multi_par8"
+
+}
\ No newline at end of file


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


[doris] 06/08: [fix](delete) fix delete from bug which can get wrong result (#17146)

Posted by mo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 73c3d7f09f7f4a6970dc4672f6a21bfed665f3f2
Author: xueweizhang <zx...@163.com>
AuthorDate: Tue Feb 28 09:20:10 2023 +0800

    [fix](delete) fix delete from bug which can get wrong result (#17146)
    
    理论上,如果是两次独立的删除,比如delete from table where a=1; delete from table where a=2;其实这个地方应该可以使用的,但是目前的代码,是把所有不同版本的delete predicates和不同列的delete predicates都放到一起了,失去了版本信息、失去了谓词间可能是and的关系,统一弱化成了delete predicates都是独立的,有一个delete predicates满足条件,就把page都去掉。
    这个pr的修改方式,就是在当前代码的基础上,当只有一个delete predicate的时候才能保证后续淘汰page的正确性,所以这里一律加了 == 1的判断才传递delete predicates。
    如果要把不同版本的delete predicates和不同列的delete predicates作为完整和严谨的逻辑去判断page,需要修改的设计就有点多了,目前的方案算是一种优先解决bug的思路,后续可以进一步把delete predicates这块加速zone判断进行page淘汰的逻辑完善,提高delete predicates使用的场景。
---
 be/src/olap/delete_handler.cpp                     |  35 ++-
 be/src/olap/delete_handler.h                       |   2 +-
 be/src/olap/iterators.h                            |   2 +-
 be/src/olap/rowset/beta_rowset_reader.cpp          |   4 +-
 be/src/olap/rowset/segment_v2/segment.cpp          |   2 +-
 be/src/olap/rowset/segment_v2/segment_iterator.cpp |   4 +-
 .../data/delete_p0/test_zone_map_delete.out        | 286 +++++++++++++++++++++
 .../suites/delete_p0/test_zone_map_delete.groovy   |  97 +++++++
 8 files changed, 405 insertions(+), 27 deletions(-)

diff --git a/be/src/olap/delete_handler.cpp b/be/src/olap/delete_handler.cpp
index 017cef5ecc..90b2f79c67 100644
--- a/be/src/olap/delete_handler.cpp
+++ b/be/src/olap/delete_handler.cpp
@@ -310,8 +310,8 @@ void DeleteHandler::finalize() {
 
 void DeleteHandler::get_delete_conditions_after_version(
         int64_t version, AndBlockColumnPredicate* and_block_column_predicate_ptr,
-        std::unordered_map<int32_t, std::vector<const ColumnPredicate*>>* col_id_to_del_predicates)
-        const {
+        std::unordered_map<int32_t, std::vector<const ColumnPredicate*>>*
+                del_predicates_for_zone_map) const {
     for (auto& del_cond : _del_conds) {
         if (del_cond.filter_version > version) {
             // now, only query support delete column predicate operator
@@ -321,33 +321,28 @@ void DeleteHandler::get_delete_conditions_after_version(
                             new SingleColumnBlockPredicate(del_cond.column_predicate_vec[0]);
                     and_block_column_predicate_ptr->add_column_predicate(
                             single_column_block_predicate);
-                    if (col_id_to_del_predicates->count(
+                    if (del_predicates_for_zone_map->count(
                                 del_cond.column_predicate_vec[0]->column_id()) < 1) {
-                        col_id_to_del_predicates->insert(
+                        del_predicates_for_zone_map->insert(
                                 {del_cond.column_predicate_vec[0]->column_id(),
                                  std::vector<const ColumnPredicate*> {}});
                     }
-                    (*col_id_to_del_predicates)[del_cond.column_predicate_vec[0]->column_id()]
+                    (*del_predicates_for_zone_map)[del_cond.column_predicate_vec[0]->column_id()]
                             .push_back(del_cond.column_predicate_vec[0]);
                 } else {
                     auto or_column_predicate = new OrBlockColumnPredicate();
 
                     // build or_column_predicate
-                    std::for_each(
-                            del_cond.column_predicate_vec.cbegin(),
-                            del_cond.column_predicate_vec.cend(),
-                            [&or_column_predicate,
-                             col_id_to_del_predicates](const ColumnPredicate* predicate) {
-                                if (col_id_to_del_predicates->count(predicate->column_id()) < 1) {
-                                    col_id_to_del_predicates->insert(
-                                            {predicate->column_id(),
-                                             std::vector<const ColumnPredicate*> {}});
-                                }
-                                (*col_id_to_del_predicates)[predicate->column_id()].push_back(
-                                        predicate);
-                                or_column_predicate->add_column_predicate(
-                                        new SingleColumnBlockPredicate(predicate));
-                            });
+                    // when delete from where a = 1 and b = 2, we can not use del_predicates_for_zone_map to filter zone page,
+                    // so here do not put predicate to del_predicates_for_zone_map,
+                    // refer #17145 for more details.
+                    // // TODO: need refactor design and code to use more version delete and more column delete to filter zone page.
+                    std::for_each(del_cond.column_predicate_vec.cbegin(),
+                                  del_cond.column_predicate_vec.cend(),
+                                  [&or_column_predicate](const ColumnPredicate* predicate) {
+                                      or_column_predicate->add_column_predicate(
+                                              new SingleColumnBlockPredicate(predicate));
+                                  });
                     and_block_column_predicate_ptr->add_column_predicate(or_column_predicate);
                 }
             }
diff --git a/be/src/olap/delete_handler.h b/be/src/olap/delete_handler.h
index 3dc8e5b3b7..e5a4c19cb2 100644
--- a/be/src/olap/delete_handler.h
+++ b/be/src/olap/delete_handler.h
@@ -101,7 +101,7 @@ public:
     void get_delete_conditions_after_version(
             int64_t version, AndBlockColumnPredicate* and_block_column_predicate_ptr,
             std::unordered_map<int32_t, std::vector<const ColumnPredicate*>>*
-                    col_id_to_del_predicates) const;
+                    del_predicates_for_zone_map) const;
 
 private:
     // Use regular expression to extract 'column_name', 'op' and 'operands'
diff --git a/be/src/olap/iterators.h b/be/src/olap/iterators.h
index 30f3ffcf11..754820cb2f 100644
--- a/be/src/olap/iterators.h
+++ b/be/src/olap/iterators.h
@@ -83,7 +83,7 @@ public:
     // used to fiter rows in row block
     std::vector<ColumnPredicate*> column_predicates;
     std::unordered_map<int32_t, std::shared_ptr<AndBlockColumnPredicate>> col_id_to_predicates;
-    std::unordered_map<int32_t, std::vector<const ColumnPredicate*>> col_id_to_del_predicates;
+    std::unordered_map<int32_t, std::vector<const ColumnPredicate*>> del_predicates_for_zone_map;
     TPushAggOp::type push_down_agg_type_opt = TPushAggOp::NONE;
 
     // REQUIRED (null is not allowed)
diff --git a/be/src/olap/rowset/beta_rowset_reader.cpp b/be/src/olap/rowset/beta_rowset_reader.cpp
index 3d9b85f8f2..df90d9ee03 100644
--- a/be/src/olap/rowset/beta_rowset_reader.cpp
+++ b/be/src/olap/rowset/beta_rowset_reader.cpp
@@ -40,7 +40,7 @@ void BetaRowsetReader::reset_read_options() {
     _read_options.delete_condition_predicates = std::make_shared<AndBlockColumnPredicate>();
     _read_options.column_predicates.clear();
     _read_options.col_id_to_predicates.clear();
-    _read_options.col_id_to_del_predicates.clear();
+    _read_options.del_predicates_for_zone_map.clear();
     _read_options.key_ranges.clear();
 }
 
@@ -74,7 +74,7 @@ Status BetaRowsetReader::get_segment_iterators(RowsetReaderContext* read_context
     if (read_context->delete_handler != nullptr) {
         read_context->delete_handler->get_delete_conditions_after_version(
                 _rowset->end_version(), _read_options.delete_condition_predicates.get(),
-                &_read_options.col_id_to_del_predicates);
+                &_read_options.del_predicates_for_zone_map);
         // if del cond is not empty, schema may be different in multiple rowset
         _can_reuse_schema = _read_options.col_id_to_del_predicates.empty();
     }
diff --git a/be/src/olap/rowset/segment_v2/segment.cpp b/be/src/olap/rowset/segment_v2/segment.cpp
index 748aaa98c1..90a8f9b447 100644
--- a/be/src/olap/rowset/segment_v2/segment.cpp
+++ b/be/src/olap/rowset/segment_v2/segment.cpp
@@ -115,7 +115,7 @@ Status Segment::new_iterator(const Schema& schema, const StorageReadOptions& rea
     }
 
     RETURN_IF_ERROR(load_index());
-    if (read_options.col_id_to_del_predicates.empty() &&
+    if (read_options.delete_condition_predicates->num_of_column_predicate() == 0 &&
         read_options.push_down_agg_type_opt != TPushAggOp::NONE) {
         iter->reset(vectorized::new_vstatistics_iterator(this->shared_from_this(), schema));
     } else {
diff --git a/be/src/olap/rowset/segment_v2/segment_iterator.cpp b/be/src/olap/rowset/segment_v2/segment_iterator.cpp
index a90d558020..9ed4a7cfa7 100644
--- a/be/src/olap/rowset/segment_v2/segment_iterator.cpp
+++ b/be/src/olap/rowset/segment_v2/segment_iterator.cpp
@@ -333,8 +333,8 @@ Status SegmentIterator::_get_row_ranges_from_conditions(RowRanges* condition_row
         DCHECK(_opts.col_id_to_predicates.count(cid) > 0);
         RETURN_IF_ERROR(_column_iterators[_schema.unique_id(cid)]->get_row_ranges_by_zone_map(
                 _opts.col_id_to_predicates[cid].get(),
-                _opts.col_id_to_del_predicates.count(cid) > 0
-                        ? &(_opts.col_id_to_del_predicates[cid])
+                _opts.del_predicates_for_zone_map.count(cid) > 0
+                        ? &(_opts.del_predicates_for_zone_map[cid])
                         : nullptr,
                 &column_row_ranges));
         // intersect different columns's row ranges to get final row ranges by zone map
diff --git a/regression-test/data/delete_p0/test_zone_map_delete.out b/regression-test/data/delete_p0/test_zone_map_delete.out
index d119d5e8de..ba300220f4 100644
--- a/regression-test/data/delete_p0/test_zone_map_delete.out
+++ b/regression-test/data/delete_p0/test_zone_map_delete.out
@@ -57,3 +57,289 @@
 
 -- !sql --
 
+-- !sql --
+
+-- !sql --
+
+-- !sql --
+1	11
+1	22
+1	33
+1	44
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+1	11
+1	22
+1	33
+1	44
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+1	11
+1	22
+1	33
+1	44
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+
+-- !sql --
+1	22
+1	33
+1	44
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+1	22
+1	33
+1	44
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+1	33
+1	44
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+1	33
+1	44
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+1	44
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+1	44
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+1	55
+1	66
+1	77
+1	88
+1	99
+1	100
+1	101
+1	102
+1	111
+1	122
+1	133
+1	144
+1	155
+1	166
+1	177
+1	188
+1	199
+1	200
+1	201
+1	202
+
+-- !sql --
+1	201
+1	202
+
+-- !sql --
+1	201
+
+-- !sql --
+1	11
+1	22
+
+-- !sql --
+1	11
+
diff --git a/regression-test/suites/delete_p0/test_zone_map_delete.groovy b/regression-test/suites/delete_p0/test_zone_map_delete.groovy
index 5e8beb375d..f79830c815 100644
--- a/regression-test/suites/delete_p0/test_zone_map_delete.groovy
+++ b/regression-test/suites/delete_p0/test_zone_map_delete.groovy
@@ -54,4 +54,101 @@ suite("test_zone_map_delete") {
     qt_sql """select * from ${tableName} ORDER BY k1;"""
 
     sql """ DROP TABLE IF EXISTS ${tableName} """
+
+    // =========================
+    sql """
+    CREATE TABLE IF NOT EXISTS ${tableName} (
+        `k1` bigint(20) NULL,
+        `k2` largeint(40) NULL,
+        `k3` largeint(40) NULL
+    ) ENGINE=OLAP
+    AGGREGATE KEY(`k1`, `k2`, `k3`)
+    COMMENT 'OLAP'
+    DISTRIBUTED BY HASH(`k1`) BUCKETS 1
+    PROPERTIES (
+    "replication_allocation" = "tag.location.default: 1",
+    "in_memory" = "false",
+    "storage_format" = "V2",
+    "light_schema_change" = "true",
+    "disable_auto_compaction" = "true"
+    );
+    """
+
+    sql """ truncate table ${tableName}; """
+
+    sql """ insert into ${tableName} values(0,1,11),(0,1,22),(0,1,33),(0,1,44),(0,1,55),(0,1,66),(0,1,77),(0,1,88),(0,1,99),(0,1,100),(0,1,101),(0,1,102),(0,1,111),(0,1,122),(0,1,133),(0,1,144),(0,1,155),(0,1,166),(0,1,177),(0,1,188),(0,1,199),(0,1,200),(0,1,201),(0,1,202);"""
+
+    sql """ delete from ${tableName} where k2=0;"""
+
+    sql """ delete from ${tableName} where k2=1;"""
+
+    qt_sql """ select k2,k3 from ${tableName} ORDER BY k3;"""
+
+    qt_sql """ select k2,k3 from ${tableName} where k2 = 1 ORDER BY k3;"""
+
+
+    sql """ truncate table ${tableName}; """
+
+    sql """ insert into ${tableName} values(0,1,11),(0,1,22),(0,1,33),(0,1,44),(0,1,55),(0,1,66),(0,1,77),(0,1,88),(0,1,99),(0,1,100),(0,1,101),(0,1,102),(0,1,111),(0,1,122),(0,1,133),(0,1,144),(0,1,155),(0,1,166),(0,1,177),(0,1,188),(0,1,199),(0,1,200),(0,1,201),(0,1,202);"""
+
+    sql """ delete from ${tableName} where k2=1 and k2=0;"""
+
+    qt_sql """ select k2,k3 from ${tableName} ORDER BY k3;"""
+
+    qt_sql """ select k2,k3 from ${tableName} where k2 = 1 ORDER BY k3;"""
+
+
+    sql """ truncate table ${tableName}; """
+
+    sql """ insert into ${tableName} values(0,1,11),(0,1,22),(0,1,33),(0,1,44),(0,1,55),(0,1,66),(0,1,77),(0,1,88),(0,1,99),(0,1,100),(0,1,101),(0,1,102),(0,1,111),(0,1,122),(0,1,133),(0,1,144),(0,1,155),(0,1,166),(0,1,177),(0,1,188),(0,1,199),(0,1,200),(0,1,201),(0,1,202);"""
+
+    sql """ delete from ${tableName} where k2 is null and k3=00;"""
+
+    qt_sql """ select k2,k3 from ${tableName} ORDER BY k3;"""
+
+    qt_sql """ select k2,k3 from ${tableName} where k2 is null ORDER BY k3;"""
+
+    sql """delete from ${tableName} where k2 is not null and k3=11;"""
+
+    qt_sql """select k2,k3 from ${tableName} ORDER BY k3;"""
+
+    qt_sql """select k2,k3 from ${tableName} where k2 is not null ORDER BY k3;"""
+
+    sql """delete from ${tableName} where k2=1 and k3=22;"""
+
+    qt_sql """select k2,k3 from ${tableName} ORDER BY k3;"""
+
+    qt_sql """select k2,k3 from ${tableName} where k2=1 ORDER BY k3;"""
+
+    sql """delete from ${tableName} where k2!=0 and k3=33;"""
+
+    qt_sql """select k2,k3 from ${tableName} ORDER BY k3;"""
+
+    qt_sql """select k2,k3 from ${tableName} where k2!=0 ORDER BY k3;"""
+
+    sql """delete from ${tableName} where k2 not in (0) and k3=44;"""
+
+    qt_sql """select k2,k3 from ${tableName} ORDER BY k3;"""
+
+    qt_sql """select k2,k3 from ${tableName} where k2 not in (0) ORDER BY k3;"""
+
+    sql """delete from ${tableName} where k2=1 and k3 >= 11 and k3 <=200;"""
+
+    qt_sql """select k2,k3 from ${tableName} ORDER BY k3;"""
+
+    qt_sql """select k2,k3 from ${tableName} where k3 = 201 ORDER BY k3;"""
+
+
+    sql """truncate table ${tableName};"""
+
+    sql """insert into ${tableName} values(0,1,11),(0,1,22),(0,1,33),(0,1,44),(0,1,55),(0,1,66),(0,1,77),(0,1,88),(0,1,99),(0,1,100),(0,1,101),(0,1,102),(0,1,111),(0,1,122),(0,1,133),(0,1,144),(0,1,155),(0,1,166),(0,1,177),(0,1,188),(0,1,199),(0,1,200),(0,1,201),(0,1,202);"""
+
+    sql """delete from ${tableName} where k2=1 and k3 <=202 and k3 >= 33;"""
+
+    qt_sql """select k2,k3 from ${tableName} ORDER BY k3;"""
+
+    qt_sql """select k2,k3 from ${tableName} where k3 = 11 ORDER BY k3;"""
+
+    sql """ DROP TABLE IF EXISTS ${tableName} """
+
 }


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


[doris] 03/08: [enhancement](memory) reduce memory usage for failed broker loads (#16974)

Posted by mo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit b5fb28ee81b3ca0295644eb5f6524757a159a960
Author: Zhengguo Yang <ya...@gmail.com>
AuthorDate: Fri Feb 24 12:07:02 2023 +0800

    [enhancement](memory) reduce memory usage for failed broker loads (#16974)
    
    Reduce more memory usage for failed broker load msg in fe after pr  #15895
---
 .../src/main/java/org/apache/doris/load/loadv2/LoadLoadingTask.java  | 5 ++++-
 fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java        | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/LoadLoadingTask.java b/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/LoadLoadingTask.java
index 3a2974e69c..5a6e9cc4a0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/LoadLoadingTask.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/LoadLoadingTask.java
@@ -45,6 +45,7 @@ import org.apache.logging.log4j.Logger;
 
 import java.util.List;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 public class LoadLoadingTask extends LoadTask {
     private static final Logger LOG = LogManager.getLogger(LoadLoadingTask.class);
@@ -176,7 +177,9 @@ public class LoadLoadingTask extends LoadTask {
                         curCoordinator.getLoadCounters(),
                         curCoordinator.getTrackingUrl(),
                         TabletCommitInfo.fromThrift(curCoordinator.getCommitInfos()),
-                        ErrorTabletInfo.fromThrift(curCoordinator.getErrorTabletInfos()));
+                        ErrorTabletInfo.fromThrift(curCoordinator.getErrorTabletInfos()
+                                .stream().limit(Config.max_error_tablet_of_broker_load).collect(Collectors.toList())));
+                curCoordinator.getErrorTabletInfos().clear();
                 // Create profile of this task and add to the job profile.
                 createProfile(curCoordinator);
             } else {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java b/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java
index a646cb06bd..0542b96c70 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/Coordinator.java
@@ -843,7 +843,10 @@ public class Coordinator {
     private void updateErrorTabletInfos(List<TErrorTabletInfo> errorTabletInfos) {
         lock.lock();
         try {
-            this.errorTabletInfos.addAll(errorTabletInfos);
+            if (this.errorTabletInfos.size() <= Config.max_error_tablet_of_broker_load) {
+                this.errorTabletInfos.addAll(errorTabletInfos.stream().limit(Config.max_error_tablet_of_broker_load
+                        - this.errorTabletInfos.size()).collect(Collectors.toList()));
+            }
         } finally {
             lock.unlock();
         }


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


[doris] 04/08: [fix](stream_load) can abort 2pc stream load when table dropped #17088

Posted by mo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 10be08cece3edeada94d744442c200657eb1ca46
Author: xueweizhang <zx...@163.com>
AuthorDate: Sun Feb 26 11:20:41 2023 +0800

    [fix](stream_load) can abort 2pc stream load when table dropped #17088
    
    when stream load with 2pc, the table was droped before commit, it will get error commit or abort, trasaction can not finish.
    if commit or abort ,will get error:
    {
    "status": "ANALYSIS_ERROR",
    "msg": "errCode = 7, detailMessage = unknown table, tableId=52579"
    }
    after this pr, i can abort success.
---
 .../java/org/apache/doris/service/FrontendServiceImpl.java     | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
index cadc707bec..a2bfe74b78 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
@@ -761,14 +761,20 @@ public class FrontendServiceImpl implements FrontendService.Iface {
             throw new UserException("transaction [" + request.getTxnId() + "] not found");
         }
         List<Long> tableIdList = transactionState.getTableIdList();
-        List<Table> tableList = database.getTablesOnIdOrderOrThrowException(tableIdList);
+        String txnOperation = request.getOperation().trim();
+        List<Table> tableList = new ArrayList<>();
+        // if table was dropped, stream load must can abort.
+        if (txnOperation.equalsIgnoreCase("abort")) {
+            tableList = database.getTablesOnIdOrderIfExist(tableIdList);
+        } else {
+            tableList = database.getTablesOnIdOrderOrThrowException(tableIdList);
+        }
         for (Table table : tableList) {
             // check auth
             checkPasswordAndPrivs(cluster, request.getUser(), request.getPasswd(), request.getDb(), table.getName(),
                     request.getUserIp(), PrivPredicate.LOAD);
         }
 
-        String txnOperation = request.getOperation().trim();
         if (txnOperation.equalsIgnoreCase("commit")) {
             Env.getCurrentGlobalTransactionMgr()
                     .commitTransaction2PC(database, tableList, request.getTxnId(), 5000);


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