Implement Spark-compatible `xpath_float`
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 58/100
Línea de trabajo
Start with the xpath_double and xpath issues, since the shared number() evaluator must exist before this narrowing step can be written; then read Spark's XPathFloat/XPathFloatEvaluator in xpath.scala and XmlExpressionEvalUtils.scala. Implement the function under crates/spark/src/function/xml/, casting the double result with d as f32, and document it with #[user_doc]. Add crates/sqllogictest/test_files/xml/xpath_float.slt covering the examples plus NaN, float overflow to Infinity, NULL/empty input and the non-foldable-path error; the slt file passing is done.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Part of #271 and apache/datafusion-comet#7300.
What the function does
xpath_float(xml, path) evaluates an XPath 1.0 expression, converts the result with XPath number() into a
Java Double, and then narrows it with Double.floatValue(), giving a FLOAT. 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, and xpath_float is that value cast to f32.
Parsing, DTD and entity handling, namespaces, NULL handling and errors are in the xpath issue. This issue
covers only the double-to-float step.
Examples
SELECT xpath_float('<a><b>1</b><b>2</b></a>', 'sum(a/b)');
-- 3.0
SELECT xpath_float('<a>this is not a number</a>', 'a');
-- NaN
SELECT xpath_float('<a>this 2 is not a number</a>', 'a');
-- NaN
SELECT xpath_float('<a><b>2000000000</b><c>40000000000</c></a>', 'a/b * a/c');
-- 8.0E19
SELECT xpath_float('<a>try a boolean</a>', 'a = 10');
-- 0.0
SELECT xpath_float('<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_float('<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_float('<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_float('<a><b>1.0</b><b>2.1</b></a>', 'sum(a/b)');
-- 3.1
These come from the ExpressionDescription, the Hive udf_xpath_float golden files run by
HiveCompatibilitySuite, XPathExpressionSuite and XPathFunctionsSuite. The last result is
3.1.toFloat, which is the rounded f32 of the double sum 3.1.
Edge cases to test
- The narrowing is Java's
(float) d, which uses IEEE round-to-nearest-even, so in Rust it isd as f32.
A finite double abovef32::MAXbecomesInfinity. XPath has no exponent literal, so build the large value
from element text, for example<a>1000000000000000000000000000000000000000</a>with path'a'. A double
below the smallestf32subnormal becomes0.0or-0.0.1 div 0staysInfinity. - Check that rounding happens once, from the double result.
sum()adds in double and narrows at the end,
so it is not equivalent to addingf32values. NaNstaysNaN(non-numeric text). A false boolean gives0.0.- The empty node-set is
NaNby XPath 1.0 rules, although the usage string says zero. See the note in the
xpath_doubleissue and verify against Spark. 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:
XPathFloatinsql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/xml/xpath.scala.
It callsXPathFloatEvaluator(ret.floatValue()) in.../xml/XmlExpressionEvalUtils.scala. - DataFusion core has no equivalent.
- Reuse the shared
number()evaluator (see thexpathandxpath_doubleissues) in
crates/spark/src/function/xml/, and cast the result tof32. - Tests: add
crates/sqllogictest/test_files/xml/xpath_float.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.
- Lenguaje dominante
- Rust
- Estrellas
- 7
- Forks
- 15
- Merge medio
- 16 h 43 min
- PR fusionados (30 d)
- 26
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/datafusion-spark
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
apache/datafusion-spark#287 ·
Los mantenedores suelen responder en 1 día
-
enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
apache/datafusion-spark#266 ·
Los mantenedores suelen responder en 1 día
-
[Bug] make_dt_interval returns NULL for more than about 1.49 million days, Spark returns the intervalPosiblemente ocupada @Subodh-17 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
apache/datafusion-spark#109 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 18/100
apache/datafusion-spark#299 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
apache/datafusion-spark#298 ·
Los mantenedores suelen responder en 1 día
Todos los issues de apache/datafusion-spark
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
storytold/photocraft#15232 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
suhina-daw/suhina-daw#1477 ·
Los mantenedores suelen responder en 1 día
-
parity priority: low ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
storytold/pdfcraft#7483 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
IngvarConsulting/unica#3097 ·
Los mantenedores suelen responder en 1 día
-
enhancement in-progress
Dificultad 1/5 Menos de una hora Aptitud para principiantes 64/100