Skip to content
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

SQL: fix object extraction from sources #37502

Merged
merged 4 commits into from
Jan 18, 2019
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 @@ -166,8 +166,14 @@ Object extractFromSource(Map<String, Object> map) {
sj.add(path[i]);
Object node = subMap.get(sj.toString());
if (node instanceof Map) {
// Add the sub-map to the queue along with the current path index
queue.add(new Tuple<>(i, (Map<String, Object>) node));
if (i < path.length - 1) {
// Add the sub-map to the queue along with the current path index
queue.add(new Tuple<>(i, (Map<String, Object>) node));
} else {
// We exhausted the path and got a map
// If it is an object - it will be handled in the value extractor
value = node;
}
} else if (node != null) {
if (i < path.length - 1) {
// If we reach a concrete value without exhausting the full path, something is wrong with the mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ public void testFieldWithDotsAndSamePathButDifferentHierarchy() {
assertThat(ex.getMessage(), is("Multiple values (returned by [a.b.c.d.e.f.g]) are not supported"));
}

public void testObjectsForSourceValue() throws IOException {
String fieldName = randomAlphaOfLength(5);
FieldHitExtractor fe = new FieldHitExtractor(fieldName, null, false);
SearchHit hit = new SearchHit(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you choose to call extract(hit) and not follow the approach as here for example: https://github.com/elastic/elasticsearch/pull/37502/files#diff-9aaee9be08445653bba7407b9f2b5ca3R302

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason. Both approaches would work I think. I can replace it if you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, just wanted to check if there was a particular reason.

XContentBuilder source = JsonXContent.contentBuilder();
source.startObject(); {
source.startObject(fieldName); {
source.field("b", "c");
}
source.endObject();
}
source.endObject();
BytesReference sourceRef = BytesReference.bytes(source);
hit.sourceRef(sourceRef);
SqlException ex = expectThrows(SqlException.class, () -> fe.extract(hit));
assertThat(ex.getMessage(), is("Objects (returned by [" + fieldName + "]) are not supported"));
}

private Object randomValue() {
Supplier<Object> value = randomFrom(Arrays.asList(
() -> randomAlphaOfLength(10),
Expand Down