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

Implement ppl join command with Calcite #3364

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@
import static org.opensearch.sql.legacy.TestUtils.getEmployeeNestedTypeIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getGameOfThronesIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getGeopointIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getHobbiesIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getJoinTypeIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getLocationIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getMappingFile;
import static org.opensearch.sql.legacy.TestUtils.getNestedSimpleIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getNestedTypeIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getOccupationIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getOdbcIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getOrderIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getPeople2IndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getPhraseIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getResponseBody;
import static org.opensearch.sql.legacy.TestUtils.getStateCountryIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getStringIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getUnexpandedObjectIndexMapping;
import static org.opensearch.sql.legacy.TestUtils.getWeblogsIndexMapping;
Expand Down Expand Up @@ -745,7 +748,22 @@ public enum Index {
TestsConstants.TEST_INDEX_GEOPOINT,
"dates",
getGeopointIndexMapping(),
"src/test/resources/geopoints.json");
"src/test/resources/geopoints.json"),
STATE_COUNTRY(
TestsConstants.TEST_INDEX_STATE_COUNTRY,
"state_country",
getStateCountryIndexMapping(),
"src/test/resources/state_country.json"),
OCCUPATION(
TestsConstants.TEST_INDEX_OCCUPATION,
"occupation",
getOccupationIndexMapping(),
"src/test/resources/occupation.json"),
HOBBIES(
TestsConstants.TEST_INDEX_HOBBIES,
"hobbies",
getHobbiesIndexMapping(),
"src/test/resources/hobbies.json");

private final String name;
private final String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ public static String getGeopointIndexMapping() {
return getMappingFile(mappingFile);
}

public static String getStateCountryIndexMapping() {
String mappingFile = "state_country_index_mapping.json";
return getMappingFile(mappingFile);
}

public static String getOccupationIndexMapping() {
String mappingFile = "occupation_index_mapping.json";
return getMappingFile(mappingFile);
}

public static String getHobbiesIndexMapping() {
String mappingFile = "hobbies_index_mapping.json";
return getMappingFile(mappingFile);
}

public static void loadBulk(Client client, String jsonPath, String defaultIndex)
throws Exception {
System.out.println(String.format("Loading file %s into opensearch cluster", jsonPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public class TestsConstants {
public static final String TEST_INDEX_NESTED_WITH_NULLS = TEST_INDEX + "_nested_with_nulls";
public static final String TEST_INDEX_GEOPOINT = TEST_INDEX + "_geopoint";
public static final String DATASOURCES = ".ql-datasources";
public static final String TEST_INDEX_STATE_COUNTRY = TEST_INDEX + "_state_country";
public static final String TEST_INDEX_OCCUPATION = TEST_INDEX + "_occupation";
public static final String TEST_INDEX_HOBBIES = TEST_INDEX + "_hobbies";

public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
public static final String TS_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
Expand Down
16 changes: 16 additions & 0 deletions integ-test/src/test/resources/hobbies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{"index":{"_id":"1"}}
{"name":"Jake","country":"USA","hobby":"Fishing","language":"English","year":2023,"month":4}
{"index":{"_id":"2"}}
{"name":"Hello","country":"USA","hobby":"Painting","language":"English","year":2023,"month":4}
{"index":{"_id":"3"}}
{"name":"John","country":"Canada","hobby":"Reading","language":"French","year":2023,"month":4}
{"index":{"_id":"4"}}
{"name":"Jim","country":"Canada","hobby":"Hiking","language":"English","year":2023,"month":4}
{"index":{"_id":"5"}}
{"name":"Peter","country":"Canada","hobby":"Gaming","language":"English","year":2023,"month":4}
{"index":{"_id":"6"}}
{"name":"Rick","country":"USA","hobby":"Swimming","language":"English","year":2023,"month":4}
{"index":{"_id":"7"}}
{"name":"David","country":"USA","hobby":"Gardening","language":"English","year":2023,"month":4}
{"index":{"_id":"8"}}
{"name":"Jane","country":"Canada","hobby":"Singing","language":"French","year":2023,"month":4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"mappings": {
"properties": {
"name": {
"type": "keyword"
},
"country": {
"type": "text"
},
"hobby": {
"type": "text"
},
"language": {
"type": "keyword"
},
"year": {
"type": "integer"
},
"month": {
"type": "integer"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"mappings": {
"properties": {
"name": {
"type": "keyword"
},
"occupation": {
"type": "text"
},
"country": {
"type": "text"
},
"salary": {
"type": "integer"
},
"year": {
"type": "integer"
},
"month": {
"type": "integer"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"mappings": {
"properties": {
"name": {
"type": "keyword"
},
"age": {
"type": "integer"
},
"state": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"country": {
"type": "text"
},
"year": {
"type": "integer"
},
"month": {
"type": "integer"
}
}
}
}
12 changes: 12 additions & 0 deletions integ-test/src/test/resources/occupation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{"index":{"_id":"1"}}
{"name":"Jake","occupation":"Engineer","country":"England","salary":100000,"year":2023,"month":4}
{"index":{"_id":"2"}}
{"name":"Hello","occupation":"Artist","country":"USA","salary":70000,"year":2023,"month":4}
{"index":{"_id":"3"}}
{"name":"John","occupation":"Doctor","country":"Canada","salary":120000,"year":2023,"month":4}
{"index":{"_id":"4"}}
{"name":"David","occupation":"Doctor","country":"USA","salary":120000,"year":2023,"month":4}
{"index":{"_id":"5"}}
{"name":"David","occupation":"Unemployed","country":"Canada","salary":0,"year":2023,"month":4}
{"index":{"_id":"6"}}
{"name":"Jane","occupation":"Scientist","country":"Canada","salary":90000,"year":2023,"month":4}
16 changes: 16 additions & 0 deletions integ-test/src/test/resources/state_country.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{"index":{"_id":"1"}}
{"name":"Jake","age":70,"state":"California","country":"USA","year":2023,"month":4}
{"index":{"_id":"2"}}
{"name":"Hello","age":30,"state":"New York","country":"USA","year":2023,"month":4}
{"index":{"_id":"3"}}
{"name":"John","age":25,"state":"Ontario","country":"Canada","year":2023,"month":4}
{"index":{"_id":"4"}}
{"name":"Jane","age":20,"state":"Quebec","country":"Canada","year":2023,"month":4}
{"index":{"_id":"5"}}
{"name":"Jim","age":27,"state":"B.C","country":"Canada","year":2023,"month":4}
{"index":{"_id":"6"}}
{"name":"Peter","age":57,"state":"B.C","country":"Canada","year":2023,"month":4}
{"index":{"_id":"7"}}
{"name":"Rick","age":70,"state":"B.C","country":"Canada","year":2023,"month":4}
{"index":{"_id":"8"}}
{"name":"David","age":40,"state":"Washington","country":"USA","year":2023,"month":4}
12 changes: 12 additions & 0 deletions ppl/src/main/antlr/OpenSearchPPLLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ ML: 'ML';
FILLNULL: 'FILLNULL';
TRENDLINE: 'TRENDLINE';

//Native JOIN KEYWORDS
JOIN: 'JOIN';
ON: 'ON';
INNER: 'INNER';
OUTER: 'OUTER';
FULL: 'FULL';
SEMI: 'SEMI';
ANTI: 'ANTI';
CROSS: 'CROSS';
LEFT_HINT: 'HINT.LEFT';
RIGHT_HINT: 'HINT.RIGHT';

// COMMAND ASSIST KEYWORDS
AS: 'AS';
BY: 'BY';
Expand Down
35 changes: 34 additions & 1 deletion ppl/src/main/antlr/OpenSearchPPLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pplCommands
commands
: whereCommand
| fieldsCommand
| joinCommand
| renameCommand
| statsCommand
| dedupCommand
Expand Down Expand Up @@ -204,7 +205,39 @@ fromClause
;

tableSourceClause
: tableSource (COMMA tableSource)*
: tableSource (COMMA tableSource)* (AS alias = qualifiedName)?
;

// join
joinCommand
: (joinType) JOIN sideAlias joinHintList? joinCriteria? right = tableSourceClause
;

joinType
: INNER?
| CROSS
| LEFT OUTER?
| RIGHT OUTER?
| FULL OUTER?
| LEFT? SEMI
| LEFT? ANTI
;

sideAlias
: (LEFT EQUAL leftAlias = qualifiedName)? COMMA? (RIGHT EQUAL rightAlias = qualifiedName)?
;

joinCriteria
: ON logicalExpression
;

joinHintList
: hintPair (COMMA? hintPair)*
;

hintPair
: leftHintKey = LEFT_HINT DOT ID EQUAL leftHintValue = ident #leftHint
| rightHintKey = RIGHT_HINT DOT ID EQUAL rightHintValue = ident #rightHint
;

renameClasue
Expand Down
Loading
Loading