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

yiguolei 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 fd4d1f4e4f6 [chore](table) Add batch method to get visible version of 
the olap table (#38949) (#39495)
fd4d1f4e4f6 is described below

commit fd4d1f4e4f6be99468193e97259232b759421a22
Author: walter <[email protected]>
AuthorDate: Sat Aug 17 16:55:06 2024 +0800

    [chore](table) Add batch method to get visible version of the olap table 
(#38949) (#39495)
    
    Cherry-pick #38949
---
 .../java/org/apache/doris/catalog/OlapTable.java   | 33 +++++++++++++++++++++-
 1 file changed, 32 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 f62e5984e19..db5c756772e 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
@@ -46,6 +46,7 @@ import org.apache.doris.common.io.DeepCopy;
 import org.apache.doris.common.io.Text;
 import org.apache.doris.common.util.PropertyAnalyzer;
 import org.apache.doris.common.util.Util;
+import org.apache.doris.datasource.InternalCatalog;
 import org.apache.doris.mtmv.MTMVRelatedTableIf;
 import org.apache.doris.mtmv.MTMVSnapshotIf;
 import org.apache.doris.mtmv.MTMVVersionSnapshot;
@@ -2156,7 +2157,6 @@ public class OlapTable extends Table implements 
MTMVRelatedTableIf {
         return baseIndexMeta.getSchemaVersion();
     }
 
-
     public void setEnableSingleReplicaCompaction(boolean 
enableSingleReplicaCompaction) {
         if (tableProperty == null) {
             tableProperty = new TableProperty(new HashMap<>());
@@ -2773,6 +2773,37 @@ public class OlapTable extends Table implements 
MTMVRelatedTableIf {
         return tableAttributes.getVisibleVersion();
     }
 
+    // Get the table versions in batch.
+    public static List<Long> getVisibleVersionByTableIds(Collection<Long> 
tableIds) {
+        List<OlapTable> tables = new ArrayList<>();
+
+        InternalCatalog catalog = Env.getCurrentEnv().getInternalCatalog();
+        for (long tableId : tableIds) {
+            Table table = catalog.getTableByTableId(tableId);
+            if (table == null) {
+                throw new RuntimeException("get table visible version failed, 
no such table " + tableId + " exists");
+            }
+            if (table.getType() != TableType.OLAP) {
+                throw new RuntimeException(
+                        "get table visible version failed, table " + tableId + 
" is not a OLAP table");
+            }
+            tables.add((OlapTable) table);
+        }
+
+        return getVisibleVersionInBatch(tables);
+    }
+
+    // Get the table versions in batch.
+    public static List<Long> getVisibleVersionInBatch(Collection<OlapTable> 
tables) {
+        if (tables.isEmpty()) {
+            return new ArrayList<>();
+        }
+
+        return tables.stream()
+                .map(table -> table.tableAttributes.getVisibleVersion())
+                .collect(Collectors.toList());
+    }
+
     public long getVisibleVersionTime() {
         return tableAttributes.getVisibleVersionTime();
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to