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

handle empty object field #2217

Closed
wants to merge 6 commits into from
Closed

handle empty object field #2217

wants to merge 6 commits into from

Conversation

luhhujbb
Copy link
Contributor

@luhhujbb luhhujbb commented Dec 6, 2019

In some indexes mapping, I've some field with this structure:

"myEmptyObjectField": {
"type": "object"
}

Since mapping is dynamic on these indexes, and object is empty elasticsearch cannot guess a type for sub fields, so it has "object" type. (ie empty object).

Because presto row type need at least one field, I just add a condition to drop the field, so that index is queryable.

@cla-bot cla-bot bot added the cla-signed label Dec 6, 2019
@luhhujbb
Copy link
Contributor Author

luhhujbb commented Dec 6, 2019

Same PR as #2209 but with right commit signature and test added.

@martint martint self-requested a review December 6, 2019 13:43
@@ -456,9 +456,12 @@ public IndexMetadata getIndexMetadata(String index)
}
result.add(new IndexMetadata.Field(name, new IndexMetadata.DateTimeType(formats)));
}
else {
else if (!type.equals("object")) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is correct. According to Elasticsearch docs (https://www.elastic.co/guide/en/elasticsearch/reference/current/object.html):

You are not required to set the field type to object explicitly, as this is the default value.

This seems to imply that a mapping that contains fields can have an explicit type = "object", which means it would be excluded. Instead, we should check whether the field has type object and empty properties to skip it.

Copy link
Contributor Author

@luhhujbb luhhujbb Dec 24, 2019

Choose a reason for hiding this comment

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

I agree with the way you understand documentation, however in elasticsearch mapping implementation, we have :
https://github.com/elastic/elasticsearch/blob/d1334b812226acbe48fdae84bbf841c484d6e675/server/src/main/java/org/elasticsearch/index/mapper/ObjectMapper.java#L534

So when you put a mapping, the type object is optional, and when you read it, it is removed except when mapping of this object is empty.

Anyway, if you want I can add the condition on properties also, as a double check.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the pointers!

This whole section can now be simplified to make the checks more explicit and the flow easier to follow:

String type = "object";
if (value.has("type")) {
    type = value.get("type").asText();
}

switch (type) {
    case "date":
        ...
        break;
    case "object":
        if (value.has("properties")) {
            result.add(new IndexMetadata.Field(name, parseType(value.get("properties"))));
        }
        else {
            LOG.debug("Ignoring empty object field: %s", name);
        }
        break;
    default:
        result.add(new IndexMetadata.Field(name, new IndexMetadata.PrimitiveType(type)));
}

@luhhujbb
Copy link
Contributor Author

luhhujbb commented Dec 24, 2019 via email

@martint
Copy link
Member

martint commented Dec 26, 2019

Merged as c84e70f. Thanks for your contribution!

@martint martint closed this Dec 26, 2019
@martint martint mentioned this pull request Dec 26, 2019
6 tasks
@martint martint added this to the 328 milestone Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants