Implement Spark-compatible `xpath_number` (alias of `xpath_double`)

Đang mở Phù hợp với người mới
#287 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

Chưa có ai nhận issue này.

Đá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
70/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
databases

Hướng nghiên cứu

Đọc UDF xpath_double hiện có trong crates/spark/src/function/xml/ trước — issue này chỉ là một alias, nên hãy xác nhận rằng UDF đó đã được đăng ký trước khi bắt đầu. Thêm xpath_number thông qua ScalarUDFImpl::aliases (phản chiếu expression[XPathDouble]("xpath_number", true) trong FunctionRegistry của Spark) và ghi chú alias trong #[user_doc]. Thêm các trường hợp vào crates/sqllogictest/test_files/xml/xpath_double.slt (hoặc một xpath_number.slt mới) bao gồm hai ví dụ, NaN/0.0, tên cột xpath_number(xml, path), đầu vào NULL và lỗi đường dẫn không thể gấp; hoàn thành nghĩa là các trường hợp slt đó đều đạt và khớp chính xác với kết quả của xpath_double.

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

Mô tả

enhancement

Part of #271 and apache/datafusion-comet#7300.

What the function does

xpath_number(xml, path) is a registered alias of xpath_double: expression[XPathDouble]("xpath_number", true) in FunctionRegistry. It evaluates an XPath 1.0 expression, converts the result with XPath number(),
and returns DOUBLE. Both arguments are strings (collation-aware from 4.0), path must be foldable, and the
result is always nullable. Available since Spark 2.0.0. The only observable difference from xpath_double is
the display name: prettyName reads the FUNC_ALIAS tag, so the column header is xpath_number(...).

The numeric conversion rules (node-set, boolean and string to number, NaN, the empty node-set) are in the
xpath_double issue. Parsing, DTD and entity handling, namespaces, NULL handling and the error behavior are
in the xpath issue. This one only needs the alias.

Examples
SELECT xpath_number('<a><b>1</b><b>2</b></a>','sum(a/b)');
-- 3.0
SELECT xpath_number('<a><b>1.0</b><b>2.1</b></a>', 'sum(a/b)');
-- 3.1

The first comes from the Hive udf_xpath_double golden file (DESCRIBE FUNCTION EXTENDED xpath_number) and
the second from XPathFunctionsSuite.

Edge cases to test
  • Run the same cases as xpath_double and check that the results match exactly, including NaN for
    non-numeric text and 0.0 for a false boolean expression.
  • The output column name is xpath_number(xml, path), not xpath_double(...).
  • NULL or '' arguments give NULL. A non-literal path gives DATATYPE_MISMATCH.NON_FOLDABLE_INPUT.
Differences across Spark versions

None found. The alias has existed since 2.0.0.

Implementation notes
  • Spark: XPathDouble in sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/xml/xpath.scala,
    registered as xpath_number in sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala.
  • DataFusion core has no equivalent.
  • Implement it as an alias (ScalarUDFImpl::aliases) of the xpath_double UDF in
    crates/spark/src/function/xml/, rather than as a separate kernel. This can be done in the same PR as
    xpath_double.
  • Tests: add xpath_number cases to crates/sqllogictest/test_files/xml/xpath_double.slt, or put them in a
    separate xpath_number.slt. Mention the alias in the #[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

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-spark

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

Issue tương tự

Thêm issue về Rust

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.