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

[BUG] fields starting with __ is missing in the returned result when query by SQL with extra filter #783

Closed
yxwyoyoyo opened this issue Aug 23, 2022 · 4 comments
Labels
bug Something isn't working legacy Issues related to legacy query engine to be deprecated SQL v2.7.0

Comments

@yxwyoyoyo
Copy link

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:

  1. Create an index with serval fields, some of them are starting with __. For example, an index test, contains a field whose name is '__time'.
  2. Construct some document.
  3. Query with the SQL select * from test and extra filter.

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 screenshots?
CleanShot 2022-08-23 at 18 02 21@2x

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 _).

/*
* 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));
}
}
}

public boolean isMetaField() {
return fieldName.startsWith("_");
}

@yxwyoyoyo yxwyoyoyo added bug Something isn't working untriaged labels Aug 23, 2022
@dai-chen
Copy link
Collaborator

@yxwyoyoyo Thanks for reporting the issue! Your investigation is very helpful. In our engine v2, we did miss this support for identifier starting with underscore: https://github.com/opensearch-project/sql/blob/main/sql/src/main/antlr/OpenSearchSQLLexer.g4#L428

Could you elaborate a little your use case and if this kind of naming is required? Thanks!

@dai-chen dai-chen added SQL legacy Issues related to legacy query engine to be deprecated and removed untriaged labels Aug 23, 2022
@yxwyoyoyo
Copy link
Author

yxwyoyoyo commented Aug 24, 2022

@dai-chen In our use case, we provide service based on ES and open the ability to customize mapping. In addition, we have serval system fields to save meta data, so we preserve names start with __ as system fields. We also took other prefixes into consideration, but none of them were ideal.

@dai-chen
Copy link
Collaborator

@dai-chen In our use case, we provide service based on ES and open the ability to customize mapping. In addition, we have serval system fields to save meta data, so we preserve names start with __ as system fields. We also took other prefixes into consideration, but none of them were ideal.

Thanks for the info! Will evaluate if we can support this.

Yury-Fridlyand added a commit to Bit-Quill/opensearch-project-sql that referenced this issue Sep 28, 2022
…pensearch-project#696 and 317 all together. (opensearch-project#479) (opensearch-project#481)

Signed-off-by: Yury Fridlyand <[email protected]>
(cherry picked from commit 646ce3c)

Co-authored-by: Yury-Fridlyand <[email protected]>
Yury-Fridlyand added a commit to Bit-Quill/opensearch-project-sql that referenced this issue Sep 28, 2022
* Disable flaky test in JdbcTestIT. (opensearch-project#475)

Signed-off-by: penghuo <[email protected]>

* Update dependency opensearch-ml-client group name (opensearch-project#477)

Signed-off-by: jackieyanghan <[email protected]>

* Collected fixes related to bugs #280, #302, opensearch-project#783, opensearch-project#696 and 317 all together. (opensearch-project#479)

Signed-off-by: Yury Fridlyand <[email protected]>

* Add JDK 8 to CI Matrix  (opensearch-project#483) (opensearch-project#484)

* fixed references in java 8 and added to ci matrix
* filter test that fails due to jdk 8 bug
* use different degree to radian conversion for difference in jdk
* skip date time format tests that cause error due to jdk bug
* only disable DateTime unit test on Java 8

Bypassing failed DCO check

Signed-off-by: David Cui <[email protected]>
(cherry picked from commit b6fccbd)

Co-authored-by: David Cui <[email protected]>

* Add parse docs to PPL commands index (opensearch-project#486) (opensearch-project#487)

Signed-off-by: Joshua Li <[email protected]>

* Add 1.3.0 release notes (opensearch-project#492)

Signed-off-by: Eugene Lee <[email protected]>

* Add Kmeans and AD command documentation (opensearch-project#493) (opensearch-project#497)

Signed-off-by: jackieyanghan <[email protected]>
(cherry picked from commit ee4bce0)

* Bump version to 1.3.1

Signed-off-by: Sayali Gaikawad <[email protected]>

* Bump ml

Signed-off-by: Sayali Gaikawad <[email protected]>

* Add new zip

Signed-off-by: Sayali Gaikawad <[email protected]>

* Updated release drafter

Signed-off-by: Sayali Gaikawad <[email protected]>

* Remove checked-in ml-commons dependency (opensearch-project#529)

Signed-off-by: jackieyanghan <[email protected]>

* Bump workbench to 1.3.1 (opensearch-project#540)

Signed-off-by: Joshua Li <[email protected]>

* Bug Fix, return default ID when log4j ThreadContext is empty (opensearch-project#538) (opensearch-project#539) (opensearch-project#543)

Signed-off-by: penghuo <[email protected]>
(cherry picked from commit 54b7257)

* Incremented version to 1.3.2. (opensearch-project#593)

Signed-off-by: Zelin Hao <[email protected]>
Signed-off-by: Joshua Li <[email protected]>

Co-authored-by: Joshua Li <[email protected]>

* Version bump 1.3.3

Signed-off-by: pgodithi <[email protected]>

* [1.3] Bump spring-beans to 5.2.20 (opensearch-project#632)

Signed-off-by: Joshua Li <[email protected]>

* Version bump 1.3.3

Signed-off-by: pgodithi <[email protected]>

* Incremented version to 1.3.4. (opensearch-project#681)

* Incremented version to 1.3.4.

Signed-off-by: Zelin Hao <[email protected]>

* bump jackson to 2.13.2

Signed-off-by: Joshua Li <[email protected]>

Co-authored-by: Joshua Li <[email protected]>

Co-authored-by: Peng Huo <[email protected]>
Co-authored-by: Jackie Han <[email protected]>
Co-authored-by: Yury-Fridlyand <[email protected]>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: David Cui <[email protected]>
Co-authored-by: Eugene Lee <[email protected]>
Co-authored-by: Sayali Gaikawad <[email protected]>
Co-authored-by: Sayali Gaikawad <[email protected]>
Co-authored-by: Joshua Li <[email protected]>
Co-authored-by: Zelin Hao <[email protected]>
Co-authored-by: pgodithi <[email protected]>
Co-authored-by: Anirudha (Ani) Jadhav <[email protected]>
Yury-Fridlyand added a commit to Bit-Quill/opensearch-project-sql that referenced this issue Sep 29, 2022
@acarbonetto
Copy link
Collaborator

@dai-chen this issue can be closed as part of #1456
We now accept any field with __ or _ so long as the field is not reserved by OpenSearch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working legacy Issues related to legacy query engine to be deprecated SQL v2.7.0
Projects
None yet
Development

No branches or pull requests

4 participants