Skip to content

Commit

Permalink
Updated the number normalizer to not fail when it cannot normalize with
Browse files Browse the repository at this point in the history
the assumption that the regex is already for a normalized number.
  • Loading branch information
ivakegg committed Sep 9, 2024
1 parent 68034a1 commit ee8bb83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/datawave/data/normalizer/NumberNormalizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import datawave.data.normalizer.regex.NumericRegexEncoder;
import datawave.data.type.util.NumericalEncoder;
import org.apache.log4j.Logger;

public class NumberNormalizer extends AbstractNormalizer<BigDecimal> {

private static final long serialVersionUID = -2781476072987375820L;
private Logger log = Logger.getLogger(NumberNormalizer.class);

public String normalize(String fv) {
if (NumericalEncoder.isPossiblyEncoded(fv)) {
Expand All @@ -32,7 +34,8 @@ public String normalizeRegex(String fieldRegex) {
try {
return NumericRegexEncoder.encode(fieldRegex);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Failed to normalize numeric field pattern '" + fieldRegex + "'", e);
log.debug("Failed to normalize numeric field pattern '" + fieldRegex + "', returning regex as is", e);
return fieldRegex;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void testNormalizingEquivalentZeroes() {
assertNormalizeResult("0", "+AE0");
assertNormalizeResult("0.0", "+AE0");
}

private void assertNormalizeResult(String input, String expected) {
assertEquals(normalizer.normalize(input), expected);
}
Expand Down Expand Up @@ -181,6 +181,10 @@ void testRandomRegexPatterns() {
// check the normalized match
assertThat(Pattern.compile(normalizedPattern).matcher(normalizedNum).matches())
.as("matching \n\"" + pattern + "\" -> \n\"" + normalizedPattern + "\"\n to " + num + " -> " + normalizedNum).isTrue();

// reormalize the pattern.
String renormalizedPattern = normalizer.normalizeRegex(normalizedPattern);
assertEquals(renormalizedPattern, normalizedPattern);
}
}
}
Expand Down

0 comments on commit ee8bb83

Please sign in to comment.