Implement Spark-compatible `is_variant_null`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 28/100
Hướng nghiên cứu
Work is blocked on the VARIANT Arrow representation from the parse_json issue (#273), so start by reading that issue's resolution and the struct layout it defines (metadata and value binary children). Then read Spark's VariantExpressionEvalUtils.isVariantNull for the single-byte check, add the function under a new crates/spark/src/function/variant/ module with #[user_doc], and write crates/sqllogictest/test_files/variant/is_variant_null.slt. Done means a non-nullable boolean where SQL NULL and row-null return false and an empty value binary raises MALFORMED_VARIANT, matching the listed examples.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Part of #273 and apache/datafusion-comet#7300.
What the function does
is_variant_null(v) returns true only when v is a variant null, meaning a JSON null stored inside a VARIANT.
In every other case it returns false, and that includes a SQL NULL input. The result is a non-nullable
BOOLEAN. The only accepted argument type is VARIANT, and there are no implicit casts. Added in Spark 4.0.0.
The check is a single byte: the first value byte must be 0x00 (basic type PRIMITIVE, type id NULL). This depends
on the VARIANT Arrow representation proposed in the parse_json issue, which uses the canonical
arrow.parquet.variant extension with metadata and value binary children.
Examples
SELECT is_variant_null(parse_json('null'));
-- true
SELECT is_variant_null(parse_json('"null"'));
-- false
SELECT is_variant_null(parse_json('13'));
-- false
SELECT is_variant_null(parse_json(null));
-- false
SELECT is_variant_null(variant_get(parse_json('{"a":null, "b":"spark"}'), '$.c'));
-- false
SELECT is_variant_null(variant_get(parse_json('{"a":null, "b":"spark"}'), '$.a'));
-- true
SELECT is_variant_null(variant_get(parse_json('{ "a": null, "b": {"c": null, "d": [13, null]} }'), '$.b.d[1]'));
-- true
SELECT is_variant_null(variant_get(parse_json('{ "a": null, "b": {"c": null, "d": [13, null]} }'), '$.b.d'));
-- false
These come from the ExpressionDescription and VariantEndToEndSuite.
Edge cases to test
- SQL
NULLreturnsfalse, not NULL.StaticInvokeusespropagateNull = false, returnNullable = false.
A missing path invariant_getgives a SQL NULL, so it also returnsfalse. - Cases that return
false:- scalars: the string
"null","",0,true,false, large ints such as2147483648, and decimals; - a long string (
"spark"repeated 100 times); - arrays and objects, including
[],[null, null]and[{"a" : 13, "b" : null}].
These all come fromVariantExpressionEvalUtilsSuite."isVariantNull".
- scalars: the string
- A variant null nested in an object or array reached through
variant_getwithout a target type is still a
variant null, so the result istrue. With a concrete target typevariant_getreturns SQL NULL instead, so
is_variant_null(variant_get(v, '$.a', 'int'))isfalse. - A malformed value with an empty
valuebinary raisesMALFORMED_VARIANT("Variant binary is malformed. Please
check the data source is valid."). Spark does not validate anything beyond the first byte. - Check that metadata is ignored: any valid header, including
sorted_stringsset or 2-4 byte offsets, gives the
same answer. - Test both a column and a literal input. Also test a variant produced by
to_variant_objector by
cast(x as variant)from a NULL array element. - The result does not depend on ANSI mode.
Differences across Spark versions
- 3.4 and 3.5 have no VARIANT type.
- No differences between 4.0.4, 4.1.3 and 4.2.0.
Implementation notes
- Spark:
IsVariantNullin
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala.
The logic is inVariantExpressionEvalUtils.isVariantNull, in the same package. - DataFusion core has no VARIANT support. arrow-rs
parquet_variant::Variant::Nullcan be used for a decoded
check, but readingvalue[0] == 0from thevaluechild of the struct array is enough and avoids decoding. - When the struct row itself is null, return
false. A row with an emptyvaluebinary should return
MALFORMED_VARIANT. - apache/datafusion-comet#5438 tracks native Variant support in Comet.
- This is blocked on the VARIANT type representation from the
parse_jsonissue. Put it in a new
crates/spark/src/function/variant/module. Addcrates/sqllogictest/test_files/variant/is_variant_null.slt
and document the function with#[user_doc].
This issue was generated by an LLM (Claude) from the Apache Spark source code and tests. Examples come from Spark's ExpressionDescription examples, test suites and .sql.out golden files, but please verify them against Spark before relying on them.
- Ngôn ngữ chính
- Rust
- Star
- 7
- Fork
- 15
- Merge trung bình
- 16 giờ 43 phút
- Pull request đã merge (30 ngày)
- 26
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/datafusion-spark
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
apache/datafusion-spark#287 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
apache/datafusion-spark#266 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] make_dt_interval returns NULL for more than about 1.49 million days, Spark returns the intervalCó thể đã có người làm @Subodh-17 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/datafusion-spark#109 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
apache/datafusion-spark#299 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
apache/datafusion-spark#298 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của apache/datafusion-spark
Issue tương tự
-
comp-rbac
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ClickHouse/ClickHouse#131875 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug(python): read_transaction raises TypeError on a Rewrite with rewritten indicesCó thể đã có người làm @Borg93 đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
lance-format/lance#11117 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
storytold/photocraft#15232 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
forge: fork preflight reads still send `requireCanonical: false`, which Rootstock rejects (-32603)Có thể đã có người làm @Ynyesto đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
foundry-rs/foundry#18485 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
bondybondbond/rushcut#238 · 1 bình luận ·