You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by la...@apache.org on 2026/10/03 16:07:16 UTC

(impala) branch master updated: IMPALA-15141 (part 1): Keep codegen enabled for queries on VARIANT

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


The following commit(s) were added to refs/heads/master by this push:
     new 55e46a673 IMPALA-15141 (part 1): Keep codegen enabled for queries on VARIANT
55e46a673 is described below

commit 55e46a6739de79fdad885951c140c15e9ac7eb85
Author: Zoltan Borok-Nagy <bo...@cloudera.com>
AuthorDate: Thu Sep 17 10:55:14 2026 +0200

    IMPALA-15141 (part 1): Keep codegen enabled for queries on VARIANT
    
    The planner set the query-wide disable_codegen_hint for every query
    that scans a VARIANT column, so these queries lost codegen in all of
    their fragments, even in operators that never touch VARIANT values.
    This patch removes the hint and makes the backend safe without it.
    Expressions that involve VARIANT are still interpreted.
    
    The hint also protected codegen paths that cannot deal with VARIANT:
    * Exec nodes call ScalarExpr::GetCodegendComputeFn() directly (e.g.
      for conjuncts, hash/sort keys and partition exprs), bypassing
      ShouldCodegen(). GetCodegendComputeFn() now returns an expected
      error for expressions that involve VARIANT, so these callers fall
      back to interpretation, but only for the given operator.
    * LlvmCodeGen::GetSlotType() now knows the layout of VARIANT slots
      (two StringValues), so TupleDescriptor::GetLlvmStruct() works for
      tuples that have a VARIANT slot.
    * Only the Parquet scanner can read VARIANT, but Iceberg tables can
      also have Avro and ORC data files with VARIANT columns. The planner
      now rejects scans that read VARIANT from non-Parquet data files,
      similarly to UUID (IMPALA-15200).
    
    Tuple::CodegenMaterializeExprs() still falls back if the destination
    tuple has a VARIANT slot (TOP-N, UNION ALL).
    
    Testing:
    * added e2e tests to check that the planner does not disable codegen
    * added Iceberg V3 test tables with VARIANT in Avro, ORC and mixed
      data files, generated with the Iceberg Java API
    
    Change-Id: I6e3c59cc41bab7421e0dd450e08944ffc3889241
    Assisted-by: Claude Fable 5.1 (Claude Code)
    Reviewed-on: http://gerrit.cloudera.org:8080/24882
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/codegen/llvm-codegen.cc                     |   3 ++
 be/src/exprs/scalar-expr.cc                        |   7 +++
 be/src/runtime/tuple.cc                            |   3 +-
 .../org/apache/impala/planner/HdfsScanNode.java    |  34 +++++++++++----
 testdata/data/README                               |  14 +++++-
 .../data/00000-0-variant.avro                      | Bin 0 -> 718 bytes
 .../4c32a9ec-306c-4e65-8646-5590e22b46d1-m0.avro   | Bin 0 -> 7809 bytes
 ...669-1-4c32a9ec-306c-4e65-8646-5590e22b46d1.avro | Bin 0 -> 4739 bytes
 .../metadata/v1.metadata.json                      |   1 +
 .../metadata/v2.metadata.json                      |   1 +
 .../metadata/version-hint.text                     |   1 +
 .../data/p=1/00000-0-variant.parquet               | Bin 0 -> 1223 bytes
 .../data/p=2/00001-0-variant.avro                  | Bin 0 -> 720 bytes
 .../23d64a68-204f-495c-a332-a66af7caa0c6-m0.avro   | Bin 0 -> 8073 bytes
 ...789-1-23d64a68-204f-495c-a332-a66af7caa0c6.avro | Bin 0 -> 4755 bytes
 .../metadata/v1.metadata.json                      |   1 +
 .../metadata/v2.metadata.json                      |   1 +
 .../metadata/version-hint.text                     |   1 +
 .../data/00000-0-variant.orc                       | Bin 0 -> 596 bytes
 .../1bd3b0e1-d755-4627-9717-743e7ca7caa3-m0.avro   | Bin 0 -> 7805 bytes
 ...215-1-1bd3b0e1-d755-4627-9717-743e7ca7caa3.avro | Bin 0 -> 4738 bytes
 .../metadata/v1.metadata.json                      |   1 +
 .../metadata/v2.metadata.json                      |   1 +
 .../metadata/version-hint.text                     |   1 +
 .../queries/QueryTest/iceberg-v3-variant-get.test  |  22 ++++++++++
 .../queries/QueryTest/iceberg-v3-variant.test      |  47 +++++++++++++++++++++
 tests/query_test/test_iceberg.py                   |   5 +++
 27 files changed, 133 insertions(+), 11 deletions(-)

diff --git a/be/src/codegen/llvm-codegen.cc b/be/src/codegen/llvm-codegen.cc
index 39ad69fea..1dc924f4d 100644
--- a/be/src/codegen/llvm-codegen.cc
+++ b/be/src/codegen/llvm-codegen.cc
@@ -605,6 +605,9 @@ llvm::Type* LlvmCodeGen::GetSlotType(const ColumnType& type) {
     case TYPE_ARRAY:
     case TYPE_MAP:
       return collection_value_type_;
+    case TYPE_VARIANT:
+      // A VARIANT slot is two consecutive StringValues: 'metadata' followed by 'value'.
+      return llvm::ArrayType::get(string_value_type_, 2);
     default:
       DCHECK(false) << "Invalid type: " << type;
       return NULL;
diff --git a/be/src/exprs/scalar-expr.cc b/be/src/exprs/scalar-expr.cc
index b267ea468..866d60dd2 100644
--- a/be/src/exprs/scalar-expr.cc
+++ b/be/src/exprs/scalar-expr.cc
@@ -377,6 +377,13 @@ Status ScalarExpr::GetCodegendComputeFn(
   if (ir_compute_fn_ != nullptr) {
     *fn = ir_compute_fn_;
   } else {
+    // Codegen for VARIANT is not implemented. ShouldCodegen() keeps such expressions from
+    // being registered as codegen entry points, but exec nodes also call this function
+    // directly (e.g. for conjuncts, hash/sort keys, partition exprs). They fall back to
+    // interpretation on a non-OK status.
+    if (InvolvesVariantType()) {
+      return Status::Expected("Codegen for expressions involving VARIANT NYI");
+    }
     RETURN_IF_ERROR(GetCodegendComputeFnImpl(codegen, fn));
     ir_compute_fn_ = *fn;
   }
diff --git a/be/src/runtime/tuple.cc b/be/src/runtime/tuple.cc
index 31d703dbd..7b0f5f0a0 100644
--- a/be/src/runtime/tuple.cc
+++ b/be/src/runtime/tuple.cc
@@ -407,7 +407,8 @@ Status Tuple::CodegenMaterializeExprs(LlvmCodeGen* codegen, bool collect_varlen_
   }
   // VARIANT slot writes are not codegen'd yet; fall back to the interpreted path
   // (Tuple::MaterializeExprs -> RawValue::WriteVariant). Without this, codegen would
-  // reach GetLlvmStruct/GetSlotType for TYPE_VARIANT and DCHECK.
+  // reach CodegenAnyVal::ToReadWriteInfo() and SlotDescriptor::CodegenWriteToSlot(),
+  // which do not support TYPE_VARIANT.
   for (const SlotDescriptor* slot : desc.slots()) {
     if (slot->type().IsVariantType()) {
       return Status::Expected("CodegenMaterializeExprs() VARIANT type NYI");
diff --git a/fe/src/main/java/org/apache/impala/planner/HdfsScanNode.java b/fe/src/main/java/org/apache/impala/planner/HdfsScanNode.java
index 091e28090..716f0eb50 100644
--- a/fe/src/main/java/org/apache/impala/planner/HdfsScanNode.java
+++ b/fe/src/main/java/org/apache/impala/planner/HdfsScanNode.java
@@ -487,6 +487,7 @@ public class HdfsScanNode extends ScanNode {
     checkSamplingAndCountStar(analyzer);
     checkForSupportedFileFormats();
     checkUuidReadSupported();
+    checkVariantReadSupported();
 
     assignCollectionConjuncts(analyzer);
 
@@ -512,15 +513,6 @@ public class HdfsScanNode extends ScanNode {
 
     computeMemLayout(analyzer);
 
-    // Disable codegen for scans involving VARIANT columns (not yet fully supported).
-    // TODO(IMPALA-15141): Enable codegen for VARIANTs.
-    for (SlotDescriptor slot : desc_.getSlots()) {
-      if (slot.isMaterialized() && slot.getType().isVariantType()) {
-        analyzer.getQueryCtx().disable_codegen_hint = true;
-        break;
-      }
-    }
-
     // This is towards the end, so that it can take all conjuncts, scan ranges and mem
     // layout into account.
     computeStats(analyzer);
@@ -703,6 +695,30 @@ public class HdfsScanNode extends ScanNode {
     ((FeIcebergTable) table).validateUuidReadSupported(fileFormats_);
   }
 
+  /**
+   * Validates that the VARIANT columns read by this scan can be read from the file
+   * formats present in this scan. Only Parquet is supported. For Iceberg tables
+   * 'fileFormats_' contains the formats of the scanned data files, which can differ from
+   * the default file format of the table.
+   */
+  private void checkVariantReadSupported() throws NotImplementedException {
+    boolean readsVariant = false;
+    for (SlotDescriptor slot : desc_.getSlots()) {
+      if (slot.isMaterialized() && slot.getType().isVariantType()) {
+        readsVariant = true;
+        break;
+      }
+    }
+    if (!readsVariant) return;
+
+    // Iterate in enum order to report the same format if there are more than one.
+    for (HdfsFileFormat format : HdfsFileFormat.values()) {
+      if (format == HdfsFileFormat.PARQUET || !fileFormats_.contains(format)) continue;
+      throw new NotImplementedException(String.format(
+          "Reading VARIANT columns from %s format is not yet supported.", format));
+    }
+  }
+
   /**
    * Populates the collection conjuncts, materializes their required slots, and marks
    * the conjuncts as assigned, if it is correct to do so. Some conjuncts may have to
diff --git a/testdata/data/README b/testdata/data/README
index 83172ae2f..464ed7560 100644
--- a/testdata/data/README
+++ b/testdata/data/README
@@ -1311,6 +1311,18 @@ map_v MAP<STRING,VARIANT>, struct_v STRUCT<a:VARIANT, b:INT>,
 arr_struct_v ARRAY<STRUCT<v:VARIANT>>. The top-level top_v column reads normally; the
 arr_v/map_v/struct_v/arr_struct_v columns exercise the nested-VARIANT rejection paths.
 
+testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro
+testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc
+testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed
+Iceberg V3 tables with a VARIANT column in non-Parquet data files, used to test that
+Impala rejects scans that read VARIANT from Avro or ORC files. Schema: id INT, p INT,
+v VARIANT. iceberg_v3_variant_avro has one Avro data file, iceberg_v3_variant_orc has
+one ORC data file. iceberg_v3_variant_mixed is partitioned by identity(p) and has a
+Parquet data file in p=1 and an Avro data file in p=2. Each data file has five rows whose
+v is 42, "hello", {"age":30,"name":"Alice"}, a variant null and a SQL NULL.
+Generated with a custom Java program (written by Claude Opus 5.5) using the Iceberg
+1.11 Java library.
+
 arrays_big.parq:
 Generated with RandomNestedDataGenerator.java from the following schema:
 {
@@ -1452,4 +1464,4 @@ geometry type combinations. Each row has 2*6 geometries, for example in id = 'in
 row each <geomtype>1 column intersects with each <geomtype>2 (e.g point1 with polygon2).
 In 'disjoint_near' and 'disjoint_far' all relations (besides st_disjoint) must be false,
 the difference is whether the bounding rectangles intersect. Some values are left NULL,
-for example point1/point2 in overlaps case as st_overlaps is not meaningful for points.
\ No newline at end of file
+for example point1/point2 in overlaps case as st_overlaps is not meaningful for points.
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/data/00000-0-variant.avro b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/data/00000-0-variant.avro
new file mode 100644
index 000000000..c40ea3035
Binary files /dev/null and b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/data/00000-0-variant.avro differ
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/4c32a9ec-306c-4e65-8646-5590e22b46d1-m0.avro b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/4c32a9ec-306c-4e65-8646-5590e22b46d1-m0.avro
new file mode 100644
index 000000000..09785ebbd
Binary files /dev/null and b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/4c32a9ec-306c-4e65-8646-5590e22b46d1-m0.avro differ
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/snap-7108812184163398669-1-4c32a9ec-306c-4e65-8646-5590e22b46d1.avro b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/snap-7108812184163398669-1-4c32a9ec-306c-4e65-8646-5590e22b46d1.avro
new file mode 100644
index 000000000..8c4dfae99
Binary files /dev/null and b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/snap-7108812184163398669-1-4c32a9ec-306c-4e65-8646-5590e22b46d1.avro differ
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/v1.metadata.json b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/v1.metadata.json
new file mode 100644
index 000000000..327b4f6bf
--- /dev/null
+++ b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/v1.metadata.json
@@ -0,0 +1 @@
+{"format-version":3,"table-uuid":"5bd8e200-cd4a-40f3-b1c3-7e2e4f25583b","location":"/test-warehouse/iceberg_v3_variant_avro","last-sequence-number":0,"last-updated-ms":1790949727625,"last-column-id":3,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":false,"type":"int"},{"id":2,"name":"p","required":false,"type":"int"},{"id":3,"name":"v","required":false,"type":"variant"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields [...]
\ No newline at end of file
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/v2.metadata.json b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/v2.metadata.json
new file mode 100644
index 000000000..f457dccd7
--- /dev/null
+++ b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/v2.metadata.json
@@ -0,0 +1 @@
+{"format-version":3,"table-uuid":"5bd8e200-cd4a-40f3-b1c3-7e2e4f25583b","location":"/test-warehouse/iceberg_v3_variant_avro","last-sequence-number":1,"last-updated-ms":1790949727886,"last-column-id":3,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":false,"type":"int"},{"id":2,"name":"p","required":false,"type":"int"},{"id":3,"name":"v","required":false,"type":"variant"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields [...]
\ No newline at end of file
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/version-hint.text b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/version-hint.text
new file mode 100644
index 000000000..d8263ee98
--- /dev/null
+++ b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_avro/metadata/version-hint.text
@@ -0,0 +1 @@
+2
\ No newline at end of file
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/data/p=1/00000-0-variant.parquet b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/data/p=1/00000-0-variant.parquet
new file mode 100644
index 000000000..ec0669d9e
Binary files /dev/null and b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/data/p=1/00000-0-variant.parquet differ
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/data/p=2/00001-0-variant.avro b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/data/p=2/00001-0-variant.avro
new file mode 100644
index 000000000..a8433f9d6
Binary files /dev/null and b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/data/p=2/00001-0-variant.avro differ
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/23d64a68-204f-495c-a332-a66af7caa0c6-m0.avro b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/23d64a68-204f-495c-a332-a66af7caa0c6-m0.avro
new file mode 100644
index 000000000..d669145da
Binary files /dev/null and b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/23d64a68-204f-495c-a332-a66af7caa0c6-m0.avro differ
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/snap-8008792904878867789-1-23d64a68-204f-495c-a332-a66af7caa0c6.avro b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/snap-8008792904878867789-1-23d64a68-204f-495c-a332-a66af7caa0c6.avro
new file mode 100644
index 000000000..4a01b9996
Binary files /dev/null and b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/snap-8008792904878867789-1-23d64a68-204f-495c-a332-a66af7caa0c6.avro differ
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/v1.metadata.json b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/v1.metadata.json
new file mode 100644
index 000000000..fcc54537b
--- /dev/null
+++ b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/v1.metadata.json
@@ -0,0 +1 @@
+{"format-version":3,"table-uuid":"79f860b6-ad73-4c2c-85db-3cd398f5dd34","location":"/test-warehouse/iceberg_v3_variant_mixed","last-sequence-number":0,"last-updated-ms":1790949728082,"last-column-id":3,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":false,"type":"int"},{"id":2,"name":"p","required":false,"type":"int"},{"id":3,"name":"v","required":false,"type":"variant"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"field [...]
\ No newline at end of file
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/v2.metadata.json b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/v2.metadata.json
new file mode 100644
index 000000000..a36347dab
--- /dev/null
+++ b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/v2.metadata.json
@@ -0,0 +1 @@
+{"format-version":3,"table-uuid":"79f860b6-ad73-4c2c-85db-3cd398f5dd34","location":"/test-warehouse/iceberg_v3_variant_mixed","last-sequence-number":1,"last-updated-ms":1790949728398,"last-column-id":3,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":false,"type":"int"},{"id":2,"name":"p","required":false,"type":"int"},{"id":3,"name":"v","required":false,"type":"variant"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"field [...]
\ No newline at end of file
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/version-hint.text b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/version-hint.text
new file mode 100644
index 000000000..d8263ee98
--- /dev/null
+++ b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_mixed/metadata/version-hint.text
@@ -0,0 +1 @@
+2
\ No newline at end of file
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/data/00000-0-variant.orc b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/data/00000-0-variant.orc
new file mode 100644
index 000000000..dea563048
Binary files /dev/null and b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/data/00000-0-variant.orc differ
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/1bd3b0e1-d755-4627-9717-743e7ca7caa3-m0.avro b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/1bd3b0e1-d755-4627-9717-743e7ca7caa3-m0.avro
new file mode 100644
index 000000000..4608964d2
Binary files /dev/null and b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/1bd3b0e1-d755-4627-9717-743e7ca7caa3-m0.avro differ
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/snap-4259005618451124215-1-1bd3b0e1-d755-4627-9717-743e7ca7caa3.avro b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/snap-4259005618451124215-1-1bd3b0e1-d755-4627-9717-743e7ca7caa3.avro
new file mode 100644
index 000000000..40e9fd30a
Binary files /dev/null and b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/snap-4259005618451124215-1-1bd3b0e1-d755-4627-9717-743e7ca7caa3.avro differ
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/v1.metadata.json b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/v1.metadata.json
new file mode 100644
index 000000000..322d2653e
--- /dev/null
+++ b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/v1.metadata.json
@@ -0,0 +1 @@
+{"format-version":3,"table-uuid":"f9b5051a-9921-44d6-b304-f48cd1a7edb7","location":"/test-warehouse/iceberg_v3_variant_orc","last-sequence-number":0,"last-updated-ms":1790949727935,"last-column-id":3,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":false,"type":"int"},{"id":2,"name":"p","required":false,"type":"int"},{"id":3,"name":"v","required":false,"type":"variant"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields" [...]
\ No newline at end of file
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/v2.metadata.json b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/v2.metadata.json
new file mode 100644
index 000000000..3a96e27a1
--- /dev/null
+++ b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/v2.metadata.json
@@ -0,0 +1 @@
+{"format-version":3,"table-uuid":"f9b5051a-9921-44d6-b304-f48cd1a7edb7","location":"/test-warehouse/iceberg_v3_variant_orc","last-sequence-number":1,"last-updated-ms":1790949728066,"last-column-id":3,"current-schema-id":0,"schemas":[{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":false,"type":"int"},{"id":2,"name":"p","required":false,"type":"int"},{"id":3,"name":"v","required":false,"type":"variant"}]}],"default-spec-id":0,"partition-specs":[{"spec-id":0,"fields" [...]
\ No newline at end of file
diff --git a/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/version-hint.text b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/version-hint.text
new file mode 100644
index 000000000..d8263ee98
--- /dev/null
+++ b/testdata/data/iceberg_test/iceberg_v3/iceberg_v3_variant_orc/metadata/version-hint.text
@@ -0,0 +1 @@
+2
\ No newline at end of file
diff --git a/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-variant-get.test b/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-variant-get.test
index dd1785f34..9f86dc4bf 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-variant-get.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-variant-get.test
@@ -602,3 +602,25 @@ SELECT variant_get(v, '$', 'string') FROM trino_variant WHERE id = 59;
 ---- TYPES
 STRING
 ====
+---- QUERY
+# IMPALA-15141: scanning a VARIANT column does not disable codegen for the whole query.
+EXPLAIN SELECT id, v FROM trino_variant WHERE variant_get(v, '$.age', 'int') > 25;
+---- RESULTS: VERIFY_IS_NOT_IN
+'Codegen disabled by planner'
+---- TYPES
+STRING
+====
+---- QUERY
+# Conjuncts with typed extractions over the whole table, next to a join and an aggregation
+# that do not involve VARIANT.
+SELECT count(*), max(a.id)
+FROM trino_variant a JOIN trino_variant b ON a.id = b.id
+WHERE variant_get(a.v, '$.age', 'int') > 25
+  AND variant_get(b.v, '$.name', 'string') = 'Alice';
+---- RESULTS
+2,32
+---- TYPES
+BIGINT, INT
+---- RUNTIME_PROFILE
+!row_regex: .*disabled due to optimization hints
+====
diff --git a/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-variant.test b/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-variant.test
index 444ee293f..99529bb76 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-variant.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/iceberg-v3-variant.test
@@ -560,3 +560,50 @@ row_regex:(?s).*"v":\s*\{.*
 ---- TYPES
 STRING
 ====
+---- QUERY
+# VARIANT can only be read from Parquet data files.
+SELECT id, v FROM iceberg_v3_variant_avro;
+---- CATCH
+Reading VARIANT columns from AVRO format is not yet supported.
+====
+---- QUERY
+SELECT id FROM iceberg_v3_variant_avro
+WHERE variant_get(v, '$.name', 'string') = 'Alice';
+---- CATCH
+Reading VARIANT columns from AVRO format is not yet supported.
+====
+---- QUERY
+SELECT id, v FROM iceberg_v3_variant_orc;
+---- CATCH
+Reading VARIANT columns from ORC format is not yet supported.
+====
+---- QUERY
+# Columns other than VARIANT can be read.
+SELECT id, p FROM iceberg_v3_variant_orc ORDER BY id;
+---- RESULTS
+1,1
+2,1
+3,1
+4,1
+5,1
+---- TYPES
+INT, INT
+====
+---- QUERY
+# The check is based on the formats of the scanned data files, not on the default file
+# format of the table (Parquet). p=1 has a Parquet data file, p=2 has an Avro data file.
+SELECT id, v FROM iceberg_v3_variant_mixed;
+---- CATCH
+Reading VARIANT columns from AVRO format is not yet supported.
+====
+---- QUERY
+SELECT id, v FROM iceberg_v3_variant_mixed WHERE p = 1 ORDER BY id;
+---- RESULTS
+1,'42'
+2,'"hello"'
+3,'{"age":30,"name":"Alice"}'
+4,'null'
+5,'NULL'
+---- TYPES
+INT, STRING
+====
diff --git a/tests/query_test/test_iceberg.py b/tests/query_test/test_iceberg.py
index 94e2f85d7..b7d1c1be4 100644
--- a/tests/query_test/test_iceberg.py
+++ b/tests/query_test/test_iceberg.py
@@ -2601,6 +2601,11 @@ class TestIcebergV3Table(IcebergTestSuite):
     # Table with VARIANT nested inside ARRAY/MAP/STRUCT; used by the negative cases
     # that assert nested VARIANT is rejected (only top-level VARIANT is queryable).
     self.load_table(unique_database, "trino_nested_variant")
+    # Tables with VARIANT in Avro / ORC / mixed Parquet and Avro data files, written by
+    # testdata/bin/generate-iceberg-v3-variant-formats.java.
+    self.load_table(unique_database, "iceberg_v3_variant_avro", format="avro")
+    self.load_table(unique_database, "iceberg_v3_variant_orc", format="orc")
+    self.load_table(unique_database, "iceberg_v3_variant_mixed")
     self.run_test_case('QueryTest/iceberg-v3-variant', vector, unique_database)
 
   def test_v3_variant_shell(self, vector):