Implement Spark-compatible `xpath_double` / `xpath_number`
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 58/100
Hướng nghiên cứu
Start in crates/spark/src/function/xml/ and confirm whether the shared evaluator from the xpath issue already exists; this issue only adds evaluate_number(xml, path) -> Option<f64> on top of it, plus registration of xpath_number as an alias. Cross-read Spark's XPathDoubleEvaluator/UDFXPathUtil.evalNumber for the number() conversion rules, then write crates/sqllogictest/test_files/xml/xpath_double.slt covering the node-set, boolean, NaN/Infinity, -0 and NULL cases listed here. Done means both names pass the slt file and the function carries a #[user_doc] entry.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Part of #271 and apache/datafusion-comet#7300.
What the function does
xpath_double(xml, path) evaluates an XPath 1.0 expression, converts the result with the XPath number()
rules (XPathConstants.NUMBER, a Java Double), and returns it as DOUBLE. xpath_number is a registered
alias of the same expression: expression[XPathDouble]("xpath_number", true), and its pretty name is
xpath_number. Both arguments are strings (collation-aware from 4.0), and path must be foldable. The result
is always nullable. Available since Spark 2.0.0.
Parsing, DTD and entity handling, namespaces, NULL and empty-string handling, invalid-XML and invalid-path
errors, and lazy path compilation are shared with the family. They are specified in the xpath issue, and
this function should reuse that evaluator. This issue covers only the numeric conversion. xpath_float,
xpath_int, xpath_long and xpath_short take the same double and narrow it.
Examples
SELECT xpath_double('<a><b>1</b><b>2</b></a>', 'sum(a/b)');
-- 3.0
SELECT xpath_double('<a>this is not a number</a>', 'a');
-- NaN
SELECT xpath_double('<a>this 2 is not a number</a>', 'a');
-- NaN
SELECT xpath_double('<a><b>2000000000</b><c>40000000000</c></a>', 'a/b * a/c');
-- 8.0E19
SELECT xpath_double('<a>try a boolean</a>', 'a = 10');
-- 0.0
SELECT xpath_double('<a><b class="odd">1</b><b class="even">2</b><b class="odd">4</b><c>8</c></a>', 'a/b');
-- 1.0
SELECT xpath_double('<a><b class="odd">1</b><b class="even">2</b><b class="odd">4</b><c>8</c></a>', 'sum(a/*)');
-- 15.0
SELECT xpath_double('<a><b class="odd">1</b><b class="even">2</b><b class="odd">4</b><c>8</c></a>', 'sum(a/b[@class="odd"])');
-- 5.0
SELECT xpath_number('<a><b>1.0</b><b>2.1</b></a>', 'sum(a/b)');
-- 3.1
These come from the ExpressionDescription, the Hive udf_xpath_double golden files run by
HiveCompatibilitySuite, XPathExpressionSuite and XPathFunctionsSuite. In UDFXPathUtilSuite, a/c[2]
on <c>-77</c> gives -77.0, and an attribute k="foo" gives NaN.
Edge cases to test
- Conversion rules from XPath 1.0
number():- a node-set uses the string value of its first node in document order (
a/babove gives1.0, not the sum); - a boolean gives
1.0or0.0(a = 10above); - a string is parsed with XPath's grammar. Surrounding whitespace is allowed, as are an optional leading
-
and digits with an optional.. There is no exponent and no leading+. Anything else isNaN, for
example'1e3','+1','1,000','Infinity'and'0x10'.
- a node-set uses the string value of its first node in document order (
- Empty node-set. The usage string says "zero if no match is found", but XPath 1.0 converts an empty node-set
throughnumber(''), which isNaN. Verifyxpath_double('<a/>', 'a/b')against Spark before asserting
either value (the integer variants mapNaNto 0 anyway). NaN,Infinityand-Infinitycan be produced by arithmetic (0 div 0,1 div 0,-1 div 0) and must
come back as the IEEE values.-0(-0 * 1) should keep its sign bit.- Large and imprecise values:
8.0E19above, andsum()over many decimal strings, which uses double
arithmetic (1.0 + 2.1gives3.1in the suite). NULLor''for either argument gives NULL. A non-literalpathgivesDATATYPE_MISMATCH.NON_FOLDABLE_INPUT.
Malformed XML and an invalid path raise runtime errors (see thexpathissue). ANSI mode has no effect.xpath_numbermust return the same values and showxpath_numberas its display name.
Differences across Spark versions
None found beyond the shared ones in the xpath issue.
Implementation notes
- Spark:
XPathDoubleinsql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/xml/xpath.scala.
It callsXPathDoubleEvaluator(.../xml/XmlExpressionEvalUtils.scala), which calls
UDFXPathUtil.evalNumber. Thexpath_numberalias is inFunctionRegistry.scala. - DataFusion core has no equivalent.
- Build it on the shared evaluator from the
xpathissue incrates/spark/src/function/xml/. A single
evaluate_number(xml, path) -> Option<f64>helper can servexpath_double,xpath_float,xpath_int,
xpath_longandxpath_short. Registerxpath_numberas an alias. - Tests:
crates/sqllogictest/test_files/xml/xpath_double.slt, which also coversxpath_number. 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 ·