Skip to content

Commit

Permalink
Rework on 53c4fdd. New fix has code coverage and all test passed on it.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
  • Loading branch information
Yury-Fridlyand committed Jan 6, 2023
1 parent 43a0a98 commit 1f7b151
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,15 @@ public static Map<String, OpenSearchDataType> traverseAndFlatten(
Map<String, OpenSearchDataType> result = new LinkedHashMap<>();
for (var entry : tree.entrySet()) {
result.put(entry.getKey(), entry.getValue().cloneEmpty());
result.putAll((Map<String, OpenSearchDataType>)
result.putAll(//(Map<String, OpenSearchDataType>)
traverseAndFlatten(entry.getValue().properties)
.entrySet().stream()
.collect(Collectors.toMap(
e -> String.format("%s.%s", entry.getKey(), e.getKey()),
e -> e.getValue(), (x, y) -> y, LinkedHashMap::new)));
.collect(
LinkedHashMap::new,
(map, item) -> map.put(
String.format("%s.%s", entry.getKey(), item.getKey()),
item.getValue()),
Map::putAll));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ public Map<String, ExprType> getFieldTypes() {
cachedFieldTypes = new OpenSearchDescribeIndexRequest(client, indexName).getFieldTypes();
}
return OpenSearchDataType.traverseAndFlatten(cachedFieldTypes).entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().getExprType(),
(x, y) -> y, LinkedHashMap::new));
.collect(
LinkedHashMap::new,
(map, item) -> map.put(item.getKey(), item.getValue()),
Map::putAll);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ void getFieldTypes() {
fieldTypes,
allOf(
aMapWithSize(13),
hasEntry("name", ExprCoreType.STRING),
hasEntry("address", (ExprType) OpenSearchDataType.of(Text)),
hasEntry("age", ExprCoreType.INTEGER),
hasEntry("account_number", ExprCoreType.LONG),
hasEntry("balance1", ExprCoreType.FLOAT),
hasEntry("balance2", ExprCoreType.DOUBLE),
hasEntry("gender", ExprCoreType.BOOLEAN),
hasEntry("family", ExprCoreType.ARRAY),
hasEntry("employer", ExprCoreType.STRUCT),
hasEntry("birthday", ExprCoreType.TIMESTAMP),
hasEntry("id1", ExprCoreType.BYTE),
hasEntry("id2", ExprCoreType.SHORT),
hasEntry("blob", (ExprType) OpenSearchDataType.of(Binary))
hasEntry("name", OpenSearchDataType.of(ExprCoreType.STRING)),
hasEntry("address", OpenSearchDataType.of(Text)),
hasEntry("age", OpenSearchDataType.of(ExprCoreType.INTEGER)),
hasEntry("account_number", OpenSearchDataType.of(ExprCoreType.LONG)),
hasEntry("balance1", OpenSearchDataType.of(ExprCoreType.FLOAT)),
hasEntry("balance2", OpenSearchDataType.of(ExprCoreType.DOUBLE)),
hasEntry("gender", OpenSearchDataType.of(ExprCoreType.BOOLEAN)),
hasEntry("family", OpenSearchDataType.of(ExprCoreType.ARRAY)),
hasEntry("employer", OpenSearchDataType.of(ExprCoreType.STRUCT)),
hasEntry("birthday", OpenSearchDataType.of(ExprCoreType.TIMESTAMP)),
hasEntry("id1", OpenSearchDataType.of(ExprCoreType.BYTE)),
hasEntry("id2", OpenSearchDataType.of(ExprCoreType.SHORT)),
hasEntry("blob", OpenSearchDataType.of(Binary))
));
}

Expand All @@ -146,15 +146,15 @@ void checkCacheUsedForFieldMappings() {
OpenSearchIndex index = new OpenSearchIndex(client, settings, "test");
assertThat(index.getFieldTypes(), allOf(
aMapWithSize(1),
hasEntry("name", STRING)));
hasEntry("name", OpenSearchDataType.of(ExprCoreType.STRING))));

//Change mocked response, but `getFieldTypes` should return cached value
lenient().when(client.getIndexMappings("test")).thenReturn(
ImmutableMap.of("test", new IndexMapping(ImmutableMap.of("name", "text"))));

assertThat(index.getFieldTypes(), allOf(
aMapWithSize(1),
hasEntry("name", STRING)));
hasEntry("name", OpenSearchDataType.of(ExprCoreType.STRING))));
}

@Test
Expand Down

0 comments on commit 1f7b151

Please sign in to comment.