generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 180
Fix PPL eval command string concatenation with + operator #4020
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5e19bf3
eval command support
ahkcs e181038
improvment
ahkcs e960732
Refactor
ahkcs 8525975
fix CI
ahkcs 4246bda
fix CI
ahkcs 49d2f20
fix CI
ahkcs 1154ef5
fixes
ahkcs 2030260
fix
ahkcs e6ab54d
Add IT
ahkcs 46f715a
remove redundant tests
ahkcs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteEvalCommandIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.calcite.remote; | ||
|
|
||
| import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; | ||
| import static org.opensearch.sql.util.MatcherUtils.rows; | ||
| import static org.opensearch.sql.util.MatcherUtils.schema; | ||
| import static org.opensearch.sql.util.MatcherUtils.verifyDataRows; | ||
| import static org.opensearch.sql.util.MatcherUtils.verifySchema; | ||
|
|
||
| import java.io.IOException; | ||
| import org.json.JSONObject; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.opensearch.client.Request; | ||
| import org.opensearch.sql.ppl.PPLIntegTestCase; | ||
|
|
||
| public class CalciteEvalCommandIT extends PPLIntegTestCase { | ||
|
|
||
| @Override | ||
| public void init() throws Exception { | ||
| super.init(); | ||
| enableCalcite(); | ||
|
|
||
| loadIndex(Index.BANK); | ||
|
|
||
| // Create test data for string concatenation | ||
| Request request1 = new Request("PUT", "/test_eval/_doc/1?refresh=true"); | ||
| request1.setJsonEntity("{\"name\": \"Alice\", \"age\": 25, \"title\": \"Engineer\"}"); | ||
| client().performRequest(request1); | ||
|
|
||
| Request request2 = new Request("PUT", "/test_eval/_doc/2?refresh=true"); | ||
| request2.setJsonEntity("{\"name\": \"Bob\", \"age\": 30, \"title\": \"Manager\"}"); | ||
| client().performRequest(request2); | ||
|
|
||
| Request request3 = new Request("PUT", "/test_eval/_doc/3?refresh=true"); | ||
| request3.setJsonEntity("{\"name\": \"Charlie\", \"age\": null, \"title\": \"Analyst\"}"); | ||
| client().performRequest(request3); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEvalStringConcatenation() throws IOException { | ||
| JSONObject result = executeQuery("source=test_eval | eval greeting = 'Hello ' + name"); | ||
| verifySchema( | ||
| result, | ||
| schema("name", "string"), | ||
| schema("title", "string"), | ||
| schema("age", "bigint"), | ||
| schema("greeting", "string")); | ||
| verifyDataRows( | ||
| result, | ||
| rows("Alice", "Engineer", 25, "Hello Alice"), | ||
| rows("Bob", "Manager", 30, "Hello Bob"), | ||
| rows("Charlie", "Analyst", null, "Hello Charlie")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEvalStringConcatenationWithNullField() throws IOException { | ||
| JSONObject result = | ||
| executeQuery( | ||
| "source=test_eval | eval age_desc = 'Age: ' + CAST(age AS STRING) | fields name, age," | ||
| + " age_desc"); | ||
| verifySchema( | ||
| result, schema("name", "string"), schema("age", "bigint"), schema("age_desc", "string")); | ||
| verifyDataRows( | ||
| result, | ||
| rows("Alice", 25, "Age: 25"), | ||
| rows("Bob", 30, "Age: 30"), | ||
| rows("Charlie", null, null)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEvalStringConcatenationWithLiterals() throws IOException { | ||
| JSONObject result = | ||
| executeQuery( | ||
| "source=test_eval | eval full_info = 'Name: ' + name + ', Title: ' + title | fields" | ||
| + " name, title, full_info"); | ||
| verifySchema( | ||
| result, schema("name", "string"), schema("title", "string"), schema("full_info", "string")); | ||
| verifyDataRows( | ||
| result, | ||
| rows("Alice", "Engineer", "Name: Alice, Title: Engineer"), | ||
| rows("Bob", "Manager", "Name: Bob, Title: Manager"), | ||
| rows("Charlie", "Analyst", "Name: Charlie, Title: Analyst")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEvalStringConcatenationWithExistingData() throws IOException { | ||
| JSONObject result = | ||
| executeQuery( | ||
| String.format( | ||
| "source=%s | eval full_name = firstname + ' ' + lastname | head 3 | fields" | ||
| + " firstname, lastname, full_name", | ||
| TEST_INDEX_BANK)); | ||
| verifySchema( | ||
| result, | ||
| schema("firstname", "string"), | ||
| schema("lastname", "string"), | ||
| schema("full_name", "string")); | ||
| verifyDataRows( | ||
| result, | ||
| rows("Amber JOHnny", "Duke Willmington", "Amber JOHnny Duke Willmington"), | ||
| rows("Hattie", "Bond", "Hattie Bond"), | ||
| rows("Nanette", "Bates", "Nanette Bates")); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.