-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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: change the way unsupported data types fields are handled #50823
Conversation
as of UNSUPPORTED type
…o ignore_flattened_fields
Pinging @elastic/es-search (:Search/SQL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if there isn't a generic approach that we can take to treat flattened as unsupported without being aware of it.
That is take into account a multi field starting with _
and potentially looking at the type and notice that we don't recognize it - essentially extending the type discovery to multi fields with special "internal" keys.
x-pack/plugin/sql/build.gradle
Outdated
@@ -39,6 +39,7 @@ check.dependsOn internalClusterTest | |||
|
|||
dependencies { | |||
compileOnly project(path: xpackModule('core'), configuration: 'default') | |||
compileOnly project(path: xpackModule('mapper-flattened')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this creates a runtime issue as plugins that are not marked as extensible (such as Painless) cannot have their classes imported into a different project.
In other words the FlatObjectFieldMapper.CONTENT_TYPE
won't be available which would result in a CNFE.
As such as I would simply declare the String constant internally and use it verbatim instead of linking to it.
@@ -493,6 +495,12 @@ public void resolveAsSeparateMappings(String indexWildcard, String javaRegex, bo | |||
if (typeEntry.getKey().startsWith("_") && typeCap.getType().startsWith("_")) { | |||
continue; | |||
} | |||
|
|||
// skip the "flattened" type of field's "_keyed" subfield |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we cannot make this a bit generic by looking for field names that have leaves starting with _
and if so, look at their type - if its not recognized, mark the field as unsupported.
@elasticmachine run elasticsearch-ci/bwc |
@elasticmachine run elasticsearch-ci/default-distro |
@elasticmachine update branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -495,6 +501,7 @@ public void resolveAsSeparateMappings(String indexWildcard, String javaRegex, bo | |||
if (typeEntry.getKey().startsWith("_") && typeCap.getType().startsWith("_")) { | |||
continue; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: extra new line
…o ignore_flattened_fields
of fields to improve error reporting
…o ignore_flattened_fields
44cf204
to
a9e9296
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - added just a few comments regarding styling.
String inherited = unsupportedParent.getInherited(); | ||
String type = unsupportedParent.getOriginalType(); | ||
|
||
if (inherited == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole block can be further simplified by
esField = new UnsupportedEsField(esField.getName(), type, inherited != null ? inherited : unsupportedParent.getName(), esField.getProperties());
for (Entry<String, EsField> entry : properties.entrySet()) { | ||
EsField field = entry.getValue(); | ||
UnsupportedEsField u; | ||
if (field instanceof UnsupportedEsField) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the if
needed - the result will be the same regardless of whether field is UnsupportedEsField
or not.
@@ -217,8 +217,14 @@ private static Attribute handleSpecialFields(UnresolvedAttribute u, Attribute na | |||
// unsupported types | |||
else if (DataTypes.isUnsupported(fa.dataType())) { | |||
UnsupportedEsField unsupportedField = (UnsupportedEsField) fa.field(); | |||
named = u.withUnresolvedMessage( | |||
"Cannot use field [" + fa.name() + "] type [" + unsupportedField.getOriginalType() + "] as is unsupported"); | |||
if (unsupportedField.hasInherited()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the message is the same in the branch, simply do the if on the prefix
String inheritedMessage = "";
if (unsupportedField.hasInherited()) {
inheritedMessage = format("in hierarchy (field [{}"], unsupportedField.getInherited()));
}
named = u.withUnresolvedMessage(... + inheritedMessage);
Further more replace the string concatenation in the message with MessageFormat.format
to trim it a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm unclear on why propagate unsupported is needed...
@@ -91,7 +91,8 @@ private static void walkMapping(String name, Object value, Map<String, EsField> | |||
break; | |||
case UNSUPPORTED: | |||
String type = content.get("type").toString(); | |||
field = new UnsupportedEsField(name, type); | |||
field = new UnsupportedEsField(name, type, null, properties); | |||
propagateUnsupportedType(name, type, properties); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is propagated needed? The parents should always be discovered before children which means an unsupported parent will discovered before its children, which in turn, will already know their parent is unsupported and thus become unsupported as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@costin If I remember well, the method pair startWalking
-walkMapping
does the discovery the other way around: start with a mapping looking like parent=[child=[another_child=[type:keyword]], type:text], type:foobar]]
, get the parent, look at properties like "it's nested", or "it's object", or "has sub-fields" here, if yes, dig into those and so on and so forth.
Then after discovering all the children, create the parent itself here. So, by the time the algorithm finds out that a root field is unsupported, the children already have some types (their own).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach is used only in the case of some tests that use a .json
file with mappings. I made this change because I wanted to also test the error message (here) that gets printed out from the Analyzer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…c#50823) The hierarchy of fields/sub-fields under a field that is of an unsupported data type will be marked as unsupported as well. Until this change, the behavior was to set the unsupported data type field's hierarchy as empty. Example, considering the following hierarchy of fields/sub-fields a -> b -> c -> d, if b would be of type "foo", then b, c and d will be marked as unsupported. (cherry picked from commit 7adb286)
#51220) The hierarchy of fields/sub-fields under a field that is of an unsupported data type will be marked as unsupported as well. Until this change, the behavior was to set the unsupported data type field's hierarchy as empty. Example, considering the following hierarchy of fields/sub-fields a -> b -> c -> d, if b would be of type "foo", then b, c and d will be marked as unsupported. (cherry picked from commit 7adb286)
#51220) The hierarchy of fields/sub-fields under a field that is of an unsupported data type will be marked as unsupported as well. Until this change, the behavior was to set the unsupported data type field's hierarchy as empty. Example, considering the following hierarchy of fields/sub-fields a -> b -> c -> d, if b would be of type "foo", then b, c and d will be marked as unsupported. (cherry picked from commit 7adb286) (cherry picked from commit df36169)
…c#50823) (elastic#51220) The hierarchy of fields/sub-fields under a field that is of an unsupported data type will be marked as unsupported as well. Until this change, the behavior was to set the unsupported data type field's hierarchy as empty. Example, considering the following hierarchy of fields/sub-fields a -> b -> c -> d, if b would be of type "foo", then b, c and d will be marked as unsupported. (cherry picked from commit 7adb286)
The hierarchy of fields/sub-fields under a field that is of an unsupported data type will be marked as unsupported as well. Until this change, the behavior was to set the unsupported data type field's hierarchy as empty. Example, considering the following hierarchy of fields/sub-fields a -> b -> c -> d, if b would be of type "foo", then b, c and d will be marked as unsupported. (cherry picked from commit 7adb286)
The hierarchy of fields/sub-fields under a field that is of an unsupported data type will be marked as unsupported as well. Until this change, the behavior was to set the unsupported data type field's hierarchy as empty. Example, considering the following hierarchy of fields/sub-fields a -> b -> c -> d, if b would be of type "foo", then b, c and d will be marked as unsupported. (cherry picked from commit 7adb286)
…c#50823) The hierarchy of fields/sub-fields under a field that is of an unsupported data type will be marked as unsupported as well. Until this change, the behavior was to set the unsupported data type field's hierarchy as empty. Example, considering the following hierarchy of fields/subfields a -> b -> c -> d, if b would be of type "foo", then b, c and d will be marked as unsupported.
The backport PR seems to have been merged. I'm therefore removing the backport pending label here. Please shout if this is incorrect |
By default, new field types in SQL are treated as UNSUPPORTED, but because "flattened" adds a
_keyed
sub-field to the flattened field, the fields discovery algorithm in SQL (looking at the output of field_caps API) is broken by the_keyed
suffix.This PR fixes this situation for the "flattened" data type, but also for other future unsupported data types, by marking an entire hierarchy of fields and sub-fields under an unsupported data type field, as unsupported.