Native from_json with a schema that repeats a field name fails with "ArrowArray struct has 2 children (expected 1)"
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
Research direction
Begin at CometJsonToStructs.isSupportedSchema, which validates field types but not names; the failure surfaces in NativeUtil.importVector because Java Arrow keys struct children by name. Add a recursive check that rejects structs with repeated field names at any depth so the query falls back to the dispatcher, which already declines them (#5766), and cover it in the JsonToStructs test suite with the SQL from the report. Done means from_json(j, 'a INT, a INT') returns Spark's {null, 1} instead of throwing IllegalStateException.
Written by the indexing model from the issue text.
Description
Describe the bug
With the native from_json path enabled (spark.comet.expression.JsonToStructs.allowIncompatible=true), a schema that repeats a field name fails the task once the result reaches the JVM. Spark accepts such a schema and fills the last field with that name, so from_json('{"a":1}', 'a INT, a INT') returns {null, 1}. Comet's native projection builds the same struct, and to_json over it matches Spark, but importing the result on the JVM fails because Java Arrow keys struct children by name:
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.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)
By default from_json runs through the codegen dispatcher, which declines structs with repeated field names (#5766), so only the opt-in native path is affected.
Steps to reproduce
Reproduced on main at fef94f6cd with Spark 4.1.3:
SET spark.comet.expression.JsonToStructs.allowIncompatible=true;
CREATE TABLE tj (j STRING) USING parquet;
INSERT INTO tj VALUES ('{"a":1}'), ('{"a":2,"b":3}'), (NULL);
SELECT from_json(j, 'a INT, a INT') FROM tj; -- IllegalStateException
SELECT to_json(from_json(j, 'a INT, a INT')) FROM tj; -- matches Spark
SELECT from_json(j, 'a INT, b INT') FROM tj; -- matches Spark
The plan is CometProject over CometNativeScan.
Expected behavior
Either match Spark or stay off the native path. CometJsonToStructs.isSupportedSchema checks the field types but not the names. If it rejected a struct with repeated field names at any depth, these schemas would go to the dispatcher, which already declines them, and the query would fall back to Spark.
Additional context
This is the same Java Arrow limitation as #6591 (struct casts) and #6251 (arrays_zip). Found while checking whether anything in #5603 was worth keeping.
- Dominant language
- Scala
- Stars
- 1.3k
- Forks
- 383
- Avg merge
- 2d 58m
- Merged PRs (30d)
- 399
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/datafusion-comet
-
area:aggregation bug priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
apache/datafusion-comet#6661 ·
Maintainers usually reply within 1 day
-
Casting to a struct type with repeated field names fails with "ArrowArray struct has 2 children (expected 1)"Possibly taken A pull request linked to this issue is open or already merged. Openarea:expressions area:ffi bug good first issue priority:high
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/datafusion-comet#6591 ·
Maintainers usually reply within 1 day
-
arrays_zip with two same-named inputs fails with "ArrowArray struct has 2 children (expected 1)"Possibly taken @mohitgurav20 claimed this 7 days ago. Openarea:expressions area:ffi bug priority:high
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/datafusion-comet#6251 · 4 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
ci: a transient Maven Central failure in lint-java is reported as a scalafix violationPossibly taken @andygrove claimed this 15 days ago. Openarea:ci bug priority:low
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
apache/datafusion-comet#6060 ·
Maintainers usually reply within 1 day
-
requires-triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
apache/datafusion-comet#5661 ·
Maintainers usually reply within 1 day
All issues in apache/datafusion-comet
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
snowflakedb/spark-snowflake#673 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
salesforce/evalon#16 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
chipsalliance/chisel#5504 ·
Maintainers usually reply within 1 day
-
documentation good first issue
Difficulty 2/5 Half a day Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Homebrew formula 2.1.26: 'cs completions bash' fails (exit 127) because bin/cs is not executableOpen
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
coursier/coursier#3896 · 1 reaction ·
Maintainers usually reply within 1 day