-
Notifications
You must be signed in to change notification settings - Fork 199
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 8 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
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 |
|---|---|---|
|
|
@@ -354,4 +354,102 @@ public void testDependedLateralEval() { | |
| + "GROUP BY `DEPTNO`"; | ||
| verifyPPLToSparkSQL(root, expectedSparkSql); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEvalStringConcatenationWithPlus() { | ||
|
ahkcs marked this conversation as resolved.
Outdated
|
||
| String ppl = | ||
| "source=EMP | eval full_name = ENAME + ' ' + JOB | fields EMPNO, ENAME, JOB, full_name |" | ||
| + " head 3"; | ||
| RelNode root = getRelNode(ppl); | ||
| String expectedLogical = | ||
| "LogicalSort(fetch=[3])\n" | ||
| + " LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], full_name=[||(||($1, ' ')," | ||
| + " $2)])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n"; | ||
| verifyLogical(root, expectedLogical); | ||
|
|
||
| String expectedSparkSql = | ||
| "SELECT `EMPNO`, `ENAME`, `JOB`, `ENAME` || ' ' || `JOB` `full_name`\n" | ||
| + "FROM `scott`.`EMP`\n" | ||
| + "LIMIT 3"; | ||
| verifyPPLToSparkSQL(root, expectedSparkSql); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEvalStringConcatenationWithNullableField() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be removed since concatenating string with null operands is actually verified in IT
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
| // Test with COMM field which naturally contains nulls in the EMP table | ||
| // When COMM is null, concatenation should result in null per SQL standard | ||
| String ppl = | ||
| "source=EMP | eval " | ||
| + "comm_desc = 'Commission: ' + CAST(COMM AS STRING) " | ||
| + "| fields EMPNO, ENAME, COMM, comm_desc | head 5"; | ||
| RelNode root = getRelNode(ppl); | ||
|
|
||
| String expectedLogical = | ||
| "LogicalSort(fetch=[5])\n" | ||
| + " LogicalProject(EMPNO=[$0], ENAME=[$1], COMM=[$6], " | ||
| + "comm_desc=[||('Commission: ':VARCHAR, NUMBER_TO_STRING($6))])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n"; | ||
| verifyLogical(root, expectedLogical); | ||
|
|
||
| String expectedSparkSql = | ||
| "SELECT `EMPNO`, `ENAME`, `COMM`, " | ||
| + "'Commission: ' || `NUMBER_TO_STRING`(`COMM`) `comm_desc`\n" | ||
| + "FROM `scott`.`EMP`\n" | ||
| + "LIMIT 5"; | ||
| verifyPPLToSparkSQL(root, expectedSparkSql); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEvalStringConcatenationChained() { | ||
| // Test chained concatenation | ||
| String ppl = | ||
| "source=EMP | eval " | ||
| + "description = ENAME + ' - ' + JOB + ' (Dept: ' + CAST(DEPTNO AS STRING) + ')' " | ||
| + "| where EMPNO IN (7369, 7499) | fields EMPNO, description"; | ||
| RelNode root = getRelNode(ppl); | ||
|
|
||
| String expectedLogical = | ||
| "LogicalProject(EMPNO=[$0], description=[$8])\n" | ||
| + " LogicalFilter(condition=[SEARCH($0, Sarg[7369, 7499])])\n" | ||
| + " LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4]," | ||
| + " SAL=[$5], COMM=[$6], DEPTNO=[$7], description=[||(||(||(||(||($1, ' - ':VARCHAR)," | ||
| + " $2), ' (Dept: ':VARCHAR), SAFE_CAST($7)), ')')])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n"; | ||
| verifyLogical(root, expectedLogical); | ||
|
|
||
| String expectedSparkSql = | ||
| "SELECT `EMPNO`, `description`\n" | ||
| + "FROM (SELECT `EMPNO`, `ENAME`, `JOB`, `MGR`, `HIREDATE`, `SAL`, `COMM`, `DEPTNO`," | ||
| + " `ENAME` || ' - ' || `JOB` || ' (Dept: ' || SAFE_CAST(`DEPTNO` AS STRING) || ')'" | ||
| + " `description`\n" | ||
| + "FROM `scott`.`EMP`) `t`\n" | ||
| + "WHERE `EMPNO` IN (7369, 7499)"; | ||
| verifyPPLToSparkSQL(root, expectedSparkSql); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEvalStringConcatenationMultipleExpressions() { | ||
| // Test multiple concatenation expressions in a single eval command | ||
| String ppl = | ||
| "source=EMP | eval " | ||
| + "name_job = ENAME + ' - ' + JOB, " | ||
| + "name_dept = ENAME + ' (Dept ' + CAST(DEPTNO AS STRING) + ')' " | ||
| + "| fields EMPNO, name_job, name_dept | head 2"; | ||
| RelNode root = getRelNode(ppl); | ||
|
|
||
| String expectedLogical = | ||
| "LogicalSort(fetch=[2])\n" | ||
| + " LogicalProject(EMPNO=[$0], name_job=[||(||($1, ' - ':VARCHAR), $2)], " | ||
| + "name_dept=[||(||(||($1, ' (Dept ':VARCHAR), SAFE_CAST($7)), ')')])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n"; | ||
| verifyLogical(root, expectedLogical); | ||
|
|
||
| String expectedSparkSql = | ||
| "SELECT `EMPNO`, `ENAME` || ' - ' || `JOB` `name_job`, " | ||
| + "`ENAME` || ' (Dept ' || SAFE_CAST(`DEPTNO` AS STRING) || ')' `name_dept`\n" | ||
| + "FROM `scott`.`EMP`\n" | ||
| + "LIMIT 2"; | ||
| verifyPPLToSparkSQL(root, expectedSparkSql); | ||
| } | ||
| } | ||
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.