Skip to content

Commit b698850

Browse files
authored
Added pre tag to keep formatting for incorrectly formatted java docs.
1 parent b8aea35 commit b698850

File tree

15 files changed

+351
-134
lines changed

15 files changed

+351
-134
lines changed

core/src/main/java/org/opensearch/sql/executor/pagination/CanPaginateVisitor.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,21 @@
4141
import org.opensearch.sql.expression.function.BuiltinFunctionName;
4242

4343
/**
44-
* Use this unresolved plan visitor to check if a plan can be serialized by PaginatedPlanCache. If
45-
*
46-
* <pre>plan.accept(new CanPaginateVisitor(...))</pre>
47-
*
48-
* returns <em>true</em>, then PaginatedPlanCache.convertToCursor will succeed. Otherwise, it will
49-
* fail. The purpose of this visitor is to activate legacy engine fallback mechanism. Currently, V2
50-
* engine does not support queries with: - aggregation (GROUP BY clause or aggregation functions
51-
* like min/max) - in memory aggregation (window function) - LIMIT/OFFSET clause(s) - without FROM
52-
* clause - JOIN - a subquery V2 also requires that the table being queried should be an OpenSearch
53-
* index. See PaginatedPlanCache.canConvertToCursor for usage.
44+
* <pre>
45+
* Use this unresolved plan visitor to check if a plan can be serialized by PaginatedPlanCache.
46+
* If <pre>plan.accept(new CanPaginateVisitor(...))</pre> returns <em>true</em>,
47+
* then PaginatedPlanCache.convertToCursor will succeed. Otherwise, it will fail.
48+
* The purpose of this visitor is to activate legacy engine fallback mechanism.
49+
* Currently, V2 engine does not support queries with:
50+
* - aggregation (GROUP BY clause or aggregation functions like min/max)
51+
* - in memory aggregation (window function)
52+
* - LIMIT/OFFSET clause(s)
53+
* - without FROM clause
54+
* - JOIN
55+
* - a subquery
56+
* V2 also requires that the table being queried should be an OpenSearch index.
57+
* See PaginatedPlanCache.canConvertToCursor for usage.
58+
* </pre>
5459
*/
5560
public class CanPaginateVisitor extends AbstractNodeVisitor<Boolean, Object> {
5661

core/src/main/java/org/opensearch/sql/expression/ExpressionNodeVisitor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ public T visitNamedAggregator(NamedAggregator node, C context) {
8282
}
8383

8484
/**
85-
* Call visitFunction() by default rather than visitChildren(). This makes CASE/WHEN able to be
86-
* handled: 1) by visitFunction() if not overwritten: ex. FilterQueryBuilder 2) by
87-
* visitCase/When() otherwise if any special logic: ex. ExprReferenceOptimizer
85+
* <pre>
86+
* Call visitFunction() by default rather than visitChildren().
87+
* This makes CASE/WHEN able to be handled:
88+
* 1) by visitFunction() if not overwritten: ex. FilterQueryBuilder
89+
* 2) by visitCase/When() otherwise if any special logic: ex. ExprReferenceOptimizer
90+
* </pre>
8891
*/
8992
public T visitCase(CaseClause node, C context) {
9093
return visitFunction(node, context);

core/src/main/java/org/opensearch/sql/expression/ReferenceExpression.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,39 @@ public String toString() {
6161
}
6262

6363
/**
64-
* Resolve the ExprValue from {@link ExprTupleValue} using paths. Considering the following sample
65-
* data. { "name": "bob smith" "project.year": 1990, "project": { "year": "2020" } "address": {
66-
* "state": "WA", "city": "seattle", "project.year": 1990 } "address.local": { "state": "WA", } }
67-
* The paths could be 1. top level, e.g. "name", which will be resolved as "bob smith" 2. multiple
68-
* paths, e.g. "name.address.state", which will be resolved as "WA" 3. special case, the "." is
69-
* the path separator, but it is possible that the path include ".", for handling this use case,
70-
* we define the resolve rule as bellow, e.g. "project.year" is resolved as 1990 instead of 2020.
71-
* Note. This logic only applied top level none object field. e.g. "address.local.state" been
72-
* resolved to Missing. but "address.project.year" could been resolved as 1990.
64+
* <pre>
65+
* Resolve the ExprValue from {@link ExprTupleValue} using paths.
66+
* Considering the following sample data.
67+
* {
68+
* "name": "bob smith"
69+
* "project.year": 1990,
70+
* "project": {
71+
* "year": "2020"
72+
* }
73+
* "address": {
74+
* "state": "WA",
75+
* "city": "seattle",
76+
* "project.year": 1990
77+
* }
78+
* "address.local": {
79+
* "state": "WA",
80+
* }
81+
* }
82+
* The paths could be
83+
* 1. top level, e.g. "name", which will be resolved as "bob smith"
84+
* 2. multiple paths, e.g. "name.address.state", which will be resolved as "WA"
85+
* 3. special case, the "." is the path separator, but it is possible that the path include
86+
* ".", for handling this use case, we define the resolve rule as bellow, e.g. "project.year" is
87+
* resolved as 1990 instead of 2020. Note. This logic only applied top level none object field.
88+
* e.g. "address.local.state" been resolved to Missing. but "address.project.year" could been
89+
* resolved as 1990.
7390
*
7491
* <p>Resolve Rule 1. Resolve the full name by combine the paths("x"."y"."z") as whole ("x.y.z").
7592
* 2. Resolve the path recursively through ExprValue.
7693
*
7794
* @param value {@link ExprTupleValue}.
7895
* @return {@link ExprTupleValue}.
96+
* <pre>
7997
*/
8098
public ExprValue resolve(ExprTupleValue value) {
8199
return resolve(value, paths);

core/src/main/java/org/opensearch/sql/expression/aggregation/AggregatorFunction.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@
3434
import org.opensearch.sql.expression.function.FunctionSignature;
3535

3636
/**
37-
* The definition of aggregator function avg, Accepts two numbers and produces a number. sum,
38-
* Accepts two numbers and produces a number. max, Accepts two numbers and produces a number. min,
39-
* Accepts two numbers and produces a number. count, Accepts two numbers and produces a number.
37+
* <pre>
38+
* The definition of aggregator function
39+
* avg, Accepts two numbers and produces a number.
40+
* sum, Accepts two numbers and produces a number.
41+
* max, Accepts two numbers and produces a number.
42+
* min, Accepts two numbers and produces a number.
43+
* count, Accepts two numbers and produces a number.
44+
* </pre>
4045
*/
4146
@UtilityClass
4247
public class AggregatorFunction {

core/src/main/java/org/opensearch/sql/expression/datetime/DateTimeFunction.java

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,15 @@ private DefaultFunctionResolver subdate() {
847847
}
848848

849849
/**
850-
* Subtracts expr2 from expr1 and returns the result. (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME
851-
* (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME TODO: MySQL has these
852-
* signatures too (STRING, STRING/TIME) -> STRING // second arg - string with time only (x,
853-
* STRING) -> NULL // second arg - string with timestamp (x, STRING/DATE) -> x // second arg -
854-
* string with date only
850+
* <pre>
851+
* Subtracts expr2 from expr1 and returns the result.
852+
* (TIME, TIME/DATE/DATETIME/TIMESTAMP) -> TIME
853+
* (DATE/DATETIME/TIMESTAMP, TIME/DATE/DATETIME/TIMESTAMP) -> DATETIME
854+
* TODO: MySQL has these signatures too
855+
* (STRING, STRING/TIME) -> STRING // second arg - string with time only
856+
* (x, STRING) -> NULL // second arg - string with timestamp
857+
* (x, STRING/DATE) -> x // second arg - string with date only
858+
* </pre>
855859
*/
856860
private DefaultFunctionResolver subtime() {
857861
return define(
@@ -954,11 +958,17 @@ private DefaultFunctionResolver time() {
954958
}
955959

956960
/**
957-
* Returns different between two times as a time. (TIME, TIME) -> TIME MySQL has these signatures
958-
* too (DATE, DATE) -> TIME // result is > 24 hours (DATETIME, DATETIME) -> TIME // result is > 24
959-
* hours (TIMESTAMP, TIMESTAMP) -> TIME // result is > 24 hours (x, x) -> NULL // when args have
960-
* different types (STRING, STRING) -> TIME // argument strings contain same types only (STRING,
961-
* STRING) -> NULL // argument strings are different types
961+
* <pre>
962+
* Returns different between two times as a time.
963+
* (TIME, TIME) -> TIME
964+
* MySQL has these signatures too
965+
* (DATE, DATE) -> TIME // result is > 24 hours
966+
* (DATETIME, DATETIME) -> TIME // result is > 24 hours
967+
* (TIMESTAMP, TIMESTAMP) -> TIME // result is > 24 hours
968+
* (x, x) -> NULL // when args have different types
969+
* (STRING, STRING) -> TIME // argument strings contain same types only
970+
* (STRING, STRING) -> NULL // argument strings are different types
971+
* </pre>
962972
*/
963973
private DefaultFunctionResolver timediff() {
964974
return define(
@@ -979,11 +989,14 @@ private DefaultFunctionResolver time_to_sec() {
979989
}
980990

981991
/**
982-
* Extracts the timestamp of a date and time value. Input strings may contain a timestamp only in
983-
* format 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]' STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP
984-
* STRING/DATE/TIME/DATETIME/TIMESTAMP, STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP All types
985-
* are converted to TIMESTAMP actually before the function call - it is responsibility of the
986-
* automatic cast mechanism defined in `ExprCoreType` and performed by `TypeCastOperator`.
992+
* <pre>
993+
* Extracts the timestamp of a date and time value.
994+
* Input strings may contain a timestamp only in format 'yyyy-MM-dd HH:mm:ss[.SSSSSSSSS]'
995+
* STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP
996+
* STRING/DATE/TIME/DATETIME/TIMESTAMP, STRING/DATE/TIME/DATETIME/TIMESTAMP -> TIMESTAMP
997+
* All types are converted to TIMESTAMP actually before the function call - it is responsibility
998+
* of the automatic cast mechanism defined in `ExprCoreType` and performed by `TypeCastOperator`.
999+
* </pre>
9871000
*/
9881001
private DefaultFunctionResolver timestamp() {
9891002
return define(
@@ -1221,9 +1234,15 @@ private DefaultFunctionResolver yearweek() {
12211234
}
12221235

12231236
/**
1224-
* Formats date according to format specifier. First argument is date, second is format. Detailed
1225-
* supported signatures: (STRING, STRING) -> STRING (DATE, STRING) -> STRING (DATETIME, STRING) ->
1226-
* STRING (TIME, STRING) -> STRING (TIMESTAMP, STRING) -> STRING
1237+
* <pre>
1238+
* Formats date according to format specifier. First argument is date, second is format.
1239+
* Detailed supported signatures:
1240+
* (STRING, STRING) -> STRING
1241+
* (DATE, STRING) -> STRING
1242+
* (DATETIME, STRING) -> STRING
1243+
* (TIME, STRING) -> STRING
1244+
* (TIMESTAMP, STRING) -> STRING
1245+
* </pre>
12271246
*/
12281247
private DefaultFunctionResolver date_format() {
12291248
return define(
@@ -1302,9 +1321,15 @@ private ExprValue exprDateApplyInterval(
13021321
}
13031322

13041323
/**
1305-
* Formats date according to format specifier. First argument is time, second is format. Detailed
1306-
* supported signatures: (STRING, STRING) -> STRING (DATE, STRING) -> STRING (DATETIME, STRING) ->
1307-
* STRING (TIME, STRING) -> STRING (TIMESTAMP, STRING) -> STRING
1324+
* <pre>
1325+
* Formats date according to format specifier. First argument is time, second is format.
1326+
* Detailed supported signatures:
1327+
* (STRING, STRING) -> STRING
1328+
* (DATE, STRING) -> STRING
1329+
* (DATETIME, STRING) -> STRING
1330+
* (TIME, STRING) -> STRING
1331+
* (TIMESTAMP, STRING) -> STRING
1332+
* </pre>
13081333
*/
13091334
private DefaultFunctionResolver time_format() {
13101335
return define(
@@ -1683,14 +1708,18 @@ private ExprValue exprLastDayToday(Clock clock) {
16831708
}
16841709

16851710
/**
1711+
* <pre>
16861712
* Following MySQL, function receives arguments of type double and rounds them before use.
1687-
* Furthermore: - zero year interpreted as 2000 - negative year is not accepted - @dayOfYear
1688-
* should be greater than 1 - if @dayOfYear is greater than 365/366, calculation goes to the next
1689-
* year(s)
1713+
* Furthermore:
1714+
* - zero year interpreted as 2000
1715+
* - negative year is not accepted
1716+
* - @dayOfYear should be greater than 1
1717+
* - if @dayOfYear is greater than 365/366, calculation goes to the next year(s)
16901718
*
16911719
* @param yearExpr year
16921720
* @param dayOfYearExp day of the @year, starting from 1
16931721
* @return Date - ExprDateValue object with LocalDate
1722+
* </pre>
16941723
*/
16951724
private ExprValue exprMakeDate(ExprValue yearExpr, ExprValue dayOfYearExp) {
16961725
var year = Math.round(yearExpr.doubleValue());

core/src/main/java/org/opensearch/sql/expression/function/FunctionSignature.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ public class FunctionSignature {
2727
private final List<ExprType> paramTypeList;
2828

2929
/**
30+
* <pre>
3031
* calculate the function signature match degree.
3132
*
32-
* @return EXACTLY_MATCH: exactly match NOT_MATCH: not match By widening rule, the small number
33-
* means better match
33+
* @return EXACTLY_MATCH: exactly match
34+
* NOT_MATCH: not match
35+
* By widening rule, the small number means better match
36+
* </pre>
3437
*/
3538
public int match(FunctionSignature functionSignature) {
3639
List<ExprType> functionTypeList = functionSignature.getParamTypeList();

core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/ArithmeticFunction.java

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@
2929
import org.opensearch.sql.expression.function.FunctionName;
3030

3131
/**
32-
* The definition of arithmetic function add, Accepts two numbers and produces a number. subtract,
33-
* Accepts two numbers and produces a number. multiply, Accepts two numbers and produces a number.
34-
* divide, Accepts two numbers and produces a number. module, Accepts two numbers and produces a
35-
* number.
32+
* <pre>
33+
* The definition of arithmetic function
34+
* add, Accepts two numbers and produces a number.
35+
* subtract, Accepts two numbers and produces a number.
36+
* multiply, Accepts two numbers and produces a number.
37+
* divide, Accepts two numbers and produces a number.
38+
* module, Accepts two numbers and produces a number.
39+
* </pre>
3640
*/
3741
@UtilityClass
3842
public class ArithmeticFunction {
@@ -108,9 +112,11 @@ private static DefaultFunctionResolver addFunction() {
108112
}
109113

110114
/**
111-
* Definition of divide(x, y) function. Returns the number x divided by number y The supported
112-
* signature of divide function is (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y:
113-
* BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE) -> wider type between types of x and y
115+
* Definition of divide(x, y) function.
116+
* Returns the number x divided by number y
117+
* The supported signature of divide function is
118+
* (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE)
119+
* -> wider type between types of x and y
114120
*/
115121
private static DefaultFunctionResolver divideBase(FunctionName functionName) {
116122
return define(
@@ -256,9 +262,15 @@ private static DefaultFunctionResolver modulusFunction() {
256262
}
257263

258264
/**
259-
* Definition of multiply(x, y) function. Returns the number x multiplied by number y The
260-
* supported signature of multiply function is (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y:
261-
* BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE) -> wider type between types of x and y
265+
* <pre>
266+
* Definition of multiply(x, y) function.
267+
* Returns the number x multiplied by number y
268+
* The supported signature of multiply function is
269+
* (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE)
270+
* -> wider type between types of x and y
271+
* (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE)
272+
* -> wider type between types of x and y
273+
* </pre>
262274
*/
263275
private static DefaultFunctionResolver multiplyBase(FunctionName functionName) {
264276
return define(
@@ -308,9 +320,13 @@ private static DefaultFunctionResolver multiplyFunction() {
308320
}
309321

310322
/**
311-
* Definition of subtract(x, y) function. Returns the number x minus number y The supported
312-
* signature of subtract function is (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y:
313-
* BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE) -> wider type between types of x and y
323+
* <pre>
324+
* Definition of subtract(x, y) function.
325+
* Returns the number x minus number y
326+
* The supported signature of subtract function is
327+
* (x: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE, y: BYTE/SHORT/INTEGER/LONG/FLOAT/DOUBLE)
328+
* -> wider type between types of x and y
329+
* </pre>
314330
*/
315331
private static DefaultFunctionResolver subtractBase(FunctionName functionName) {
316332
return define(

core/src/main/java/org/opensearch/sql/expression/operator/arthmetic/MathematicalFunction.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,13 @@ private static DefaultFunctionResolver ceiling() {
151151
}
152152

153153
/**
154-
* Definition of conv(x, a, b) function. Convert number x from base a to base b The supported
155-
* signature of floor function is (STRING, INTEGER, INTEGER) -> STRING (INTEGER, INTEGER, INTEGER)
156-
* -> STRING
154+
* <pre>
155+
* Definition of conv(x, a, b) function.
156+
* Convert number x from base a to base b
157+
* The supported signature of floor function is
158+
* (STRING, INTEGER, INTEGER) -> STRING
159+
* (INTEGER, INTEGER, INTEGER) -> STRING
160+
* </pre>
157161
*/
158162
private static DefaultFunctionResolver conv() {
159163
return define(
@@ -396,9 +400,15 @@ private static DefaultFunctionResolver pi() {
396400
}
397401

398402
/**
399-
* Definition of pow(x, y)/power(x, y) function. Calculate the value of x raised to the power of y
400-
* The supported signature of pow/power function is (INTEGER, INTEGER) -> DOUBLE (LONG, LONG) ->
401-
* DOUBLE (FLOAT, FLOAT) -> DOUBLE (DOUBLE, DOUBLE) -> DOUBLE
403+
* <pre>
404+
* Definition of pow(x, y)/power(x, y) function.
405+
* Calculate the value of x raised to the power of y
406+
* The supported signature of pow/power function is
407+
* (INTEGER, INTEGER) -> DOUBLE
408+
* (LONG, LONG) -> DOUBLE
409+
* (FLOAT, FLOAT) -> DOUBLE
410+
* (DOUBLE, DOUBLE) -> DOUBLE
411+
* </pre>
402412
*/
403413
private static DefaultFunctionResolver pow() {
404414
return define(BuiltinFunctionName.POW.getName(), powerFunctionImpl());
@@ -478,10 +488,15 @@ private static DefaultFunctionResolver rint() {
478488
}
479489

480490
/**
481-
* Definition of round(x)/round(x, d) function. Rounds the argument x to d decimal places, d
482-
* defaults to 0 if not specified. The supported signature of round function is (x: INTEGER [, y:
483-
* INTEGER]) -> INTEGER (x: LONG [, y: INTEGER]) -> LONG (x: FLOAT [, y: INTEGER]) -> FLOAT (x:
484-
* DOUBLE [, y: INTEGER]) -> DOUBLE
491+
* <pre>
492+
* Definition of round(x)/round(x, d) function.
493+
* Rounds the argument x to d decimal places, d defaults to 0 if not specified.
494+
* The supported signature of round function is
495+
* (x: INTEGER [, y: INTEGER]) -> INTEGER
496+
* (x: LONG [, y: INTEGER]) -> LONG
497+
* (x: FLOAT [, y: INTEGER]) -> FLOAT
498+
* (x: DOUBLE [, y: INTEGER]) -> DOUBLE
499+
* </pre>
485500
*/
486501
private static DefaultFunctionResolver round() {
487502
return define(
@@ -613,9 +628,15 @@ private static DefaultFunctionResolver cbrt() {
613628
}
614629

615630
/**
616-
* Definition of truncate(x, d) function. Returns the number x, truncated to d decimal places The
617-
* supported signature of round function is (x: INTEGER, y: INTEGER) -> LONG (x: LONG, y: INTEGER)
618-
* -> LONG (x: FLOAT, y: INTEGER) -> DOUBLE (x: DOUBLE, y: INTEGER) -> DOUBLE
631+
* <pre>
632+
* Definition of truncate(x, d) function.
633+
* Returns the number x, truncated to d decimal places
634+
* The supported signature of round function is
635+
* (x: INTEGER, y: INTEGER) -> LONG
636+
* (x: LONG, y: INTEGER) -> LONG
637+
* (x: FLOAT, y: INTEGER) -> DOUBLE
638+
* (x: DOUBLE, y: INTEGER) -> DOUBLE
639+
* </pre>
619640
*/
620641
private static DefaultFunctionResolver truncate() {
621642
return define(

0 commit comments

Comments
 (0)