Skip to content

Commit

Permalink
Clean up unused validateFieldName() and use existing methods for Text…
Browse files Browse the repository at this point in the history
…EmbeddingProcessorIT (opensearch-project#1074)

Signed-off-by: Yizhe Liu <[email protected]>
  • Loading branch information
yizheliu-amazon authored Jan 8, 2025
1 parent 5b9f43b commit fea0a7f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,30 +296,6 @@ private static void unflattenSingleItem(String key, Object value, Map<String, Ob
}
}

/**
* Validate if field name is in correct format, which is either "a", or "a.b.c".
* If field name is like "..a..b", "a..b", "a.b..", it should be invalid.
* This is done via checking if a string contains empty segments when split by dots.
*
* @param input the string to check
* @throws IllegalArgumentException if the input is null or has invalid dot usage
*/
private static void validateFieldName(String input) {
if (StringUtils.isBlank(input)) {
throw new IllegalArgumentException("Field name cannot be null or empty");
}

// Use split with -1 limit to preserve trailing empty strings
String[] segments = input.split("\\.", -1);

// Check if any segment is empty
for (String segment : segments) {
if (StringUtils.isBlank(segment)) {
throw new IllegalArgumentException(String.format(Locale.ROOT, "Field name '%s' contains invalid dot usage", input));
}
}
}

// Helper classes to maintain state during iteration
private static class ProcessJsonObjectItem {
String key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,9 @@ public void testNestedFieldMapping_whenDocumentInListIngested_thenSuccessful() t
Map<String, Object> searchResponseAsMap = search(INDEX_NAME, queryNestedHighLevel, 2);
assertNotNull(searchResponseAsMap);

Map<String, Object> hits = (Map<String, Object>) searchResponseAsMap.get("hits");
assertNotNull(hits);

List<Map<String, Object>> listOfHits = (List<Map<String, Object>>) hits.get("hits");
assertNotNull(listOfHits);
assertEquals(1, listOfHits.size());
assertEquals(1, getHitCount(searchResponseAsMap));

Map<String, Object> innerHitDetails = listOfHits.getFirst();
Map<String, Object> innerHitDetails = getFirstInnerHit(searchResponseAsMap);
assertEquals("5", innerHitDetails.get("_id"));
} finally {
wipeOfTestResources(INDEX_NAME, PIPELINE_NAME, modelId, null);
Expand Down

0 comments on commit fea0a7f

Please sign in to comment.