generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 180
mvjoin support in PPL Caclite
#4217
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
bbacdcd
mvjoin support in PPL Caclite
ps48 5259ac5
fix texts
ps48 bf80878
update docs
ps48 8b8a1c1
update doc examples
ps48 4875c8a
rebase main, update test
ps48 b74c8ee
update test with real array fields
ps48 7937bb6
use verifyQueryThrowsException in CalcitePPLFunctionTypeTest
ps48 9e8b850
spotless check fix
ps48 94034bc
remove string,string registration for mvjoin
ps48 1823f0c
remove string,string test
ps48 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
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
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
6 changes: 6 additions & 0 deletions
6
integ-test/src/test/resources/expectedOutput/calcite/explain_mvjoin.json
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,6 @@ | ||
| { | ||
| "calcite": { | ||
| "logical": "LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])\n LogicalSort(fetch=[1])\n LogicalProject(result=[ARRAY_JOIN(array('a', 'b', 'c'), ',')])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n", | ||
| "physical": "EnumerableCalc(expr#0..16=[{inputs}], expr#17=['a'], expr#18=['b'], expr#19=['c'], expr#20=[array($t17, $t18, $t19)], expr#21=[','], expr#22=[ARRAY_JOIN($t20, $t21)], result=[$t22])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]], PushDownContext=[[LIMIT->1, LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"size\":1,\"timeout\":\"1m\"}, requestedTotalSize=1, pageSize=null, startFrom=0)])\n" | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
integ-test/src/test/resources/expectedOutput/calcite_no_pushdown/explain_mvjoin.json
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,6 @@ | ||
| { | ||
| "calcite": { | ||
| "logical": "LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])\n LogicalSort(fetch=[1])\n LogicalProject(result=[ARRAY_JOIN(array('a', 'b', 'c'), ',')])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n", | ||
| "physical": "EnumerableLimit(fetch=[10000])\n EnumerableCalc(expr#0..16=[{inputs}], expr#17=['a'], expr#18=['b'], expr#19=['c'], expr#20=[array($t17, $t18, $t19)], expr#21=[','], expr#22=[ARRAY_JOIN($t20, $t21)], result=[$t22])\n EnumerableLimit(fetch=[1])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n" | ||
| } | ||
| } |
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
109 changes: 109 additions & 0 deletions
109
ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLArrayFunctionTest.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,109 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.ppl.calcite; | ||
|
|
||
| import org.apache.calcite.rel.RelNode; | ||
| import org.apache.calcite.test.CalciteAssert; | ||
| import org.junit.Test; | ||
|
|
||
| public class CalcitePPLArrayFunctionTest extends CalcitePPLAbstractTest { | ||
|
|
||
| public CalcitePPLArrayFunctionTest() { | ||
| super(CalciteAssert.SchemaSpec.SCOTT_WITH_TEMPORAL); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMvjoinWithStringArray() { | ||
| String ppl = | ||
| "source=EMP | eval joined = mvjoin(array('a', 'b', 'c'), ',') | head 1 | fields joined"; | ||
| RelNode root = getRelNode(ppl); | ||
|
|
||
| String expectedLogical = | ||
| "LogicalProject(joined=[$8])\n" | ||
| + " LogicalSort(fetch=[1])\n" | ||
| + " LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4]," | ||
| + " SAL=[$5], COMM=[$6], DEPTNO=[$7], joined=[ARRAY_JOIN(array('a', 'b', 'c'), ',')])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n"; | ||
| verifyLogical(root, expectedLogical); | ||
|
|
||
| String expectedResult = "joined=a,b,c\n"; | ||
| verifyResult(root, expectedResult); | ||
|
|
||
| String expectedSparkSql = | ||
| "SELECT ARRAY_JOIN(`array`('a', 'b', 'c'), ',') `joined`\n" | ||
| + "FROM `scott`.`EMP`\n" | ||
| + "LIMIT 1"; | ||
| verifyPPLToSparkSQL(root, expectedSparkSql); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMvjoinWithDifferentDelimiter() { | ||
| String ppl = | ||
| "source=EMP | eval joined = mvjoin(array('apple', 'banana', 'cherry'), ' | ') | head 1 |" | ||
| + " fields joined"; | ||
| RelNode root = getRelNode(ppl); | ||
|
|
||
| String expectedLogical = | ||
| "LogicalProject(joined=[$8])\n" | ||
| + " LogicalSort(fetch=[1])\n" | ||
| + " LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4]," | ||
| + " SAL=[$5], COMM=[$6], DEPTNO=[$7], joined=[ARRAY_JOIN(array('apple':VARCHAR," | ||
| + " 'banana':VARCHAR, 'cherry':VARCHAR), ' | ':VARCHAR)])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n"; | ||
| verifyLogical(root, expectedLogical); | ||
|
|
||
| String expectedResult = "joined=apple | banana | cherry\n"; | ||
| verifyResult(root, expectedResult); | ||
|
|
||
| String expectedSparkSql = | ||
| "SELECT ARRAY_JOIN(`array`('apple', 'banana', 'cherry'), ' | ') `joined`\n" | ||
| + "FROM `scott`.`EMP`\n" | ||
| + "LIMIT 1"; | ||
| verifyPPLToSparkSQL(root, expectedSparkSql); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMvjoinWithEmptyArray() { | ||
| String ppl = "source=EMP | eval joined = mvjoin(array(), ',') | head 1 | fields joined"; | ||
| RelNode root = getRelNode(ppl); | ||
|
|
||
| String expectedLogical = | ||
| "LogicalProject(joined=[$8])\n" | ||
| + " LogicalSort(fetch=[1])\n" | ||
| + " LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4]," | ||
| + " SAL=[$5], COMM=[$6], DEPTNO=[$7], joined=[ARRAY_JOIN(array(), ',')])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n"; | ||
| verifyLogical(root, expectedLogical); | ||
|
|
||
| String expectedResult = "joined=\n"; | ||
| verifyResult(root, expectedResult); | ||
|
|
||
| String expectedSparkSql = | ||
| "SELECT ARRAY_JOIN(`array`(), ',') `joined`\n" + "FROM `scott`.`EMP`\n" + "LIMIT 1"; | ||
| verifyPPLToSparkSQL(root, expectedSparkSql); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMvjoinWithFieldReference() { | ||
| String ppl = | ||
| "source=EMP | eval joined = mvjoin(array(ENAME, JOB), '-') | head 1 | fields joined"; | ||
| RelNode root = getRelNode(ppl); | ||
|
|
||
| String expectedLogical = | ||
| "LogicalProject(joined=[$8])\n" | ||
| + " LogicalSort(fetch=[1])\n" | ||
| + " LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4]," | ||
| + " SAL=[$5], COMM=[$6], DEPTNO=[$7], joined=[ARRAY_JOIN(array($1, $2), '-')])\n" | ||
| + " LogicalTableScan(table=[[scott, EMP]])\n"; | ||
| verifyLogical(root, expectedLogical); | ||
|
|
||
| String expectedSparkSql = | ||
| "SELECT ARRAY_JOIN(`array`(`ENAME`, `JOB`), '-') `joined`\n" | ||
| + "FROM `scott`.`EMP`\n" | ||
| + "LIMIT 1"; | ||
| verifyPPLToSparkSQL(root, expectedSparkSql); | ||
| } | ||
| } |
Oops, something went wrong.
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.