8000 #1826 fix JsonFieldSelectorTrie logic for objects and parts of those objects both being included in selected fields by thjaeckle · Pull Request #1828 · eclipse-ditto/ditto · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

#1826 fix JsonFieldSelectorTrie logic for objects and parts of those objects both being included in selected fields #1828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,21 @@ private JsonFieldSelectorTrie addJsonKeyIterator(final Iterator<JsonKey> iterato
if (iterator.hasNext()) {
final JsonKey key = iterator.next();
children.compute(key, (theKey, theChild) -> {
final JsonFieldSelectorTrie child = theChild != null ? theChild : new JsonFieldSelectorTrie();
final JsonFieldSelectorTrie child;
if (theChild != null) {
if (iterator.hasNext()) {
if (theChild.children.isEmpty()) {
return theChild;
} else {
child = theChild;
}
} else {
child = new JsonFieldSelectorTrie();
}
} else {
child = new JsonFieldSelectorTrie();
}

return child.addJsonKeyIterator(iterator);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,36 @@ public void trieWithNonemptyPaths() {
assertThat(getDescendantKeys(underTest, "c")).isEmpty();
}

@Test
public void trieWithJsonObjectAndCertainFieldInSameJsonObject() {
// given
// a field selector containing both, a "field" inside an "object" and the "object" itself
final JsonFieldSelector fieldSelector = JsonFieldSelector.newInstance("object/field", "object");

// when
final JsonFieldSelectorTrie underTest = JsonFieldSelectorTrie.of(fieldSelector);

// then
assertThat(getDescendantKeys(underTest)).isEqualTo(keySetOf("object"));
// ensure that not only the "field" is contained, but the complete "object" instead:
assertThat(getDescendantKeys(underTest, "object")).isEmpty();
}

@Test
public void trieWithJsonObjectAndCertainFieldInSameJsonObjectOrderSwapped() {
// given
// a field selector containing both, a "field" inside an "object" and the "object" itself
final JsonFieldSelector fieldSelectorReverse = JsonFieldSelector.newInstance("object", "object/field");

// when
final JsonFieldSelectorTrie underTestReverse = JsonFieldSelectorTrie.of(fieldSelectorReverse);

// then
assertThat(getDescendantKeys(underTestReverse)).isEqualTo(keySetOf("object"));
// ensure that not only the "field" is contained, but the complete "object" instead:
assertThat(getDescendantKeys(underTestReverse, "object")).isEmpty();
}

private static Set<JsonKey> keySetOf(final String... keyNames) {
return Arrays.stream(keyNames).map(JsonKey::of).collect(Collectors.toSet());
}
Expand Down
0