Implement Spark-compatible `xpath_short`
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
- 68/100
Hướng nghiên cứu
Start by reading Spark's XPathShort and XPathShortEvaluator in xpath.scala and XmlExpressionEvalUtils.scala, then locate the shared number() evaluator in crates/spark/src/function/xml/ referenced by the xpath and xpath_double issues. Implement the narrowing as (d as i32) as i16, add crates/sqllogictest/test_files/xml/xpath_short.slt, and document the function with #[user_doc]. Done means the listed examples and edge cases pass in the SLT file.
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_short(xml, path) evaluates an XPath 1.0 expression, converts the result with XPath number() into a
Java Double, and narrows it with Double.shortValue(), giving a SMALLINT. 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.
The number() conversion is in the xpath_double issue. Parsing, DTD and entity handling, namespaces, NULL
handling and errors are in the xpath issue. This issue covers only the double-to-short step.
The narrowing is Java's (short) d, which does not saturate. JLS 5.1.3 first converts the double to int,
with saturation and NaN becoming 0, and then keeps the low 16 bits. In Rust this is (d as i32) as i16, not
d as i16, which would saturate at i16::MAX.
Examples
SELECT xpath_short('<a><b>1</b><b>2</b></a>', 'sum(a/b)');
-- 3
SELECT xpath_short('<a>this is not a number</a>', 'a');
-- 0
SELECT xpath_short('<a><b>2000000000</b><c>40000000000</c></a>', 'a/b * a/c');
-- -1
SELECT xpath_short('<a>try a boolean</a>', 'a = 10');
-- 0
SELECT xpath_short('<a><b class="odd">1</b><b class="even">2</b><b class="odd">4</b><c>8</c></a>', 'a/b');
-- 1
SELECT xpath_short('<a><b class="odd">1</b><b class="even">2</b><b class="odd">4</b><c>8</c></a>', 'sum(a/*)');
-- 15
SELECT xpath_short('<a><b class="odd">10000</b><b class="even">2</b><b class="odd">4</b><c>8</c></a>', 'sum(a/b[@class="odd"])');
-- 10004
These come from the ExpressionDescription, the Hive udf_xpath_short golden files run by
HiveCompatibilitySuite, and XPathExpressionSuite. The -1 comes from
(short) (int) 8.0E19 = (short) 2147483647 = -1.
Edge cases to test
- Wrap-around, by code reading:
<a>40000</a>gives-25536;<a>32768</a>gives-32768;<a>65536</a>gives0;-1 div 0gives(short) Integer.MIN_VALUE, which is0;1 div 0gives-1.
- Truncation toward zero before wrapping:
<a>-2.7</a>gives-2. NaNgives0. This covers non-numeric text,0 div 0, and the empty node-set, which isNaNin
XPath 1.0.NULLor''arguments give NULL. A non-literal path givesDATATYPE_MISMATCH.NON_FOLDABLE_INPUT.
Malformed XML and an invalid path raise runtime errors (see thexpathissue).
Differences across Spark versions
None found beyond the shared ones in the xpath issue.
Implementation notes
- Spark:
XPathShortinsql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/xml/xpath.scala.
It callsXPathShortEvaluator(ret.shortValue()) in.../xml/XmlExpressionEvalUtils.scala. - DataFusion core has no equivalent.
- Reuse the shared
number()evaluator from thexpathandxpath_doubleissues in
crates/spark/src/function/xml/, and narrow with(d as i32) as i16. - Tests: add
crates/sqllogictest/test_files/xml/xpath_short.sltand 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 ·