Skip to content

Commit f3368fb

Browse files
committed
try shadow
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent 2f74cb1 commit f3368fb

16 files changed

Lines changed: 147 additions & 86 deletions

File tree

core/src/main/java/org/opensearch/sql/analysis/Analyzer.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import static org.opensearch.sql.ast.tree.Sort.NullOrder.NULL_LAST;
1111
import static org.opensearch.sql.ast.tree.Sort.SortOrder.ASC;
1212
import static org.opensearch.sql.ast.tree.Sort.SortOrder.DESC;
13-
import static org.opensearch.sql.data.type.ExprCoreType.DATE;
1413
import static org.opensearch.sql.data.type.ExprCoreType.STRUCT;
15-
import static org.opensearch.sql.data.type.ExprCoreType.TIME;
16-
import static org.opensearch.sql.data.type.ExprCoreType.TIMESTAMP;
1714
import static org.opensearch.sql.utils.MLCommonsConstants.RCF_ANOMALOUS;
1815
import static org.opensearch.sql.utils.MLCommonsConstants.RCF_ANOMALY_GRADE;
1916
import static org.opensearch.sql.utils.MLCommonsConstants.RCF_SCORE;
@@ -623,16 +620,17 @@ public LogicalPlan visitTrendline(Trendline node, AnalysisContext context) {
623620
} else {
624621
ExprType type = resolvedField.type();
625622
if (type == ExprCoreType.DATE
626-
|| type == ExprCoreType.TIME
627-
|| type == ExprCoreType.TIMESTAMP) {
623+
|| type == ExprCoreType.TIME
624+
|| type == ExprCoreType.TIMESTAMP) {
628625
averageType = (ExprCoreType) type;
629626
} else {
630627
throw new SemanticCheckException(
631-
String.format(
632-
"Invalid field used for trendline computation %s. Source field %s had type %s but must be a numerical or datetime field.",
633-
computation.getAlias(),
634-
computation.getDataField().getChild().get(0),
635-
type.typeName()));
628+
String.format(
629+
"Invalid field used for trendline computation %s. Source field %s had type %s"
630+
+ " but must be a numerical or datetime field.",
631+
computation.getAlias(),
632+
computation.getDataField().getChild().get(0),
633+
type.typeName()));
636634
}
637635
}
638636
currEnv.define(new Symbol(Namespace.FIELD_NAME, computation.getAlias()), averageType);

core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ private boolean containsSubqueryExpression(Node expr) {
129129
if (expr instanceof SubqueryExpression) {
130130
return true;
131131
}
132-
if (expr instanceof Let l) {
132+
if (expr instanceof Let) {
133+
Let l = (Let) expr;
133134
return containsSubqueryExpression(l.getExpression());
134135
}
135136
for (Node child : expr.getChild()) {
@@ -166,10 +167,12 @@ public RelNode visitRename(Rename node, CalcitePlanContext context) {
166167
List<String> originalNames = context.relBuilder.peek().getRowType().getFieldNames();
167168
List<String> newNames = new ArrayList<>(originalNames);
168169
for (org.opensearch.sql.ast.expression.Map renameMap : node.getRenameList()) {
169-
if (renameMap.getTarget() instanceof Field t) {
170+
if (renameMap.getTarget() instanceof Field) {
171+
Field t = (Field) renameMap.getTarget();
170172
String newName = t.getField().toString();
171173
RexNode check = rexVisitor.analyze(renameMap.getOrigin(), context);
172-
if (check instanceof RexInputRef ref) {
174+
if (check instanceof RexInputRef) {
175+
RexInputRef ref = (RexInputRef) check;
173176
newNames.set(ref.getIndex(), newName);
174177
} else {
175178
throw new SemanticCheckException(

core/src/main/java/org/opensearch/sql/calcite/utils/BuiltinFunctionUtils.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ static SqlOperator translate(String op) {
6464
return SqlLibraryOperators.CONCAT_WS;
6565
case "LIKE":
6666
return SqlLibraryOperators.ILIKE;
67-
case "LTRIM", "RTRIM", "TRIM":
67+
case "LTRIM":
68+
case "RTRIM":
69+
case "TRIM":
6870
return SqlStdOperatorTable.TRIM;
6971
case "LENGTH":
7072
return SqlStdOperatorTable.CHAR_LENGTH;
@@ -86,9 +88,11 @@ static SqlOperator translate(String op) {
8688
case "SQRT":
8789
return TransferUserDefinedFunction(
8890
SqrtFunction.class, "SQRT", ReturnTypes.DOUBLE_FORCE_NULLABLE);
89-
case "ATAN", "ATAN2":
91+
case "ATAN":
92+
case "ATAN2":
9093
return SqlStdOperatorTable.ATAN2;
91-
case "POW", "POWER":
94+
case "POW":
95+
case "POWER":
9296
return SqlStdOperatorTable.POWER;
9397
// Built-in Date Functions
9498
case "CURRENT_TIMESTAMP":

core/src/main/java/org/opensearch/sql/calcite/utils/OpenSearchTypeFactory.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import org.apache.calcite.rel.type.RelDataType;
3131
import org.apache.calcite.rel.type.RelDataTypeSystem;
3232
import org.apache.calcite.sql.type.SqlTypeName;
33-
import org.opensearch.sql.data.model.ExprValue;
34-
import org.opensearch.sql.data.model.ExprValueUtils;
3533
import org.opensearch.sql.data.type.ExprCoreType;
3634
import org.opensearch.sql.data.type.ExprType;
3735
import org.opensearch.sql.executor.OpenSearchTypeSystem;

core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.time.LocalDateTime;
1515
import java.time.LocalTime;
1616
import java.time.ZoneId;
17-
import java.time.ZoneOffset;
1817
import java.time.ZonedDateTime;
1918
import java.time.format.DateTimeFormatter;
2019
import java.time.format.DateTimeParseException;

core/src/main/java/org/opensearch/sql/data/model/ExprValueUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.time.LocalDate;
1414
import java.time.LocalDateTime;
1515
import java.time.LocalTime;
16-
import java.time.ZoneOffset;
1716
import java.time.temporal.TemporalAmount;
1817
import java.util.ArrayList;
1918
import java.util.LinkedHashMap;

core/src/test/java/org/opensearch/sql/data/model/ExprValueUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public class ExprValueUtilsTest {
116116
ExprCoreType.FLOAT,
117117
ExprCoreType.DOUBLE);
118118
private static final List<ExprCoreType> nonNumberTypes =
119-
Arrays.asList(IP, STRING, BOOLEAN, ARRAY, STRUCT);
119+
Arrays.asList(IP, STRING, BOOLEAN, ARRAY, STRUCT);
120120
private static List<ExprCoreType> dateAndTimeTypes =
121121
Arrays.asList(DATE, TIME, DATETIME, TIMESTAMP, INTERVAL);
122122
private static List<ExprCoreType> allTypes =

core/src/test/java/org/opensearch/sql/expression/function/WideningTypeRuleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class WideningTypeRuleTest {
5959
.put(STRING, TIMESTAMP, 1)
6060
.put(STRING, DATE, 1)
6161
.put(STRING, TIME, 1)
62-
.put(STRING, IP, 1)
62+
.put(STRING, IP, 1)
6363
.put(STRING, DATETIME, 1)
6464
.put(DATE, DATETIME, 1)
6565
.put(TIME, DATETIME, 1)

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLInSubqueryIT.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public void testWhereInSubquery() {
6666
JSONObject result =
6767
executeQuery(
6868
String.format(
69-
"source = %s | where id in [source = %s | fields uid ] | sort - salary | fields id, name, salary",
69+
"source = %s | where id in [source = %s | fields uid ] | sort - salary | fields"
70+
+ " id, name, salary",
7071
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
7172
verifySchema(
7273
result, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));
@@ -84,7 +85,8 @@ public void testFilterInSubquery() {
8485
JSONObject result =
8586
executeQuery(
8687
String.format(
87-
"source = %s id in [source = %s | fields uid]| sort - salary| fields id, name, salary",
88+
"source = %s id in [source = %s | fields uid]| sort - salary| fields id, name,"
89+
+ " salary",
8890
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
8991
verifySchema(
9092
result, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));
@@ -102,12 +104,14 @@ public void testInSubqueryWithParentheses() {
102104
JSONObject result1 =
103105
executeQuery(
104106
String.format(
105-
"source = %s| where (id) in [source = %s | fields uid]| sort - salary| fields id, name",
107+
"source = %s| where (id) in [source = %s | fields uid]| sort - salary| fields id,"
108+
+ " name",
106109
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
107110
JSONObject result2 =
108111
executeQuery(
109112
String.format(
110-
"source = %s (id) in [ source = %s | fields uid] | sort - salary | fields id, name, salary",
113+
"source = %s (id) in [ source = %s | fields uid] | sort - salary | fields id,"
114+
+ " name, salary",
111115
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
112116
verifySchema(
113117
result1, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));
@@ -134,7 +138,8 @@ public void testTwoExpressionsInSubquery() {
134138
JSONObject result =
135139
executeQuery(
136140
String.format(
137-
" source = %s | where (id, name) in [ source = %s | fields uid, name] | sort - salary | fields id, name, salary ",
141+
" source = %s | where (id, name) in [ source = %s | fields uid, name] | sort -"
142+
+ " salary | fields id, name, salary ",
138143
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
139144
verifySchema(
140145
result, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));
@@ -151,7 +156,8 @@ public void testWhereNotInSubquery() {
151156
JSONObject result =
152157
executeQuery(
153158
String.format(
154-
"source = %s | where id not in [ source = %s | fields uid] | sort - salary | fields id, name, salary ",
159+
"source = %s | where id not in [ source = %s | fields uid] | sort - salary |"
160+
+ " fields id, name, salary ",
155161
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
156162
verifySchema(
157163
result, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));
@@ -163,7 +169,8 @@ public void testFilterNotInSubquery() {
163169
JSONObject result =
164170
executeQuery(
165171
String.format(
166-
"source = %s id not in [ source = %s | fields uid] | sort - salary | fields id, name, salary ",
172+
"source = %s id not in [ source = %s | fields uid] | sort - salary | fields id,"
173+
+ " name, salary ",
167174
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
168175
verifySchema(
169176
result, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));
@@ -175,7 +182,8 @@ public void testTwoExpressionsNotInSubquery() {
175182
JSONObject result =
176183
executeQuery(
177184
String.format(
178-
"source = %s | where (id, name) not in [ source = %s | fields uid, name] | sort - salary | fields id, name, salary ",
185+
"source = %s | where (id, name) not in [ source = %s | fields uid, name] | sort -"
186+
+ " salary | fields id, name, salary ",
179187
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
180188
verifySchema(
181189
result, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));
@@ -188,7 +196,8 @@ public void testEmptyInSubquery() {
188196
JSONObject result =
189197
executeQuery(
190198
String.format(
191-
"source = %s id not in [source = %s | where uid = 0000 | fields uid]| sort - salary| fields id, name, salary",
199+
"source = %s id not in [source = %s | where uid = 0000 | fields uid]| sort -"
200+
+ " salary| fields id, name, salary",
192201
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
193202
verifySchema(
194203
result, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));
@@ -208,7 +217,9 @@ public void testNestedInSubquery() {
208217
JSONObject result =
209218
executeQuery(
210219
String.format(
211-
"source = %s| where id in [source = %s| where occupation in [source = %s| where occupation != 'Engineer'| fields occupation ]| fields uid]| sort - salary| fields id, name, salary",
220+
"source = %s| where id in [source = %s| where occupation in [source = %s| where"
221+
+ " occupation != 'Engineer'| fields occupation ]| fields uid]| sort - salary|"
222+
+ " fields id, name, salary",
212223
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION, TEST_INDEX_OCCUPATION));
213224
verifySchema(
214225
result, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));
@@ -224,7 +235,9 @@ public void testInSubqueryAsJoinFilter() {
224235
JSONObject result =
225236
executeQuery(
226237
String.format(
227-
"source = %s| inner join left=a, right=b ON a.id = b.uid AND b.occupation in [source = %s | where occupation != 'Engineer' | fields occupation] %s | fields a.id, a.name, a.salary, b.occupation",
238+
"source = %s| inner join left=a, right=b ON a.id = b.uid AND b.occupation in"
239+
+ " [source = %s | where occupation != 'Engineer' | fields occupation] %s |"
240+
+ " fields a.id, a.name, a.salary, b.occupation",
228241
TEST_INDEX_WORKER, TEST_INDEX_OCCUPATION, TEST_INDEX_WORK_INFORMATION));
229242
verifySchema(
230243
result, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));
@@ -243,7 +256,8 @@ public void failWhenNumOfColumnsNotMatchOutputOfSubquery() {
243256
() ->
244257
executeQuery(
245258
String.format(
246-
"source = %s| where id in [source = %s | fields uid, department ]| sort - salary | fields id, name, salary",
259+
"source = %s| where id in [source = %s | fields uid, department ]| sort -"
260+
+ " salary | fields id, name, salary",
247261
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION)));
248262
verifyErrorMessageContains(
249263
e1,
@@ -256,7 +270,8 @@ public void failWhenNumOfColumnsNotMatchOutputOfSubquery() {
256270
() ->
257271
executeQuery(
258272
String.format(
259-
"source = %s| where (id, name, salary) in [source = %s | fields uid, department] | sort - salary| fields id, name, salary",
273+
"source = %s| where (id, name, salary) in [source = %s | fields uid,"
274+
+ " department] | sort - salary| fields id, name, salary",
260275
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION)));
261276
verifyErrorMessageContains(
262277
e2,
@@ -269,7 +284,8 @@ public void testInSubqueryWithTableAlias() {
269284
JSONObject result =
270285
executeQuery(
271286
String.format(
272-
"source = %s as o | where id in [ source = %s as i | where i.department = 'DATA' | fields uid] | sort - o.salary | fields o.id, o.name, o.salary ",
287+
"source = %s as o | where id in [ source = %s as i | where i.department = 'DATA' |"
288+
+ " fields uid] | sort - o.salary | fields o.id, o.name, o.salary ",
273289
TEST_INDEX_WORKER, TEST_INDEX_WORK_INFORMATION));
274290
verifySchema(
275291
result, schema("id", "integer"), schema("name", "string"), schema("salary", "integer"));

integ-test/src/test/java/org/opensearch/sql/calcite/standalone/CalcitePPLJoinIT.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,19 @@ public void testMultipleJoins() {
356356
JSONObject actual =
357357
executeQuery(
358358
String.format(
359-
" source = %s | where country = 'Canada' OR country = 'England' | inner join left=a, right=b ON a.name = b.name AND a.year = 2023 AND a.month = 4 AND b.year = 2023 AND b.month = 4 %s | eval a_name = a.name | eval a_country = a.country| eval b_country = b.country | fields a_name, age, state, a_country, occupation, b_country, salary | left join left=a, right=bON a.a_name = b.name%s | eval aa_country = a.a_country| eval ab_country = a.b_country | eval bb_country = b.country| fields a_name, age, state, aa_country, occupation, ab_country, salary, bb_country, hobby, language | cross join left=a, right=b %s| eval new_country = a.aa_country| eval new_salary = b.salary | stats avg(new_salary) as avg_salary by span(age, 5) as age_span, state| left semi join left=a, right=bON a.state = b.state %s | eval new_avg_salary = floor(avg_salary)| fields state, age_span, new_avg_salary",
359+
" source = %s | where country = 'Canada' OR country = 'England' | inner join"
360+
+ " left=a, right=b ON a.name = b.name AND a.year = 2023 AND a.month = 4 AND"
361+
+ " b.year = 2023 AND b.month = 4 %s | eval a_name = a.name | eval a_country ="
362+
+ " a.country| eval b_country = b.country | fields a_name, age, state,"
363+
+ " a_country, occupation, b_country, salary | left join left=a, right=bON"
364+
+ " a.a_name = b.name%s | eval aa_country = a.a_country| eval ab_country ="
365+
+ " a.b_country | eval bb_country = b.country| fields a_name, age, state,"
366+
+ " aa_country, occupation, ab_country, salary, bb_country, hobby, language |"
367+
+ " cross join left=a, right=b %s| eval new_country = a.aa_country| eval"
368+
+ " new_salary = b.salary | stats avg(new_salary) as avg_salary by span(age, 5)"
369+
+ " as age_span, state| left semi join left=a, right=bON a.state = b.state %s |"
370+
+ " eval new_avg_salary = floor(avg_salary)| fields state, age_span,"
371+
+ " new_avg_salary",
360372
TEST_INDEX_STATE_COUNTRY,
361373
TEST_INDEX_OCCUPATION,
362374
TEST_INDEX_HOBBIES,

0 commit comments

Comments
 (0)