This is an automated email from the ASF dual-hosted git repository.
lijibing pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 1aea05b5b04 [improvement](statistics)Support partition row count
return -1 when it is not fully reported. (#41348) (#41408)
1aea05b5b04 is described below
commit 1aea05b5b04bb6d1995fe0abfb9ad43f7d92f27b
Author: Jibing-Li <[email protected]>
AuthorDate: Fri Sep 27 22:17:16 2024 +0800
[improvement](statistics)Support partition row count return -1 when it is
not fully reported. (#41348) (#41408)
backport: https://github.com/apache/doris/pull/41348
---
.../java/org/apache/doris/catalog/OlapTable.java | 32 ++++++++++++++-
.../org/apache/doris/catalog/OlapTableTest.java | 47 ++++++++++++++++++++++
2 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
index 9f4bb83375a..2f6f6b9e98b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
@@ -1402,18 +1402,48 @@ public class OlapTable extends Table implements
MTMVRelatedTableIf {
return getRowCountForIndex(baseIndexId, false);
}
+ /**
+ * @return If strict is true, -1 if there are some tablets whose row count
is not reported to FE
+ * If strict is false, return the sum of all partition's index
current reported row count.
+ */
public long getRowCountForIndex(long indexId, boolean strict) {
long rowCount = 0;
for (Map.Entry<Long, Partition> entry : idToPartition.entrySet()) {
MaterializedIndex index = entry.getValue().getIndex(indexId);
+ if (index == null) {
+ LOG.warn("Index {} not exist in partition {}, table {}, {}",
+ indexId, entry.getValue().getName(), id, name);
+ return -1;
+ }
if (strict && !index.getRowCountReported()) {
return -1;
}
- rowCount += (index == null || index.getRowCount() == -1) ? 0 :
index.getRowCount();
+ rowCount += index.getRowCount() == -1 ? 0 : index.getRowCount();
}
return rowCount;
}
+ /**
+ * @return If strict is true, -1 if there are some tablets whose row count
is not reported to FE.
+ * If strict is false, return the sum of partition's all indexes
current reported row count.
+ */
+ public long getRowCountForPartitionIndex(long partitionId, long indexId,
boolean strict) {
+ Partition partition = idToPartition.get(partitionId);
+ if (partition == null) {
+ LOG.warn("Partition {} not exist in table {}, {}", partitionId,
id, name);
+ return -1;
+ }
+ MaterializedIndex index = partition.getIndex(indexId);
+ if (index == null) {
+ LOG.warn("Index {} not exist in partition {}, table {}, {}",
indexId, partitionId, id, name);
+ return -1;
+ }
+ if (strict && !index.getRowCountReported()) {
+ return -1;
+ }
+ return index.getRowCount() == -1 ? 0 : index.getRowCount();
+ }
+
@Override
public long getAvgRowLength() {
long rowCount = 0;
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java
b/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java
index aa85178c08e..fd394353cd2 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/OlapTableTest.java
@@ -121,4 +121,51 @@ public class OlapTableTest {
Assert.assertFalse(olapTable.getTableProperty().getDynamicPartitionProperty().getEnable());
Assert.assertEquals((short) 3,
olapTable.getDefaultReplicaAllocation().getTotalReplicaNum());
}
+
+ @Test
+ public void testGetPartitionRowCount() {
+ OlapTable olapTable = new OlapTable();
+ // Partition is null.
+ long row = olapTable.getRowCountForPartitionIndex(0, 0, true);
+ Assert.assertEquals(-1, row);
+
+ // Index is null.
+ MaterializedIndex index = new MaterializedIndex(10,
MaterializedIndex.IndexState.NORMAL);
+ Partition partition = new Partition(11, "p1", index, null);
+ olapTable.addPartition(partition);
+ row = olapTable.getRowCountForPartitionIndex(11, 0, true);
+ Assert.assertEquals(-1, row);
+
+ // Strict is true and index is not reported.
+ index.setRowCountReported(false);
+ index.setRowCount(100);
+ row = olapTable.getRowCountForPartitionIndex(11, 10, true);
+ Assert.assertEquals(-1, row);
+
+ // Strict is true and index is reported.
+ index.setRowCountReported(true);
+ index.setRowCount(101);
+ row = olapTable.getRowCountForPartitionIndex(11, 10, true);
+ Assert.assertEquals(101, row);
+
+ // Strict is false and index is not reported.
+ index.setRowCountReported(false);
+ index.setRowCount(102);
+ row = olapTable.getRowCountForPartitionIndex(11, 10, false);
+ Assert.assertEquals(102, row);
+
+ // Reported row is -1, we should return 0
+ index.setRowCountReported(true);
+ index.setRowCount(-1);
+ row = olapTable.getRowCountForPartitionIndex(11, 10, false);
+ Assert.assertEquals(0, row);
+
+ // Return reported row.
+ index.setRowCountReported(true);
+ index.setRowCount(103);
+ row = olapTable.getRowCountForPartitionIndex(11, 10, false);
+ Assert.assertEquals(103, row);
+
+ olapTable.getRowCountForPartitionIndex(11, 10, true);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]