Implement Spark-compatible `is_variant_null`

未关闭
#277 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
28/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

enhancement

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 NULL returns false, not NULL. StaticInvoke uses propagateNull = false, returnNullable = false.
    A missing path in variant_get gives a SQL NULL, so it also returns false.
  • Cases that return false:
    • scalars: the string "null", "", 0, true, false, large ints such as 2147483648, and decimals;
    • a long string ("spark" repeated 100 times);
    • arrays and objects, including [], [null, null] and [{"a" : 13, "b" : null}].
      These all come from VariantExpressionEvalUtilsSuite."isVariantNull".
  • A variant null nested in an object or array reached through variant_get without a target type is still a
    variant null, so the result is true. With a concrete target type variant_get returns SQL NULL instead, so
    is_variant_null(variant_get(v, '$.a', 'int')) is false.
  • A malformed value with an empty value binary raises MALFORMED_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_strings set 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_object or 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: IsVariantNull in
    sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala.
    The logic is in VariantExpressionEvalUtils.isVariantNull, in the same package.
  • DataFusion core has no VARIANT support. arrow-rs parquet_variant::Variant::Null can be used for a decoded
    check, but reading value[0] == 0 from the value child of the struct array is enough and avoids decoding.
  • When the struct row itself is null, return false. A row with an empty value binary 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_json issue. Put it in a new
    crates/spark/src/function/variant/ module. Add crates/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.

主要语言
Rust
星标
7
派生
15
平均合并
16 小时 43 分钟
30 天内合并 PR
26

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/datafusion-spark 的其他 Issue

查看 apache/datafusion-spark 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。