-
Notifications
You must be signed in to change notification settings - Fork 190
[BUG] fields starting with __ is missing in the returned result when query by SQL with extra filter #783
Description
What is the bug?
Fields starting with __ is missing in the returned result when query by SQL with extra filter.
How can one reproduce the bug?
Steps to reproduce the behavior:
- Create an index with serval fields, some of them are starting with
__. For example, an indextest, contains a field whose name is '__time'. - Construct some document.
- Query with the SQL
select * from testand extrafilter.
What is the expected behavior?
The result should contains __time.
What is your host/environment?
- environment: docker.
- version: 1.0.1、2.2.0
- plugin: opensearch-sql
Do you have any additional context?
It seems that the query is fallback to legacy sql engine. In this situation, when populating columns, it will ignore meta fields (starting with _).
sql/legacy/src/main/java/org/opensearch/sql/legacy/executor/format/SelectResultSet.java
Lines 434 to 480 in eeb90cf
| /* | |
| * Unnecessary fields (ex. _index, _parent) are ignored. | |
| * Fields like field.keyword will be ignored when isSelectAll is true but will be returned if | |
| * explicitly selected. | |
| */ | |
| FieldMapping field = new FieldMapping(fieldName, typeMappings, fieldMap); | |
| if (!field.isMetaField()) { | |
| if (field.isMultiField() && !field.isSpecified()) { | |
| continue; | |
| } | |
| if (field.isPropertyField() && !field.isSpecified() && !field.isWildcardSpecified()) { | |
| continue; | |
| } | |
| /* | |
| * Three cases regarding Type: | |
| * 1. If Type exists, create Column | |
| * 2. If Type doesn't exist and isSelectAll() is false, throw exception | |
| * 3. If Type doesn't exist and isSelectAll() is true, Column creation for fieldName is skipped | |
| */ | |
| String type = field.type().toUpperCase(); | |
| if (Schema.hasType(type)) { | |
| // If the current field is a group key, we should use alias as the identifier | |
| boolean isGroupKey = false; | |
| Select select = (Select) query; | |
| if (null != select.getGroupBys() | |
| && !select.getGroupBys().isEmpty() | |
| && select.getGroupBys().get(0).contains(fieldMap.get(fieldName))) { | |
| isGroupKey = true; | |
| } | |
| columns.add( | |
| new Schema.Column( | |
| fieldName, | |
| fetchAlias(fieldName, fieldMap), | |
| Schema.Type.valueOf(type), | |
| isGroupKey | |
| ) | |
| ); | |
| } else if (!isSelectAll()) { | |
| throw new IllegalArgumentException( | |
| String.format("%s fieldName types are currently not supported.", type)); | |
| } | |
| } | |
| } |
sql/legacy/src/main/java/org/opensearch/sql/legacy/esdomain/mapping/FieldMapping.java
Lines 95 to 97 in eeb90cf
| public boolean isMetaField() { | |
| return fieldName.startsWith("_"); | |
| } |
