You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by bo...@apache.org on 2026/04/20 13:43:48 UTC

(impala) branch master updated (61bc940b5 -> 6128f6b18)

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

asf-gitbox-commits pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git


    from 61bc940b5 IMPALA-14902: Bump Maven to 3.9.15
     new 71c63ed61 IMPALA-14806: Cache IcebergContentFileStore
     new 6128f6b18 IMPALA-14825: Add syntactic sugar for Iceberg Row Lineage data

The 2 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:
 common/thrift/CatalogObjects.thrift                |   4 +-
 .../java/org/apache/impala/analysis/Analyzer.java  |   3 +
 .../org/apache/impala/analysis/SelectList.java     |  18 +-
 .../org/apache/impala/catalog/FeIcebergTable.java  |  13 +-
 .../impala/catalog/IcebergContentFileStore.java    |  38 +++-
 .../org/apache/impala/catalog/IcebergTable.java    |  20 +-
 .../org/apache/impala/catalog/VirtualColumn.java   |  13 ++
 .../impala/catalog/local/CatalogdMetaProvider.java |  64 +++++-
 .../impala/catalog/local/DirectMetaProvider.java   |   7 +
 .../impala/catalog/local/IcebergMetaProvider.java  |  29 ++-
 .../impala/catalog/local/LocalIcebergTable.java    |  16 +-
 .../apache/impala/catalog/local/MetaProvider.java  |  19 ++
 .../catalog/local/MetaProviderDecorator.java       |   5 +
 .../impala/catalog/local/MultiMetaProvider.java    |   8 +
 .../rewrite/IcebergVirtualColumnRewriteRule.java   |  64 ++++++
 .../java/org/apache/impala/util/IcebergUtil.java   |  62 ++++--
 .../impala/catalog/local/LocalCatalogTest.java     |   2 +-
 .../catalog/local/MetaProviderDecoratorTest.java   |   2 +-
 .../queries/QueryTest/iceberg-v3-optimize.test     |  48 +++--
 .../queries/QueryTest/iceberg-v3-row-lineage.test  | 236 +++++++++++++++++++++
 .../ranger_iceberg_v3_column_masking.test          |  27 +++
 tests/authorization/test_ranger.py                 |  46 ++++
 22 files changed, 675 insertions(+), 69 deletions(-)
 create mode 100644 fe/src/main/java/org/apache/impala/rewrite/IcebergVirtualColumnRewriteRule.java
 create mode 100644 testdata/workloads/functional-query/queries/QueryTest/ranger_iceberg_v3_column_masking.test


(impala) 02/02: IMPALA-14825: Add syntactic sugar for Iceberg Row Lineage data

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

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 6128f6b18ecaad8ec7c6f99048d4d28cbf01e6bd
Author: Zoltan Borok-Nagy <bo...@cloudera.com>
AuthorDate: Thu Apr 9 17:12:04 2026 +0200

    IMPALA-14825: Add syntactic sugar for Iceberg Row Lineage data
    
    Currently Row Lineage fields can only be queried by complex expressions:
    
    * row-id:
      COALESCE(_file_row_id,
               ICEBERG__FIRST__ROW__ID + FILE__POSITION)
    * last-updated-sequence-number
      COALESCE(_file_last_updated_sequence_number,
               ICEBERG__DATA__SEQUENCE__NUMBER)
    
    This patch adds _row_id and _last_updated_sequence_number virtual
    columns to Iceberg V3 tables as syntactic sugars, i.e. they get
    re-written during analysis to the corresponding COALESCE() expr.
    
    _row_id and _last_updated_sequence_number are being used by other
    engines as well, e.g. Spark.
    
    Testing:
    * e2e tests added
    * column-masking tests
    
    Generated-by: Claude Sonnet 4.6
    Generated-by: Claude Opus 4.6
    
    Change-Id: I02aceeb0969243ba6d28e4c0c97d5dd7a5afd765
    Reviewed-on: http://gerrit.cloudera.org:8080/24184
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 common/thrift/CatalogObjects.thrift                |   4 +-
 .../java/org/apache/impala/analysis/Analyzer.java  |   3 +
 .../org/apache/impala/analysis/SelectList.java     |  18 +-
 .../org/apache/impala/catalog/IcebergTable.java    |   4 +
 .../org/apache/impala/catalog/VirtualColumn.java   |  13 ++
 .../rewrite/IcebergVirtualColumnRewriteRule.java   |  64 ++++++
 .../java/org/apache/impala/util/IcebergUtil.java   |  62 ++++--
 .../queries/QueryTest/iceberg-v3-optimize.test     |  48 +++--
 .../queries/QueryTest/iceberg-v3-row-lineage.test  | 236 +++++++++++++++++++++
 .../ranger_iceberg_v3_column_masking.test          |  27 +++
 tests/authorization/test_ranger.py                 |  46 ++++
 11 files changed, 492 insertions(+), 33 deletions(-)

diff --git a/common/thrift/CatalogObjects.thrift b/common/thrift/CatalogObjects.thrift
index 56a6d645c..b8e51f562 100644
--- a/common/thrift/CatalogObjects.thrift
+++ b/common/thrift/CatalogObjects.thrift
@@ -96,7 +96,9 @@ enum TVirtualColumnType {
   ICEBERG_DATA_SEQUENCE_NUMBER,
   PARTITION_VALUE_SERIALIZED,
   BUCKET_ID,
-  ICEBERG_FIRST_ROW_ID
+  ICEBERG_FIRST_ROW_ID,
+  ICEBERG_ROW_ID,
+  ICEBERG_LAST_UPDATED_SEQUENCE_NUMBER
 }
 
 // TODO: Since compression is also enabled for Kudu columns, we should
diff --git a/fe/src/main/java/org/apache/impala/analysis/Analyzer.java b/fe/src/main/java/org/apache/impala/analysis/Analyzer.java
index a8357e972..6f92ce978 100644
--- a/fe/src/main/java/org/apache/impala/analysis/Analyzer.java
+++ b/fe/src/main/java/org/apache/impala/analysis/Analyzer.java
@@ -104,6 +104,7 @@ import org.apache.impala.rewrite.ExprRewriter;
 import org.apache.impala.rewrite.ExtractCommonConjunctRule;
 import org.apache.impala.rewrite.ExtractCompoundVerticalBarExprRule;
 import org.apache.impala.rewrite.FoldConstantsRule;
+import org.apache.impala.rewrite.IcebergVirtualColumnRewriteRule;
 import org.apache.impala.rewrite.NormalizeBinaryPredicatesRule;
 import org.apache.impala.rewrite.NormalizeCountStarRule;
 import org.apache.impala.rewrite.NormalizeExprsRule;
@@ -679,6 +680,8 @@ public class Analyzer {
       // expr rewrites can be disabled via a query option. When rewrites are enabled
       // BetweenPredicates should be rewritten first to help trigger other rules.
       rules.add(BetweenToCompoundRule.INSTANCE);
+      // Iceberg V3 syntactic-sugar virtual columns must be rewritten before planning.
+      rules.add(IcebergVirtualColumnRewriteRule.INSTANCE);
       // Binary predicates must be rewritten to a canonical form for both Kudu predicate
       // pushdown and Parquet row group pruning based on min/max statistics.
       rules.add(NormalizeBinaryPredicatesRule.INSTANCE);
diff --git a/fe/src/main/java/org/apache/impala/analysis/SelectList.java b/fe/src/main/java/org/apache/impala/analysis/SelectList.java
index cb52ce0c8..b3b54cd91 100644
--- a/fe/src/main/java/org/apache/impala/analysis/SelectList.java
+++ b/fe/src/main/java/org/apache/impala/analysis/SelectList.java
@@ -95,10 +95,24 @@ public class SelectList {
   public void rewriteExprs(ExprRewriter rewriter, Analyzer analyzer)
       throws AnalysisException {
     List<Subquery> subqueryExprs = new ArrayList<>();
-    for (SelectListItem item: items_) {
+    for (int i = 0; i < items_.size(); ++i) {
+      SelectListItem item = items_.get(i);
       if (item.isStar()) continue;
       if (item.isSkipExprRewrite()) continue;
-      item.setExpr(rewriter.rewrite(item.getExpr(), analyzer));
+      Expr origExpr = item.getExpr();
+      Expr newExpr = rewriter.rewrite(origExpr, analyzer);
+      if (newExpr != origExpr && item.getAlias() == null
+          && origExpr instanceof SlotRef) {
+        // The expression was rewritten (e.g., an Iceberg virtual-column SlotRef
+        // replaced by its definition). Preserve the original column label as an
+        // explicit alias so that re-analysis does not change the output column
+        // name, which would break outer-query references (e.g., in CTEs).
+        String colLabel = item.toColumnLabel(i, false);
+        items_.set(i, new SelectListItem(newExpr, colLabel));
+        item = items_.get(i);
+      } else {
+        item.setExpr(newExpr);
+      }
       item.getExpr().collect(Subquery.class, subqueryExprs);
     }
     for (Subquery s : subqueryExprs) {
diff --git a/fe/src/main/java/org/apache/impala/catalog/IcebergTable.java b/fe/src/main/java/org/apache/impala/catalog/IcebergTable.java
index 29357baf1..9d5b565cd 100644
--- a/fe/src/main/java/org/apache/impala/catalog/IcebergTable.java
+++ b/fe/src/main/java/org/apache/impala/catalog/IcebergTable.java
@@ -746,6 +746,10 @@ public class IcebergTable extends Table implements FeIcebergTable {
     addVirtualColumn(VirtualColumn.ICEBERG_PARTITION_SERIALIZED);
     addVirtualColumn(VirtualColumn.ICEBERG_DATA_SEQUENCE_NUMBER);
     addVirtualColumn(VirtualColumn.ICEBERG_FIRST_ROW_ID);
+    if (getFormatVersion() >= 3) {
+      addVirtualColumn(VirtualColumn.ICEBERG_ROW_ID);
+      addVirtualColumn(VirtualColumn.ICEBERG_LAST_UPDATED_SEQUENCE_NUMBER);
+    }
   }
 
   private void addHiddenColumns() {
diff --git a/fe/src/main/java/org/apache/impala/catalog/VirtualColumn.java b/fe/src/main/java/org/apache/impala/catalog/VirtualColumn.java
index 37f20bc44..641976e30 100644
--- a/fe/src/main/java/org/apache/impala/catalog/VirtualColumn.java
+++ b/fe/src/main/java/org/apache/impala/catalog/VirtualColumn.java
@@ -54,6 +54,16 @@ public class VirtualColumn extends Column {
       Type.BIGINT,
       TVirtualColumnType.ICEBERG_FIRST_ROW_ID);
 
+  // Iceberg V3 syntactic-sugar virtual columns (rewritten during analysis).
+  public static VirtualColumn ICEBERG_ROW_ID = new VirtualColumn(
+      "_row_id",
+      Type.BIGINT,
+      TVirtualColumnType.ICEBERG_ROW_ID);
+  public static VirtualColumn ICEBERG_LAST_UPDATED_SEQUENCE_NUMBER = new VirtualColumn(
+      "_last_updated_sequence_number",
+      Type.BIGINT,
+      TVirtualColumnType.ICEBERG_LAST_UPDATED_SEQUENCE_NUMBER);
+
   // Paimon-related virtual columns.
   public static VirtualColumn PARTITION_VALUE_SERIALIZED = new
           VirtualColumn("PARTITION__VALUE__SERIALIZED", Type.BINARY,
@@ -72,6 +82,9 @@ public class VirtualColumn extends Column {
       case PARTITION_VALUE_SERIALIZED: return PARTITION_VALUE_SERIALIZED;
       case BUCKET_ID: return BUCKET_ID;
       case ICEBERG_FIRST_ROW_ID: return ICEBERG_FIRST_ROW_ID;
+      case ICEBERG_ROW_ID: return ICEBERG_ROW_ID;
+      case ICEBERG_LAST_UPDATED_SEQUENCE_NUMBER:
+          return ICEBERG_LAST_UPDATED_SEQUENCE_NUMBER;
       default: break;
     }
     return null;
diff --git a/fe/src/main/java/org/apache/impala/rewrite/IcebergVirtualColumnRewriteRule.java b/fe/src/main/java/org/apache/impala/rewrite/IcebergVirtualColumnRewriteRule.java
new file mode 100644
index 000000000..1e7b9b0ca
--- /dev/null
+++ b/fe/src/main/java/org/apache/impala/rewrite/IcebergVirtualColumnRewriteRule.java
@@ -0,0 +1,64 @@
+// 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.impala.rewrite;
+
+import org.apache.impala.analysis.Analyzer;
+import org.apache.impala.analysis.Expr;
+import org.apache.impala.analysis.SlotDescriptor;
+import org.apache.impala.analysis.SlotRef;
+import org.apache.impala.common.AnalysisException;
+import org.apache.impala.thrift.TVirtualColumnType;
+import org.apache.impala.util.IcebergUtil;
+
+/**
+ * Rewrites references to the syntactic-sugar virtual columns of Iceberg V3 tables
+ * into their equivalent COALESCE expressions:
+ *   _row_id ->
+ *       COALESCE(_file_row_id, ICEBERG__FIRST__ROW__ID + FILE__POSITION)
+ *   _last_updated_sequence_number ->
+ *       COALESCE(_file_last_updated_sequence_number,
+ *           ICEBERG__DATA__SEQUENCE__NUMBER)
+ *
+ * This rule runs as a mandatory rewrite so that these virtual columns are never
+ * visible to the planner or backend.
+ */
+public class IcebergVirtualColumnRewriteRule implements ExprRewriteRule {
+  public static final ExprRewriteRule INSTANCE = new IcebergVirtualColumnRewriteRule();
+
+  @Override
+  public Expr apply(Expr expr, Analyzer analyzer) throws AnalysisException {
+    if (!(expr instanceof SlotRef)) return expr;
+    SlotRef slotRef = (SlotRef) expr;
+    if (!slotRef.isAnalyzed()) return expr;
+    SlotDescriptor desc = slotRef.getDesc();
+    if (desc == null) return expr;
+
+    String tableAlias = desc.getParent().getAlias();
+    if (tableAlias == null) return expr;
+
+    TVirtualColumnType colType = desc.getVirtualColumnType();
+    switch (colType) {
+      case ICEBERG_ROW_ID:
+        return IcebergUtil.buildRowIdExpr(tableAlias);
+      case ICEBERG_LAST_UPDATED_SEQUENCE_NUMBER:
+        return IcebergUtil.buildLastUpdatedSeqNoExpr(tableAlias);
+      default:
+        return expr;
+    }
+  }
+}
diff --git a/fe/src/main/java/org/apache/impala/util/IcebergUtil.java b/fe/src/main/java/org/apache/impala/util/IcebergUtil.java
index 16d56b08e..ba9ba4c2b 100644
--- a/fe/src/main/java/org/apache/impala/util/IcebergUtil.java
+++ b/fe/src/main/java/org/apache/impala/util/IcebergUtil.java
@@ -83,6 +83,7 @@ import org.apache.impala.analysis.IcebergPartitionField;
 import org.apache.impala.analysis.IcebergPartitionSpec;
 import org.apache.impala.analysis.IcebergPartitionTransform;
 import org.apache.impala.analysis.NumericLiteral;
+import org.apache.impala.analysis.Path;
 import org.apache.impala.analysis.SlotRef;
 import org.apache.impala.analysis.StatementBase;
 import org.apache.impala.analysis.StringLiteral;
@@ -1592,32 +1593,66 @@ public class IcebergUtil {
       List<Expr> resultExprs) throws AnalysisException {
     FeIcebergTable table = (FeIcebergTable) tableRef.getTable();
     if (table.getFormatVersion() < 3) return;
-    resultExprs.add(IcebergUtil.getRowIdExpr(analyzer, tableRef));
-    resultExprs.add(IcebergUtil.getLastUpdatedSeqNoExpr(analyzer, tableRef));
+    resultExprs.add(getAnalyzedRowIdExpr(analyzer, tableRef));
+    resultExprs.add(getAnalyzedLastUpdatedSeqNoExpr(analyzer, tableRef));
     Preconditions.checkState(resultExprs.size() == table.getColumns().size());
   }
 
+  /**
+   * Builds an unanalyzed expression equivalent to:
+   *   COALESCE(_file_row_id, ICEBERG__FIRST__ROW__ID + FILE__POSITION)
+   */
+  public static Expr buildRowIdExpr(String tableAlias) {
+    SlotRef fileRowId = new SlotRef(
+        Path.createRawPath(tableAlias, "_file_row_id"));
+    SlotRef firstRowId = new SlotRef(
+        Path.createRawPath(tableAlias, "ICEBERG__FIRST__ROW__ID"));
+    SlotRef filePosition = new SlotRef(
+        Path.createRawPath(tableAlias, "FILE__POSITION"));
+    Expr addExpr = new ArithmeticExpr(
+        ArithmeticExpr.Operator.ADD, firstRowId, filePosition);
+    FunctionCallExpr fnCall = new FunctionCallExpr(
+        "coalesce", Arrays.asList(fileRowId, addExpr));
+    fnCall.setIsInternalFnCall(true);
+    return fnCall;
+  }
+
+  /**
+   * Builds an unanalyzed expression equivalent to:
+   *   COALESCE(_file_last_updated_sequence_number, ICEBERG__DATA__SEQUENCE__NUMBER)
+   */
+  public static Expr buildLastUpdatedSeqNoExpr(String tableAlias) {
+    SlotRef fileLastUpdatedSeqNo = new SlotRef(
+        Path.createRawPath(tableAlias, "_file_last_updated_sequence_number"));
+    SlotRef dataSeqNo = new SlotRef(
+        Path.createRawPath(tableAlias, "ICEBERG__DATA__SEQUENCE__NUMBER"));
+    FunctionCallExpr fnCall = new FunctionCallExpr(
+        "coalesce", Arrays.asList(fileLastUpdatedSeqNo, dataSeqNo));
+    fnCall.setIsInternalFnCall(true);
+    return fnCall;
+  }
+
   /**
    * Returns COALESCE(_file_row_id, ICEBERG__FIRST__ROW__ID + FILE__POSITION).
    */
-  public static Expr getRowIdExpr(Analyzer analyzer, TableRef tableRef)
+  public static Expr getAnalyzedRowIdExpr(Analyzer analyzer, TableRef tableRef)
       throws AnalysisException {
-    Expr addExpr = new ArithmeticExpr(ArithmeticExpr.Operator.ADD,
-        createSlotRef(analyzer, tableRef, "ICEBERG__FIRST__ROW__ID"),
-        createSlotRef(analyzer, tableRef, "FILE__POSITION"));
-    return createCoalesceFn(analyzer,
-        createSlotRef(analyzer, tableRef, "_file_row_id"), addExpr);
+    Expr expr = buildRowIdExpr(tableRef.getUniqueAlias());
+    expr.analyze(analyzer);
+    analyzer.materializeSlots(expr);
+    return expr;
   }
 
   /**
    * Returns
    * COALESCE(_file_last_updated_sequence_number, ICEBERG__DATA__SEQUENCE__NUMBER).
    */
-  public static Expr getLastUpdatedSeqNoExpr(Analyzer analyzer, TableRef tableRef)
+  public static Expr getAnalyzedLastUpdatedSeqNoExpr(Analyzer analyzer, TableRef tableRef)
       throws AnalysisException {
-    return createCoalesceFn(analyzer,
-        createSlotRef(analyzer, tableRef, "_file_last_updated_sequence_number"),
-        createSlotRef(analyzer, tableRef, "ICEBERG__DATA__SEQUENCE__NUMBER"));
+    Expr expr = buildLastUpdatedSeqNoExpr(tableRef.getUniqueAlias());
+    expr.analyze(analyzer);
+    analyzer.materializeSlots(expr);
+    return expr;
   }
 
   /**
@@ -1639,8 +1674,7 @@ public class IcebergUtil {
 
   public static SlotRef createSlotRef(Analyzer analyzer, TableRef tableRef,
       String colName) throws AnalysisException {
-    List<String> path = org.apache.impala.analysis.Path
-        .createRawPath(tableRef.getUniqueAlias(), colName);
+    List<String> path = Path.createRawPath(tableRef.getUniqueAlias(), colName);
     SlotRef ref = new SlotRef(path);
     ref.analyze(analyzer);
     return ref;
diff --git a/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-optimize.test b/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-optimize.test
index ae620692d..e29a392a9 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-optimize.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-optimize.test
@@ -89,34 +89,38 @@ INSERT INTO optimize_part VALUES (1,'aa'),(2,'ab');
 INSERT INTO optimize_part VALUES (3,'ac'),(4,'ad');
 INSERT INTO optimize_part VALUES (5,'ba'),(6,'bb');
 
-SELECT _file_row_id, ICEBERG__FIRST__ROW__ID, _file_last_updated_sequence_number, ICEBERG__DATA__SEQUENCE__NUMBER, *
+SELECT _file_row_id, ICEBERG__FIRST__ROW__ID, _row_id, '|',
+       _file_last_updated_sequence_number, ICEBERG__DATA__SEQUENCE__NUMBER, _last_updated_sequence_number, '|',
+       *
 FROM optimize_part;
 ---- RESULTS
-NULL,0,NULL,1,1,'aa'
-NULL,0,NULL,1,2,'ab'
-NULL,2,NULL,2,3,'ac'
-NULL,2,NULL,2,4,'ad'
-NULL,4,NULL,3,5,'ba'
-NULL,4,NULL,3,6,'bb'
+NULL,0,0,'|',NULL,1,1,'|',1,'aa'
+NULL,0,1,'|',NULL,1,1,'|',2,'ab'
+NULL,2,2,'|',NULL,2,2,'|',3,'ac'
+NULL,2,3,'|',NULL,2,2,'|',4,'ad'
+NULL,4,4,'|',NULL,3,3,'|',5,'ba'
+NULL,4,5,'|',NULL,3,3,'|',6,'bb'
 ---- TYPES
-BIGINT,BIGINT,BIGINT,BIGINT,INT,STRING
+BIGINT,BIGINT,BIGINT,STRING,BIGINT,BIGINT,BIGINT,STRING,INT,STRING
 ====
 ---- QUERY
 # With FILE_SIZE_THRESHOLD_MB specified, OPTIMIZE only compact partitions with at least
 # two data files.
 OPTIMIZE TABLE optimize_part (FILE_SIZE_THRESHOLD_MB=10);
 
-SELECT _file_row_id, _file_last_updated_sequence_number, *
+SELECT _file_row_id, _row_id, '|',
+       _file_last_updated_sequence_number, _last_updated_sequence_number, '|',
+       *
 FROM optimize_part;
 ---- RESULTS
-0,1,1,'aa'
-1,1,2,'ab'
-2,2,3,'ac'
-3,2,4,'ad'
-NULL,NULL,5,'ba'
-NULL,NULL,6,'bb'
+0,0,'|',1,1,'|',1,'aa'
+1,1,'|',1,1,'|',2,'ab'
+2,2,'|',2,2,'|',3,'ac'
+3,3,'|',2,2,'|',4,'ad'
+NULL,4,'|',NULL,3,'|',5,'ba'
+NULL,5,'|',NULL,3,'|',6,'bb'
 ---- TYPES
-BIGINT,BIGINT,INT,STRING
+BIGINT,BIGINT,STRING,BIGINT,BIGINT,STRING,INT,STRING
 ====
 ---- QUERY
 # Let's do a full compaction on the partially compacted table.
@@ -205,4 +209,16 @@ FROM optimize_upgraded;
 2,8,3,6,3
 ---- TYPES
 BIGINT,BIGINT,BIGINT,BIGINT,INT
+====
+---- QUERY
+SELECT _file_row_id, ICEBERG__FIRST__ROW__ID, _row_id, '|',
+       _file_last_updated_sequence_number, ICEBERG__DATA__SEQUENCE__NUMBER, _last_updated_sequence_number, '|',
+       *
+FROM optimize_upgraded;
+---- RESULTS
+0,6,0,'|',1,6,1,'|',1
+1,7,1,'|',2,6,2,'|',2
+2,8,2,'|',3,6,3,'|',3
+---- TYPES
+BIGINT,BIGINT,BIGINT,STRING,BIGINT,BIGINT,BIGINT,STRING,INT
 ====
\ No newline at end of file
diff --git a/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-row-lineage.test b/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-row-lineage.test
index 8c92f88fc..ad557cf65 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-row-lineage.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-row-lineage.test
@@ -77,6 +77,18 @@ from iceberg_v3_row_lineage for system_version as of 2872597867664652808;
 INT,BIGINT,BIGINT
 ====
 ---- QUERY
+# Use syntactic sugars '_row_id' and '_last_updated_sequence_number' in time-travel query.
+# They should provide the same results as the expressions in the previous query.
+select i, _row_id, _last_updated_sequence_number
+from iceberg_v3_row_lineage for system_version as of 2872597867664652808;
+---- RESULTS
+1,0,1
+2,1,2
+3,2,3
+---- TYPES
+INT,BIGINT,BIGINT
+====
+---- QUERY
 # Calculate 'row_id' and 'last_updated_sequence_number'
 select i, coalesce(_file_row_id, ICEBERG__FIRST__ROW__ID + FILE__POSITION),
           coalesce(_file_last_updated_sequence_number, ICEBERG__DATA__SEQUENCE__NUMBER)
@@ -89,6 +101,16 @@ from iceberg_v3_row_lineage;
 INT,BIGINT,BIGINT
 ====
 ---- QUERY
+select i, _row_id, _last_updated_sequence_number
+from iceberg_v3_row_lineage;
+---- RESULTS
+1,0,1
+2,1,2
+3,2,3
+---- TYPES
+INT,BIGINT,BIGINT
+====
+---- QUERY
 INSERT INTO iceberg_v3_row_lineage (i) VALUES (4);
 ====
 ---- QUERY
@@ -422,6 +444,17 @@ from iceberg_v3_row_lineage_orc for system_version as of 7033898671372067760;
 INT,BIGINT,BIGINT
 ====
 ---- QUERY
+# Use syntactic sugars '_row_id' and '_last_updated_sequence_number' in time-travel query.
+select i, _row_id, _last_updated_sequence_number
+from iceberg_v3_row_lineage_orc for system_version as of 7033898671372067760;
+---- RESULTS
+1,0,1
+2,1,2
+3,2,3
+---- TYPES
+INT,BIGINT,BIGINT
+====
+---- QUERY
 # Calculate 'row_id' and 'last_updated_sequence_number'
 select i, coalesce(_file_row_id, ICEBERG__FIRST__ROW__ID + FILE__POSITION),
           coalesce(_file_last_updated_sequence_number, ICEBERG__DATA__SEQUENCE__NUMBER)
@@ -434,6 +467,16 @@ from iceberg_v3_row_lineage_orc;
 INT,BIGINT,BIGINT
 ====
 ---- QUERY
+select i, _row_id, _last_updated_sequence_number
+from iceberg_v3_row_lineage_orc;
+---- RESULTS
+1,0,1
+2,1,2
+3,2,3
+---- TYPES
+INT,BIGINT,BIGINT
+====
+---- QUERY
 compute stats iceberg_v3_row_lineage_orc;
 show table stats iceberg_v3_row_lineage_orc;
 ---- RESULTS
@@ -500,3 +543,196 @@ alter table iceberg_v3_row_lineage_orc drop column _file_last_updated_sequence_n
 ---- CATCH
 cannot be dropped.
 ====
+---- QUERY
+# Query syntactic sugar columns of row lineage fields.
+select i, _row_id, _last_updated_sequence_number from iceberg_v3_row_lineage;
+---- RESULTS
+1,0,1
+2,1,2
+3,2,3
+---- TYPES
+INT,BIGINT,BIGINT
+---- LABELS
+i,_row_id,_last_updated_sequence_number
+====
+---- QUERY
+# Syntactic sugar column results match the explicit COALESCE expressions.
+select i,
+    _row_id = coalesce(_file_row_id, ICEBERG__FIRST__ROW__ID + FILE__POSITION),
+    _last_updated_sequence_number
+        = coalesce(_file_last_updated_sequence_number, ICEBERG__DATA__SEQUENCE__NUMBER)
+from iceberg_v3_row_lineage;
+---- RESULTS
+1,true,true
+2,true,true
+3,true,true
+---- TYPES
+INT,BOOLEAN,BOOLEAN
+====
+---- QUERY
+# WHERE clause: filter using _row_id.
+select i from iceberg_v3_row_lineage where _row_id = 1;
+---- RESULTS
+2
+---- TYPES
+INT
+====
+---- QUERY
+# WHERE clause: filter using _last_updated_sequence_number.
+select i from iceberg_v3_row_lineage where _last_updated_sequence_number > 1;
+---- RESULTS
+2
+3
+---- TYPES
+INT
+====
+---- QUERY
+# ORDER BY using _row_id (descending).
+select i, _row_id from iceberg_v3_row_lineage order by _row_id desc;
+---- RESULTS
+3,2
+2,1
+1,0
+---- TYPES
+INT,BIGINT
+---- LABELS
+i,_row_id
+====
+---- QUERY
+# ORDER BY using _last_updated_sequence_number.
+select i, _last_updated_sequence_number
+from iceberg_v3_row_lineage order by _last_updated_sequence_number desc;
+---- RESULTS
+3,3
+2,2
+1,1
+---- TYPES
+INT,BIGINT
+---- LABELS
+i,_last_updated_sequence_number
+====
+---- QUERY
+# GROUP BY using _row_id.
+select _row_id, count(*) from iceberg_v3_row_lineage group by _row_id order by _row_id;
+---- RESULTS
+0,1
+1,1
+2,1
+---- TYPES
+BIGINT,BIGINT
+====
+---- QUERY
+# GROUP BY using _last_updated_sequence_number.
+select _last_updated_sequence_number, count(*)
+from iceberg_v3_row_lineage
+group by _last_updated_sequence_number
+order by _last_updated_sequence_number;
+---- RESULTS
+1,1
+2,1
+3,1
+---- TYPES
+BIGINT,BIGINT
+====
+---- QUERY
+# HAVING clause using _row_id, grouped by i.
+select i, max(_row_id) row_id from iceberg_v3_row_lineage
+group by i
+having max(_row_id) >= 1
+order by i;
+---- RESULTS
+2,1
+3,2
+---- TYPES
+INT,BIGINT
+====
+---- QUERY
+# Subquery: _row_id used in inner SELECT, referenced by outer WHERE.
+select i from (
+    select i, _row_id from iceberg_v3_row_lineage
+) sub
+where _row_id < 2
+order by i;
+---- RESULTS
+1
+2
+---- TYPES
+INT
+====
+---- QUERY
+# CTE using _row_id and _last_updated_sequence_number.
+with ids as (
+    select i, _row_id, _last_updated_sequence_number
+    from iceberg_v3_row_lineage
+)
+select i, _row_id, _last_updated_sequence_number
+from ids
+order by i;
+---- RESULTS
+1,0,1
+2,1,2
+3,2,3
+---- TYPES
+INT,BIGINT,BIGINT
+====
+---- QUERY
+create table ice_v3_a (x int) stored as iceberg
+tblproperties ('format-version'='3');
+create table ice_v3_b (y int) stored as iceberg
+tblproperties ('format-version'='3');
+insert into ice_v3_a values (10);
+insert into ice_v3_a values (20);
+insert into ice_v3_b values (20);
+insert into ice_v3_b values (10);
+====
+---- QUERY
+# Qualified _row_id and _last_updated_sequence_number across two V3 tables in one query.
+select a.x, a._row_id, a._last_updated_sequence_number,
+       b.y, b._row_id, b._last_updated_sequence_number
+from ice_v3_a a, ice_v3_b b
+where a.x = b.y;
+---- RESULTS
+10,0,1,10,1,2
+20,1,2,20,0,1
+---- TYPES
+INT,BIGINT,BIGINT,INT,BIGINT,BIGINT
+====
+---- QUERY
+# Join: _row_id from both tables in WHERE predicate.
+select a.x, b.y
+from ice_v3_a a cross join ice_v3_b b
+where a._row_id = b._row_id;
+---- RESULTS
+10,20
+20,10
+---- TYPES
+INT,INT
+====
+---- QUERY
+# _row_id on V2 table should fail, column does not exist on non-V3 tables.
+create table ice_v2_no_sugar (i int) stored as iceberg
+tblproperties ('format-version'='2');
+insert into ice_v2_no_sugar values (1);
+select _row_id from ice_v2_no_sugar;
+---- CATCH
+Could not resolve column/field reference: '_row_id'
+====
+---- QUERY
+# _last_updated_sequence_number on V2 table should fail.
+select _last_updated_sequence_number from ice_v2_no_sugar;
+---- CATCH
+Could not resolve column/field reference: '_last_updated_sequence_number'
+====
+---- QUERY
+# Unqualified _row_id is ambiguous when multiple V3 tables are in scope.
+select _row_id from ice_v3_a a, ice_v3_b b;
+---- CATCH
+Column/field reference is ambiguous: '_row_id'
+====
+---- QUERY
+# Unqualified _last_updated_sequence_number is ambiguous when multiple V3 tables
+# are in scope.
+select _last_updated_sequence_number from ice_v3_a a cross join ice_v3_b b;
+---- CATCH
+Column/field reference is ambiguous: '_last_updated_sequence_number'
+====
diff --git a/testdata/workloads/functional-query/queries/QueryTest/ranger_iceberg_v3_column_masking.test b/testdata/workloads/functional-query/queries/QueryTest/ranger_iceberg_v3_column_masking.test
new file mode 100644
index 000000000..1f43bc2e2
--- /dev/null
+++ b/testdata/workloads/functional-query/queries/QueryTest/ranger_iceberg_v3_column_masking.test
@@ -0,0 +1,27 @@
+====
+---- QUERY
+# _row_id, _file_row_id, _last_updated_sequence_number, _file_last_updated_sequence_number
+# have column masking rules that multiplies their values by -1.
+# _row_id returns _file_row_id if the latter is present, but it doesn't mean we multiply
+# the final result by -1 twice. I.e., the final results are always the original results
+# plus the column masking rule applied on top of it.
+select _row_id, _file_row_id, _last_updated_sequence_number,
+    _file_last_updated_sequence_number, i
+from $UNIQUE_DB.ice_v3 where i < 10 order by _row_id;
+---- RESULTS
+-6001202,-6001202,-3,-3,6
+-6001201,-6001201,-3,-3,5
+-6001200,-6001200,-3,-3,4
+regex:-\d+,NULL,-2,NULL,7
+regex:-\d+,NULL,-2,NULL,7
+regex:-\d+,NULL,-2,NULL,7
+regex:-\d+,NULL,-2,NULL,7
+regex:-\d+,NULL,-2,NULL,7
+regex:-\d+,NULL,-2,NULL,7
+regex:-\d+,NULL,-2,NULL,7
+-2,-2,-1,-1,3
+-1,-1,-1,-1,2
+0,0,-1,-1,1
+---- TYPES
+BIGINT,BIGINT,BIGINT,BIGINT,INT
+====
diff --git a/tests/authorization/test_ranger.py b/tests/authorization/test_ranger.py
index c09d4433d..3a9e84470 100644
--- a/tests/authorization/test_ranger.py
+++ b/tests/authorization/test_ranger.py
@@ -3554,6 +3554,52 @@ class TestRangerLocalCatalog(TestRanger):
     finally:
       admin_client.execute("drop database if exists {0} cascade".format(unique_database))
 
+  @pytest.mark.execute_serially
+  def test_iceberg_v3_column_masking(self, vector, unique_name):
+    """Test column masking on Iceberg V3 virtual columns (_row_id, _file_row_id,
+    _last_updated_sequence_number, _file_last_updated_sequence_number)."""
+    user = getuser()
+    admin_client = self.create_impala_client(user=ADMIN)
+    unique_database = unique_name + "_db"
+    short_table_name = "ice_v3"
+    tbl_name = unique_database + "." + short_table_name
+
+    policy_cnt = 0
+    try:
+      admin_client.execute("drop database if exists {0} cascade"
+                           .format(unique_database))
+      admin_client.execute("create database {0}".format(unique_database))
+      admin_client.execute(
+          "create table {0} (i int) stored by iceberg "
+          "tblproperties ('format-version'='3')".format(tbl_name))
+      admin_client.execute("insert into {0} values (1), (2), (3)".format(tbl_name))
+      admin_client.execute(
+          "insert into {0} select cast(l_orderkey as INT) "
+          "from tpch.lineitem where l_orderkey > 6".format(tbl_name))
+      admin_client.execute("insert into {0} values (4), (5), (6)".format(tbl_name))
+      admin_client.execute(
+          "optimize table {0} (file_size_threshold_mb=1)".format(tbl_name))
+      admin_client.execute("grant select on database {0} to user {1} "
+                           .format(unique_database, user))
+
+      # Add column masking policies that produce the negative values of virtual columns.
+      for col in ["_row_id", "_file_row_id", "_last_updated_sequence_number",
+                  "_file_last_updated_sequence_number"]:
+        TestRanger._add_column_masking_policy(
+            unique_name + str(policy_cnt), user, unique_database, short_table_name,
+            col, "CUSTOM", "-{col}")
+        policy_cnt += 1
+      self.execute_query_expect_success(admin_client, "refresh authorization")
+      self.run_test_case("QueryTest/ranger_iceberg_v3_column_masking", vector,
+                         test_file_vars={'$UNIQUE_DB': unique_database})
+    finally:
+      admin_client.execute("revoke select on database {0} from user {1}"
+                            .format(unique_database, user))
+      admin_client.execute("drop database if exists {0} cascade"
+                           .format(unique_database))
+      for i in range(policy_cnt):
+        TestRanger._remove_policy(unique_name + str(i))
+
   @pytest.mark.execute_serially
   def test_convert_table_to_iceberg(self, unique_name):
     """Test that autorization is taken into account when performing a table migration to


(impala) 01/02: IMPALA-14806: Cache IcebergContentFileStore

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

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 71c63ed6132c73e4cf0907014d3f2fd8f1e9a6ee
Author: Csaba Ringhofer <cs...@cloudera.com>
AuthorDate: Thu Apr 9 19:29:29 2026 +0200

    IMPALA-14806: Cache IcebergContentFileStore
    
    This change was split out from larger change
    https://gerrit.cloudera.org/#/c/24049/
    
    With this patch Iceberg file descriptors are cached in
    IcebergFileContentStore instead of TPartialTableInfo.
    TPartialInfo is still cached, but without file info.
    
    Based on experiments this both makes mem need smaller and
    planning much faster by not needing to convert TPartialTableInfo
    to IcebergFileContentStore in each query. The drawback
    is that +1 GetPartialCatalogObject RPC is needed to
    fetch an Iceberg table from catalog.
    
    Examples are for 1M files, 25K partitions Iceberg table
    on my dev machine.
    
    Mem:
      Before:
       558 MB org.apache.impala.thrift.TPartialTableInfo
      After:
       449 MB org.apache.impala.catalog.IcebergFileContentStore
         3 MB org.apache.impala.thrift.TPartialTableInfo
    
    Speed:
      DESCRIBE t: 1.7s->10ms
      EXPLAIN SELECT * FROM t: 5.5s->4.7s
      EXPLAIN SELECT * FROM t WHERE part_col=100: 1.5s->0.7s
    
    Change-Id: Ic93eeb3a90a280a7138672affd71ac6f87df71a1
    Reviewed-on: http://gerrit.cloudera.org:8080/24177
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 .../org/apache/impala/catalog/FeIcebergTable.java  | 13 +++--
 .../impala/catalog/IcebergContentFileStore.java    | 38 +++++++++++--
 .../org/apache/impala/catalog/IcebergTable.java    | 16 ++++--
 .../impala/catalog/local/CatalogdMetaProvider.java | 64 +++++++++++++++++++++-
 .../impala/catalog/local/DirectMetaProvider.java   |  7 +++
 .../impala/catalog/local/IcebergMetaProvider.java  | 29 ++++++----
 .../impala/catalog/local/LocalIcebergTable.java    | 16 +++---
 .../apache/impala/catalog/local/MetaProvider.java  | 19 +++++++
 .../catalog/local/MetaProviderDecorator.java       |  5 ++
 .../impala/catalog/local/MultiMetaProvider.java    |  8 +++
 .../impala/catalog/local/LocalCatalogTest.java     |  2 +-
 .../catalog/local/MetaProviderDecoratorTest.java   |  2 +-
 12 files changed, 183 insertions(+), 36 deletions(-)

diff --git a/fe/src/main/java/org/apache/impala/catalog/FeIcebergTable.java b/fe/src/main/java/org/apache/impala/catalog/FeIcebergTable.java
index 74ff9069c..03bd51267 100644
--- a/fe/src/main/java/org/apache/impala/catalog/FeIcebergTable.java
+++ b/fe/src/main/java/org/apache/impala/catalog/FeIcebergTable.java
@@ -630,18 +630,19 @@ public interface FeIcebergTable extends FeFsTable {
       Map<String, TIcebergPartitionStats> nameToStats = new HashMap<>();
       // Use IcebergUtil.planFiles to retrieve only matching files.
       // This uses Iceberg's metadata (manifest files) to skip files that don't match.
+      Table apiTable = table.getIcebergApiTable();
       try (CloseableIterable<FileScanTask> tasks = IcebergUtil.planFiles(table,
           Collections.singletonList(filterExpr), null, null)) {
         // Iceberg has already done the filtering at the metadata level.
         for (FileScanTask task : tasks) {
           ContentFile<?> contentFile = task.file();
-          String partitionKey = getPartitionKey(table, contentFile);
+          String partitionKey = getPartitionKey(apiTable, contentFile);
           nameToStats.put(partitionKey,
               mergePartitionStats(nameToStats, contentFile, partitionKey));
 
           // Also include delete files for completeness
           for (DeleteFile deleteFile : task.deletes()) {
-            String deletePartitionKey = getPartitionKey(table, deleteFile);
+            String deletePartitionKey = getPartitionKey(apiTable, deleteFile);
             nameToStats.put(deletePartitionKey,
                 mergePartitionStats(nameToStats, deleteFile, deletePartitionKey));
           }
@@ -1012,10 +1013,10 @@ public interface FeIcebergTable extends FeFsTable {
      * TODO(IMPALA-11516): Return better partition stats for V2 tables.
      */
     public static Map<String, TIcebergPartitionStats> loadPartitionStats(
-        IcebergTable table, GroupedContentFiles icebergFiles) {
+        Table apiTable, GroupedContentFiles icebergFiles) {
       Map<String, TIcebergPartitionStats> nameToStats = new HashMap<>();
       for (ContentFile<?> contentFile : icebergFiles.getAllContentFiles()) {
-        String name = getPartitionKey(table, contentFile);
+        String name = getPartitionKey(apiTable, contentFile);
         nameToStats.put(name, mergePartitionStats(nameToStats, contentFile, name));
       }
       return nameToStats;
@@ -1050,9 +1051,9 @@ public interface FeIcebergTable extends FeFsTable {
     /**
      * Get iceberg partition from a dataFile and wrapper to a json string
      */
-    public static String getPartitionKey(FeIcebergTable table,
+    public static String getPartitionKey(Table apiTable,
         ContentFile<?> contentFile) {
-      PartitionSpec spec = table.getIcebergApiTable().specs().get(contentFile.specId());
+      PartitionSpec spec = apiTable.specs().get(contentFile.specId());
       Map<String, String> fieldNameToPartitionValue = new LinkedHashMap<>();
       for (int i = 0; i < spec.fields().size(); ++i) {
         Object partValue = contentFile.partition().get(i, Object.class);
diff --git a/fe/src/main/java/org/apache/impala/catalog/IcebergContentFileStore.java b/fe/src/main/java/org/apache/impala/catalog/IcebergContentFileStore.java
index 723b8f8d6..e80605d5d 100644
--- a/fe/src/main/java/org/apache/impala/catalog/IcebergContentFileStore.java
+++ b/fe/src/main/java/org/apache/impala/catalog/IcebergContentFileStore.java
@@ -197,6 +197,9 @@ public class IcebergContentFileStore {
     }
   }
 
+  /////////////////////////////////////////
+  // BEGIN: immutable members
+
   // Separate map-list containers for the different content files.
   private MapListContainer dataFilesWithoutDeletes_ = new MapListContainer();
   private MapListContainer dataFilesWithDeletes_ = new MapListContainer();
@@ -208,6 +211,17 @@ public class IcebergContentFileStore {
   // from the IcebergFileDescriptors.
   private Map<TIcebergPartition, Integer> partitions_;
 
+  // Flags to indicate file formats used in the table.
+  private boolean hasAvro_ = false;
+  private boolean hasOrc_ = false;
+  private boolean hasParquet_ = false;
+
+  // END: immutable members
+  /////////////////////////////////////////
+
+  /////////////////////////////////////////
+  // BEGIN: mutable members
+
   // Caches file descriptors loaded during time-travel queries.
   private final ConcurrentMap<Hash128, EncodedFileDescriptor> oldFileDescMap_ =
       new ConcurrentHashMap<>();
@@ -215,10 +229,8 @@ public class IcebergContentFileStore {
   private final ConcurrentMap<TIcebergPartition, Integer> oldPartitionMap_ =
       new ConcurrentHashMap<>();
 
-  // Flags to indicate file formats used in the table.
-  private boolean hasAvro_ = false;
-  private boolean hasOrc_ = false;
-  private boolean hasParquet_ = false;
+  // END: mutable members
+  /////////////////////////////////////////
 
   public IcebergContentFileStore() {}
 
@@ -255,6 +267,24 @@ public class IcebergContentFileStore {
     dataFileToDV_ = icebergFiles.dataFileToDV;
   }
 
+  // Creates a new instance with shared immutable members but
+  // new empty mutable ones.
+  public IcebergContentFileStore cloneWithoutMutables() {
+    IcebergContentFileStore ret = new IcebergContentFileStore();
+    // Separate map-list containers for the different content files.
+    ret.dataFilesWithoutDeletes_ = dataFilesWithoutDeletes_;
+    ret.dataFilesWithDeletes_ = dataFilesWithDeletes_;
+    ret.positionDeleteFiles_ = positionDeleteFiles_;
+    ret.equalityDeleteFiles_ = equalityDeleteFiles_;
+    ret.dataFileToDV_ = dataFileToDV_;
+    ret.missingFiles_ = missingFiles_;
+    ret.partitions_ = partitions_;
+    ret.hasAvro_ = hasAvro_;
+    ret.hasOrc_ = hasOrc_;
+    ret.hasParquet_ = hasParquet_;
+    return ret;
+  }
+
   private void storeFile(ContentFile<?> contentFile,
       Map<String, IcebergFileDescriptor> fileDescMap, MapListContainer container) {
     Pair<Hash128, EncodedFileDescriptor> pathHashAndFd =
diff --git a/fe/src/main/java/org/apache/impala/catalog/IcebergTable.java b/fe/src/main/java/org/apache/impala/catalog/IcebergTable.java
index e9817da70..29357baf1 100644
--- a/fe/src/main/java/org/apache/impala/catalog/IcebergTable.java
+++ b/fe/src/main/java/org/apache/impala/catalog/IcebergTable.java
@@ -549,7 +549,7 @@ public class IcebergTable extends Table implements FeIcebergTable {
       catalogTimeline.markEvent("Loaded Iceberg file descriptors");
       fileStore_ = new IcebergContentFileStore(icebergApiTable_,
           loader.getLoadedIcebergFds(), icebergFiles, loader.getIcebergPartitions());
-      partitionStats_ = Utils.loadPartitionStats(this, icebergFiles);
+      partitionStats_ = Utils.loadPartitionStats(this.getIcebergApiTable(), icebergFiles);
 
       setAvroSchema(msClient, msTable_, fileStore_, catalogTimeline);
       updateMetrics(loader.getFileMetadataStats());
@@ -887,6 +887,13 @@ public class IcebergTable extends Table implements FeIcebergTable {
     }
 
     if (req.table_info_selector.want_iceberg_table) {
+      resp.table_info.setIceberg_table(Utils.getTIcebergTable(this,
+          ThriftObjectType.DESCRIPTOR_ONLY));
+      resp.table_info.iceberg_table.setCatalog_snapshot_id(catalogSnapshotId_);
+    }
+
+    if (req.table_info_selector.want_iceberg_table
+        && req.table_info_selector.want_partition_files) {
       // Only apply pagination if the coordinator explicitly opted in by setting
       // iceberg_file_offset. This ensures callers that don't support pagination
       // always receive the full file set.
@@ -903,10 +910,9 @@ public class IcebergTable extends Table implements FeIcebergTable {
           getContentFileStore().toThriftPartial(fileOffset, fileLimit);
 
       // Count files actually returned
-      long filesReturned = IcebergContentFileStore.countContentFiles(partialContentFiles);
+      long filesReturned =
+          IcebergContentFileStore.countContentFiles(partialContentFiles);
 
-      resp.table_info.setIceberg_table(Utils.getTIcebergTable(this,
-          ThriftObjectType.DESCRIPTOR_ONLY));
       resp.table_info.iceberg_table.setContent_files(partialContentFiles);
 
       // On the first request, include total file count so the coordinator knows
@@ -923,8 +929,8 @@ public class IcebergTable extends Table implements FeIcebergTable {
       if (!resp.table_info.isSetNetwork_addresses()) {
         resp.table_info.setNetwork_addresses(getHostIndex().getList());
       }
-      resp.table_info.iceberg_table.setCatalog_snapshot_id(catalogSnapshotId_);
     }
+
     return resp;
   }
 
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/CatalogdMetaProvider.java b/fe/src/main/java/org/apache/impala/catalog/local/CatalogdMetaProvider.java
index 7115641c5..1cacace3b 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/CatalogdMetaProvider.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/CatalogdMetaProvider.java
@@ -1227,19 +1227,66 @@ public class CatalogdMetaProvider implements MetaProvider {
         new Callable<TPartialTableInfo>() {
           @Override
           public TPartialTableInfo call() throws Exception {
-            return loadIcebergTableWithPagination(table);
+            // Load Iceberg table without file list.
+            TGetPartialCatalogObjectRequest req = newReqForTable(table);
+            req.table_info_selector.want_iceberg_table = true;
+            req.table_info_selector.want_partition_files = false;
+            TGetPartialCatalogObjectResponse resp = sendRequest(req);
+            checkResponse(resp.table_info != null &&
+                resp.table_info.iceberg_table != null, req,
+                "missing Iceberg table metadata");
+            return resp.getTable_info();
           }
     });
   }
 
+  @Override
+  public CachedIcebergFiles
+      loadIcebergContentFileStore(final TableMetaRef table) throws TException {
+    Preconditions.checkArgument(table instanceof TableMetaRefImpl);
+    TableMetaRefImpl tableRef = (TableMetaRefImpl)table;
+
+    String itemStr = "content file store for " + tableRef.dbName_ + "."
+        + tableRef.tableName_;
+    // TODO: use snapshot id for key to make usable for REST catalog
+    IcebergContentFileStoreCacheKey cacheKey =
+        new IcebergContentFileStoreCacheKey(tableRef);
+    MetaProvider.CachedIcebergFiles result =
+        loadWithCaching(itemStr, TABLE_METADATA_CACHE_CATEGORY, cacheKey,
+          new Callable<CachedIcebergFiles>() {
+            @Override
+            public CachedIcebergFiles call() throws Exception {
+              TPartialTableInfo tableInfo = loadIcebergTableWithPagination(table);
+              ListMap<TNetworkAddress> hostIndex = new ListMap<>();
+              IcebergContentFileStore contentFiles = IcebergContentFileStore.fromThrift(
+                  tableInfo.getIceberg_table().getContent_files(),
+                  tableInfo.getNetwork_addresses(),
+                  hostIndex);
+              return new CachedIcebergFiles(
+                  contentFiles, hostIndex,
+                  tableInfo.getIceberg_table().getPartition_stats());
+            }
+          });
+
+    // The result is cloned to share immutable members but keep mutable ones private.
+    // Mutable concurrent hash maps are used to cache files from time-travel queries,
+    // which is thread-safe, but would increase the size of the cached object without
+    // updating weight.
+    // TODO: come up with a way to cache files in time-travel queries
+    return new MetaProvider.CachedIcebergFiles(result.fileStore.cloneWithoutMutables(),
+        result.hostIndex, result.partitionStats);
+  }
+
   /**
    * Load Iceberg table metadata, handling partial file responses with pagination.
    * Similar to loadPartitionsFromCatalogd but for Iceberg file pagination.
    */
-  private TPartialTableInfo loadIcebergTableWithPagination(TableMetaRef table)
+  @VisibleForTesting
+  TPartialTableInfo loadIcebergTableWithPagination(TableMetaRef table)
       throws TException {
     TGetPartialCatalogObjectRequest req = newReqForTable(table);
     req.table_info_selector.want_iceberg_table = true;
+    req.table_info_selector.want_partition_files = true;
     req.table_info_selector.setIceberg_file_offset(0);
 
     TGetPartialCatalogObjectResponse resp = sendRequest(req);
@@ -1266,6 +1313,7 @@ public class CatalogdMetaProvider implements MetaProvider {
 
       TGetPartialCatalogObjectRequest nextReq = newReqForTable(table);
       nextReq.table_info_selector.want_iceberg_table = true;
+      nextReq.table_info_selector.want_partition_files = true;
       nextReq.table_info_selector.setIceberg_file_offset(fileOffset);
 
       TGetPartialCatalogObjectResponse nextResp = sendRequest(nextReq);
@@ -2348,6 +2396,18 @@ public class CatalogdMetaProvider implements MetaProvider {
     }
   }
 
+  /**
+   * Cache key for an entry storing Iceberg files
+   *
+   * Values for these keys are 'MetaProvider.CachedIcebergFiles' objects.
+   */
+  private static class IcebergContentFileStoreCacheKey extends VersionedTableCacheKey {
+
+    public IcebergContentFileStoreCacheKey(TableMetaRefImpl table) {
+      super(table);
+    }
+  }
+
   /**
    * Cache key for a DataSource object.
    */
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/DirectMetaProvider.java b/fe/src/main/java/org/apache/impala/catalog/local/DirectMetaProvider.java
index 58deeecd1..00bce2a38 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/DirectMetaProvider.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/DirectMetaProvider.java
@@ -600,4 +600,11 @@ class DirectMetaProvider implements MetaProvider {
     throw new NotImplementedException(
         "loadIcebergApiTable() is not implemented for DirectMetaProvider");
   }
+
+  @Override
+  public MetaProvider.CachedIcebergFiles
+      loadIcebergContentFileStore(final TableMetaRef table) throws TException {
+    throw new NotImplementedException(
+        "loadIcebergContentFileStore() is not implemented for DirectMetaProvider");
+  }
 }
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/IcebergMetaProvider.java b/fe/src/main/java/org/apache/impala/catalog/local/IcebergMetaProvider.java
index d21a088f5..a40f72650 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/IcebergMetaProvider.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/IcebergMetaProvider.java
@@ -52,6 +52,7 @@ import org.apache.impala.authorization.AuthorizationChecker;
 import org.apache.impala.authorization.AuthorizationPolicy;
 import org.apache.impala.catalog.CatalogException;
 import org.apache.impala.catalog.DataSource;
+import org.apache.impala.catalog.FeIcebergTable;
 import org.apache.impala.catalog.FileDescriptor;
 import org.apache.impala.catalog.Function;
 import org.apache.impala.catalog.HdfsCachePool;
@@ -73,6 +74,7 @@ import org.apache.impala.common.Pair;
 import org.apache.impala.compat.MetastoreShim;
 import org.apache.impala.thrift.TBriefTableMeta;
 import org.apache.impala.thrift.TIcebergContentFileStore;
+import org.apache.impala.thrift.TIcebergPartitionStats;
 import org.apache.impala.thrift.TIcebergTable;
 import org.apache.impala.thrift.TNetworkAddress;
 import org.apache.impala.thrift.TPartialTableInfo;
@@ -563,11 +565,7 @@ public class IcebergMetaProvider implements MetaProvider {
       iceTable.setCatalog_snapshot_id(apiTable.currentSnapshot().snapshotId());
     }
     iceTable.setDefault_partition_spec_id(apiTable.spec().specId());
-    ListMap<TNetworkAddress> hostIndex = new ListMap<>();
-    iceTable.setContent_files(getTContentFileStore(table, apiTable, hostIndex));
-    iceTable.setPartition_stats(Collections.emptyMap());
     ret.setIceberg_table(iceTable);
-    ret.setNetwork_addresses(hostIndex.getList());
     return ret;
   }
 
@@ -577,25 +575,36 @@ public class IcebergMetaProvider implements MetaProvider {
     return ((TableMetaRefImpl)table).iceApiTbl_;
   }
 
-  public String getLocation(final TableMetaRef table) {
-    return ((TableMetaRefImpl)table).msTable_.getSd().getLocation();
+  @Override
+  public MetaProvider.CachedIcebergFiles
+      loadIcebergContentFileStore(final TableMetaRef table) throws TException {
+    // TODO: integrate with CatalogdMetadataProvider's cache somehow
+    TableMetaRefImpl tableRef = (TableMetaRefImpl) table;
+    ListMap<TNetworkAddress> hostIndex = new ListMap<>();
+    return getContentFileStore(tableRef.iceApiTbl_, hostIndex, true);
   }
 
-  private TIcebergContentFileStore getTContentFileStore(final TableMetaRef table,
-      org.apache.iceberg.Table apiTable, ListMap<TNetworkAddress> hostIndex) {
+  private static MetaProvider.CachedIcebergFiles getContentFileStore(
+      org.apache.iceberg.Table apiTable,
+      ListMap<TNetworkAddress> hostIndex, boolean loadPartStats) {
     try {
       TableScan scan = apiTable.newScan();
       GroupedContentFiles groupedFiles = new GroupedContentFiles(scan.planFiles());
       IcebergFileMetadataLoader iceFml = new IcebergFileMetadataLoader(
           apiTable, Collections.emptyList(), hostIndex, groupedFiles,
-          new ArrayList<>(), false);
+          Collections.emptyList(), false);
       iceFml.load();
       IcebergContentFileStore contentFileStore = new IcebergContentFileStore(apiTable,
           iceFml.getLoadedIcebergFds(), groupedFiles, iceFml.getIcebergPartitions());
-      return contentFileStore.toThrift();
+      Map<String, TIcebergPartitionStats> partStats = null;
+      if (loadPartStats) {
+        partStats = FeIcebergTable.Utils.loadPartitionStats(apiTable, groupedFiles);
+      }
+      return new MetaProvider.CachedIcebergFiles(contentFileStore, hostIndex, partStats);
     } catch (Exception e) {
       throw new IllegalStateException(
           "Exception occurred during loading Iceberg file metadata", e);
     }
   }
+
 }
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/LocalIcebergTable.java b/fe/src/main/java/org/apache/impala/catalog/local/LocalIcebergTable.java
index f09c62871..57998edeb 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/LocalIcebergTable.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/LocalIcebergTable.java
@@ -94,6 +94,9 @@ public class LocalIcebergTable extends LocalTable implements FeIcebergTable {
       TableParams tableParams = new TableParams(msTable);
       TPartialTableInfo tableInfo = db.getCatalog().getMetaProvider()
           .loadIcebergTable(ref);
+      MetaProvider.CachedIcebergFiles cachedFiles =
+          db.getCatalog().getMetaProvider().loadIcebergContentFileStore(ref);
+
       LocalFsTable fsTable = LocalFsTable.load(db, msTable, ref);
       warmupMetaProviderCache(db, msTable, ref, fsTable);
       org.apache.iceberg.Table icebergApiTable = db.getCatalog().getMetaProvider()
@@ -110,7 +113,7 @@ public class LocalIcebergTable extends LocalTable implements FeIcebergTable {
           db.getName() + "." + msTable.getTableName(),
           /*isFullAcidSchema=*/false);
       return new LocalIcebergTable(db, msTable, ref, fsTable, colMap, tableInfo,
-          tableParams, icebergApiTable);
+          tableParams, icebergApiTable, cachedFiles);
     } catch (InconsistentMetadataFetchException e) {
       // Just rethrow this so the query can be retried by the Frontend.
       throw e;
@@ -146,17 +149,17 @@ public class LocalIcebergTable extends LocalTable implements FeIcebergTable {
 
   private LocalIcebergTable(LocalDb db, Table msTable, MetaProvider.TableMetaRef ref,
       LocalFsTable fsTable, ColumnMap cmap, TPartialTableInfo tableInfo,
-      TableParams tableParams, org.apache.iceberg.Table icebergApiTable)
+      TableParams tableParams, org.apache.iceberg.Table icebergApiTable,
+      MetaProvider.CachedIcebergFiles cachedFiles)
       throws ImpalaRuntimeException {
     super(db, msTable, ref, cmap);
 
     Preconditions.checkNotNull(tableInfo);
     localFsTable_ = fsTable;
     tableParams_ = tableParams;
-    fileStore_ = IcebergContentFileStore.fromThrift(
-        tableInfo.getIceberg_table().getContent_files(),
-        tableInfo.getNetwork_addresses(),
-        getHostIndex());
+    fileStore_ = cachedFiles.fileStore;
+    getHostIndex().populate(cachedFiles.hostIndex.getList());
+    partitionStats_ = cachedFiles.partitionStats;
     if (fileStore_.hasAvro()) localFsTable_.setAvroSchema(msTable);
     icebergApiTable_ = icebergApiTable;
     catalogSnapshotId_ = tableInfo.getIceberg_table().getCatalog_snapshot_id();
@@ -167,7 +170,6 @@ public class LocalIcebergTable extends LocalTable implements FeIcebergTable {
     icebergParquetRowGroupSize_ = Utils.getIcebergParquetRowGroupSize(msTable);
     icebergParquetPlainPageSize_ = Utils.getIcebergParquetPlainPageSize(msTable);
     icebergParquetDictPageSize_ = Utils.getIcebergParquetDictPageSize(msTable);
-    partitionStats_ = tableInfo.getIceberg_table().getPartition_stats();
     setIcebergTableStats();
     addVirtualColumns(ref.getVirtualColumns());
   }
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/MetaProvider.java b/fe/src/main/java/org/apache/impala/catalog/local/MetaProvider.java
index a97929742..15375b64d 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/MetaProvider.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/MetaProvider.java
@@ -34,11 +34,13 @@ import org.apache.impala.catalog.Function;
 import org.apache.impala.catalog.HdfsCachePool;
 import org.apache.impala.catalog.HdfsPartitionLocationCompressor;
 import org.apache.impala.catalog.HdfsStorageDescriptor;
+import org.apache.impala.catalog.IcebergContentFileStore;
 import org.apache.impala.catalog.SqlConstraints;
 import org.apache.impala.catalog.VirtualColumn;
 import org.apache.impala.catalog.local.LocalIcebergTable.TableParams;
 import org.apache.impala.common.Pair;
 import org.apache.impala.thrift.TBriefTableMeta;
+import org.apache.impala.thrift.TIcebergPartitionStats;
 import org.apache.impala.thrift.TNetworkAddress;
 import org.apache.impala.thrift.TPartialTableInfo;
 import org.apache.impala.thrift.TValidWriteIdList;
@@ -164,6 +166,23 @@ public interface MetaProvider {
   public org.apache.iceberg.Table loadIcebergApiTable(
       final TableMetaRef table, TableParams param, Table msTable) throws TException;
 
+  public class CachedIcebergFiles {
+    public IcebergContentFileStore fileStore;
+    public ListMap<TNetworkAddress> hostIndex;
+    public Map<String, TIcebergPartitionStats> partitionStats;
+
+    public CachedIcebergFiles(IcebergContentFileStore fileStore,
+        ListMap<TNetworkAddress> hostIndex,
+        Map<String, TIcebergPartitionStats> partitionStats) {
+      this.fileStore = fileStore;
+      this.hostIndex = hostIndex;
+      this.partitionStats = partitionStats;
+    }
+  }
+
+  public CachedIcebergFiles
+      loadIcebergContentFileStore(final TableMetaRef table) throws TException;
+
   /**
    * Reference to a table as returned by loadTable(). This reference must be passed
    * back to other functions to fetch more details about the table. Implementations
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/MetaProviderDecorator.java b/fe/src/main/java/org/apache/impala/catalog/local/MetaProviderDecorator.java
index b8fa1ec0b..79b9a0a1b 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/MetaProviderDecorator.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/MetaProviderDecorator.java
@@ -155,6 +155,11 @@ public abstract class MetaProviderDecorator implements MetaProvider {
     return this.decoratedObj_.loadIcebergApiTable(table, param, msTable);
   }
 
+  public MetaProvider.CachedIcebergFiles
+      loadIcebergContentFileStore(final TableMetaRef table) throws TException {
+    return this.decoratedObj_.loadIcebergContentFileStore(table);
+  }
+
   public TValidWriteIdList getValidWriteIdList(TableMetaRef ref) {
     return this.decoratedObj_.getValidWriteIdList(ref);
   }
diff --git a/fe/src/main/java/org/apache/impala/catalog/local/MultiMetaProvider.java b/fe/src/main/java/org/apache/impala/catalog/local/MultiMetaProvider.java
index 30d5d3035..e1e2643c6 100644
--- a/fe/src/main/java/org/apache/impala/catalog/local/MultiMetaProvider.java
+++ b/fe/src/main/java/org/apache/impala/catalog/local/MultiMetaProvider.java
@@ -214,6 +214,14 @@ public class MultiMetaProvider implements MetaProvider {
         unchecked(provider -> provider.loadIcebergApiTable(table, param, msTable)));
   }
 
+  // TODO: this interface doesn't really make sense, see IMPALA-14892
+  @Override
+  public MetaProvider.CachedIcebergFiles
+      loadIcebergContentFileStore(final TableMetaRef table) throws TException {
+    return tryAllProviders(
+        unchecked(provider -> provider.loadIcebergContentFileStore(table)));
+  }
+
   @Override
   public TValidWriteIdList getValidWriteIdList(TableMetaRef ref) {
     try {
diff --git a/fe/src/test/java/org/apache/impala/catalog/local/LocalCatalogTest.java b/fe/src/test/java/org/apache/impala/catalog/local/LocalCatalogTest.java
index a213336c3..0c4541766 100644
--- a/fe/src/test/java/org/apache/impala/catalog/local/LocalCatalogTest.java
+++ b/fe/src/test/java/org/apache/impala/catalog/local/LocalCatalogTest.java
@@ -280,7 +280,7 @@ public class LocalCatalogTest {
     LocalIcebergTable t = (LocalIcebergTable)catalog_.getTable(
         "functional_parquet", "iceberg_partitioned");
     IcebergContentFileStore fileStore = t.getContentFileStore();
-    TPartialTableInfo tblInfo = provider_.loadIcebergTable(t.ref_);
+    TPartialTableInfo tblInfo = provider_.loadIcebergTableWithPagination(t.ref_);
     ListMap<TNetworkAddress> catalogdHostIndexes = new ListMap<>();
     catalogdHostIndexes.populate(tblInfo.getNetwork_addresses());
     IcebergContentFileStore catalogFileStore = IcebergContentFileStore.fromThrift(
diff --git a/fe/src/test/java/org/apache/impala/catalog/local/MetaProviderDecoratorTest.java b/fe/src/test/java/org/apache/impala/catalog/local/MetaProviderDecoratorTest.java
index 84396a911..7660d643f 100644
--- a/fe/src/test/java/org/apache/impala/catalog/local/MetaProviderDecoratorTest.java
+++ b/fe/src/test/java/org/apache/impala/catalog/local/MetaProviderDecoratorTest.java
@@ -63,7 +63,7 @@ public class MetaProviderDecoratorTest {
 
   // Expected number of public methods in MetaProvider interface
   // Update this constant when adding new methods to MetaProvider
-  private static final int EXPECTED_METHOD_COUNT = 23;
+  private static final int EXPECTED_METHOD_COUNT = 24;
 
   @Test
   public void testMetaProviderMethodCount() {