nick-boss-tech commented on code in PR #5071:
URL: https://github.com/apache/solr/pull/5071#discussion_r4240214704
##########
solr/core/src/java/org/apache/solr/update/processor/ParseNumericFieldUpdateProcessorFactory.java:
##########
@@ -45,8 +46,24 @@ public abstract class ParseNumericFieldUpdateProcessorFactory
private static final String LOCALE_PARAM = "locale";
+ private static final Pattern EXPONENT_PLUS =
Pattern.compile("([eE])\\+(\\d+)$");
+
+ private static final Pattern LOWERCASE_EXPONENT =
Pattern.compile("(\\d)e([+-]?\\d+)$");
+
protected Locale locale = Locale.ROOT;
+ /**
+ * Normalizes a trailing exponent so {@link java.text.NumberFormat} can
parse it, e.g. {@code
+ * 4.5E+10} becomes {@code 4.5E10} and {@code 4.5e-3} becomes {@code
4.5E-3}. NumberFormat accepts
+ * neither a plus sign in the exponent nor a lowercase exponent marker, but
Java, JSON and the
+ * corresponding Solr field types accept both. Both rewrites are anchored to
a trailing exponent,
+ * so a value without one is returned unchanged.
+ */
+ static String normalizeExponent(String value) {
Review Comment:
🤖 *AI text below* 🤖 *(posted on behalf of Nick Shanin)*
**No library Solr has does this job, and for exponent spellings the two
fixes are the complete set.**
I checked the parsers on JDK 21: Double.parseDouble, BigDecimal, and
NumberUtils from commons-lang3 3.20.0, which Solr core already depends on. None
of the three accepts grouping separators or takes a locale. These factories
parse with NumberFormat because it does both, in the configured locale. Its one
gap is exponents: it rejects a plus sign (4.5E+10) and a lowercase marker
(4.5e-3), forms that Java, JSON, and the Solr field types all accept.
The rewrite runs in the Double and Float factories and fixes exactly that
gap: a lowercase e becomes E, and the plus sign in the exponent is removed.
After it, every exponent spelling is accepted: E or e, with +, -, or no sign,
with or without grouping. Other forms stay as they were. Hex floats and a
trailing d suffix stay rejected, as before this change, and the rewrite touches
only a trailing exponent, so a trailing space or a form like 5.e3 still fails.
Those are not spellings JSON or the field types produce.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]