This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 1273ec4a044 [minor](stats) Update olap table row count after analyze
(#27858)
1273ec4a044 is described below
commit 1273ec4a044d4cfa409ca2dda8aac49093bc2a50
Author: AKIRA <[email protected]>
AuthorDate: Fri Dec 1 15:07:34 2023 +0800
[minor](stats) Update olap table row count after analyze (#27858)
pick from master #27814
---
.../apache/doris/statistics/TableStatsMeta.java | 25 +++++++++---
.../doris/statistics/AnalysisManagerTest.java | 2 +-
.../statistics/StatisticsAutoCollectorTest.java | 2 +-
.../doris/statistics/TableStatsMetaTest.java | 46 ++++++++++++++++++++++
4 files changed, 67 insertions(+), 8 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/statistics/TableStatsMeta.java
b/fe/fe-core/src/main/java/org/apache/doris/statistics/TableStatsMeta.java
index 97a2cd15186..04b9e3486b0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/statistics/TableStatsMeta.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/TableStatsMeta.java
@@ -18,6 +18,7 @@
package org.apache.doris.statistics;
import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
@@ -25,6 +26,7 @@ import org.apache.doris.persist.gson.GsonUtils;
import org.apache.doris.statistics.AnalysisInfo.JobType;
import org.apache.doris.statistics.util.StatisticsUtil;
+import com.google.common.annotations.VisibleForTesting;
import com.google.gson.annotations.SerializedName;
import java.io.DataInput;
@@ -54,7 +56,7 @@ public class TableStatsMeta implements Writable {
// Used for external table.
@SerializedName("rowCount")
- public final long rowCount;
+ public long rowCount;
@SerializedName("updateTime")
public long updatedTime;
@@ -65,6 +67,12 @@ public class TableStatsMeta implements Writable {
@SerializedName("trigger")
public JobType jobType;
+ @VisibleForTesting
+ public TableStatsMeta() {
+ tblId = 0;
+ idxId = 0;
+ }
+
// It's necessary to store these fields separately from AnalysisInfo,
since the lifecycle between AnalysisInfo
// and TableStats is quite different.
public TableStatsMeta(long rowCount, AnalysisInfo analyzedJob, TableIf
table) {
@@ -136,11 +144,16 @@ public class TableStatsMeta implements Writable {
}
}
jobType = analyzedJob.jobType;
- if (tableIf != null && analyzedJob.colToPartitions.keySet()
- .containsAll(tableIf.getBaseSchema().stream()
- .filter(c ->
!StatisticsUtil.isUnsupportedType(c.getType()))
- .map(Column::getName).collect(Collectors.toSet()))) {
- updatedRows.set(0);
+ if (tableIf != null) {
+ if (tableIf instanceof OlapTable) {
+ rowCount = tableIf.getRowCount();
+ }
+ if (analyzedJob.colToPartitions.keySet()
+ .containsAll(tableIf.getBaseSchema().stream()
+ .filter(c ->
!StatisticsUtil.isUnsupportedType(c.getType()))
+
.map(Column::getName).collect(Collectors.toSet()))) {
+ updatedRows.set(0);
+ }
}
}
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisManagerTest.java
b/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisManagerTest.java
index 72754943404..7c57a67f889 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisManagerTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/statistics/AnalysisManagerTest.java
@@ -379,7 +379,7 @@ public class AnalysisManagerTest {
new MockUp<OlapTable>() {
int count = 0;
- int[] rowCount = new int[]{100, 200};
+ int[] rowCount = new int[]{100, 100, 200, 200};
final Column c = new Column("col1", PrimitiveType.INT);
@Mock
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/statistics/StatisticsAutoCollectorTest.java
b/fe/fe-core/src/test/java/org/apache/doris/statistics/StatisticsAutoCollectorTest.java
index 732196ef31b..56475201765 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/statistics/StatisticsAutoCollectorTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/statistics/StatisticsAutoCollectorTest.java
@@ -471,7 +471,7 @@ public class StatisticsAutoCollectorTest {
new MockUp<OlapTable>() {
int count = 0;
- int[] rowCounts = {100, 0};
+ int[] rowCounts = {100, 100, 100, 0, 0, 0, 0};
@Mock
public long getRowCount() {
return rowCounts[count++];
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/statistics/TableStatsMetaTest.java
b/fe/fe-core/src/test/java/org/apache/doris/statistics/TableStatsMetaTest.java
new file mode 100644
index 00000000000..b5e73ba09da
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/statistics/TableStatsMetaTest.java
@@ -0,0 +1,46 @@
+// 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.OlapTable;
+
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+
+class TableStatsMetaTest {
+
+ @Test
+ void update(@Mocked OlapTable table) {
+ new MockUp<OlapTable>() {
+ @Mock
+ public long getRowCount() {
+ return 4;
+ }
+ };
+ TableStatsMeta tableStatsMeta = new TableStatsMeta();
+ AnalysisInfo jobInfo = new
AnalysisInfoBuilder().setColToPartitions(new HashMap<>())
+ .setColName("col1").build();
+ tableStatsMeta.update(jobInfo, table);
+ Assertions.assertEquals(4, tableStatsMeta.rowCount);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]