Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Casting to a struct type with repeated field names fails with "ArrowArray struct has 2 children (expected 1)"

Đang mở Phù hợp với người mới
#6,591 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Samearth17 đang làm issue này rồi.

Từ ngày 5/10/2026.

  • #6671 của @Samearth17 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust, scala
Lĩnh vực
backend

Hướng nghiên cứu

Đọc nhánh struct của CometCast.isSupported và so sánh nó với CometCreateNamedStruct, thứ đã từ chối các tên trường lặp lại; các nhánh array và map đệ quy vào nó, vì vậy một kiểm tra bao phủ các trường hợp lồng nhau trong SQL repro. Tái hiện với ba truy vấn CAST thất bại cộng với hai đối chứng thành công, sau đó xác nhận bản sửa khiến cast fallback để kết quả khớp với Spark. Hoàn thành trông giống như một case mới bao phủ các tên trường struct lặp lại trong bộ kiểm thử cast và không có IllegalStateException từ NativeUtil.importVector.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area:expressions area:ffi bug good first issue priority:high
Describe the bug

A cast whose target struct type repeats a field name fails the task when Comet runs it natively. Spark allows the cast as long as each pair of fields casts, so CAST(s AS STRUCT<x: INT, x: INT>) over a STRUCT<p: INT, q: INT> column returns {1, 10}. Comet's native cast_struct_to_struct builds the result with the target fields, and the projection itself works: to_json over the cast matches Spark with {"x":1,"x":10}. Importing the result on the JVM then fails, because Java Arrow keys struct children by name and the two x children collapse into one:

java.lang.IllegalStateException: ArrowArray struct has 2 children (expected 1)
	at org.apache.arrow.util.Preconditions.checkState(Preconditions.java:562)
	at org.apache.arrow.c.ArrayImporter.doImport(ArrayImporter.java:92)
	at org.apache.arrow.c.ArrayImporter.importChild(ArrayImporter.java:83)
	at org.apache.arrow.c.ArrayImporter.doImport(ArrayImporter.java:101)
	at org.apache.arrow.c.ArrayImporter.importArray(ArrayImporter.java:68)
	at org.apache.arrow.c.ArrowImporter.importVector(ArrowImporter.java:62)
	at org.apache.comet.vector.NativeUtil.importVector(NativeUtil.scala:264)
	at org.apache.comet.vector.NativeUtil.getNextBatch(NativeUtil.scala:211)
	at org.apache.comet.CometExecIterator.getNextBatch(CometExecIterator.scala:236)

The same happens when the struct is nested in an array or a map value.

Steps to reproduce

Default configs, reproduced on main at fef94f6cd with Spark 4.1.3:

CREATE TABLE ts (
  s STRUCT<p: INT, q: INT>,
  arr ARRAY<STRUCT<p: INT, q: INT>>,
  m MAP<STRING, STRUCT<p: INT, q: INT>>) USING parquet;

INSERT INTO ts VALUES
  (named_struct('p', 1, 'q', 10), array(named_struct('p', 1, 'q', 10)),
   map('k', named_struct('p', 1, 'q', 10))),
  (named_struct('p', 2, 'q', NULL), array(), map()),
  (NULL, NULL, NULL);

SELECT CAST(s AS STRUCT<x: INT, x: INT>) FROM ts;               -- IllegalStateException
SELECT CAST(arr AS ARRAY<STRUCT<x: INT, x: INT>>) FROM ts;      -- IllegalStateException
SELECT CAST(m AS MAP<STRING, STRUCT<x: INT, x: INT>>) FROM ts;  -- IllegalStateException
SELECT CAST(s AS STRUCT<x: INT, y: INT>) FROM ts;               -- matches Spark
SELECT to_json(CAST(s AS STRUCT<x: INT, x: INT>)) FROM ts;      -- matches Spark

The plan is CometProject over CometNativeScan. Spark returns {1, 10}, {2, null} and null for the first query.

Expected behavior

Either match Spark or fall back. The smallest fix is probably for the struct branch of CometCast.isSupported to return Unsupported when the target struct repeats a field name, the same way CometCreateNamedStruct declines repeated names. The array and map branches already recurse into the struct branch, so one check there also covers the nested cases.

Additional context

This is the same Java Arrow limitation as #6251 (arrays_zip, fix in #6324), #5605 and #1015. Main declines structs with repeated field names wherever they would cross into Java Arrow: the shuffle and row conversion checks (#5866), the codegen dispatcher (#5766) and the cache serializer (#6004). Those checks guard the paths that bring a struct into Comet, though, and a native cast creates one. The broadcast exchange admits these types too (CometSink.convert calls supportedDataType with the default allowDuplicateStructFieldNames = true), so declining in the serde that produces the struct is what keeps it out.

Found while checking whether anything in #5603 was worth keeping.

Ngôn ngữ chính
Scala
Star
1.3k
Fork
383
Merge trung bình
2 ngày 58 phút
Pull request đã merge (30 ngày)
399

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/datafusion-comet

Tất cả issue của apache/datafusion-comet

Issue tương tự

Thêm issue về Scala

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.