File tree Expand file tree Collapse file tree 3 files changed +24
-32
lines changed
core/src/main/java/org/opensearch/sql
expression/function/CollectionUDF Expand file tree Collapse file tree 3 files changed +24
-32
lines changed Original file line number Diff line number Diff line change 66package org .opensearch .sql .calcite ;
77
88import com .google .common .collect .ImmutableList ;
9+ import java .util .ArrayList ;
910import java .util .Arrays ;
1011import java .util .List ;
1112import java .util .Locale ;
@@ -179,7 +180,7 @@ public RexNode createStringArrayLiteral(List<String> values) {
179180 RelDataType stringType = getTypeFactory ().createSqlType (SqlTypeName .VARCHAR );
180181 RelDataType arrayType = getTypeFactory ().createArrayType (stringType , -1 );
181182
182- List <RexNode > elements = new java . util . ArrayList <>();
183+ List <RexNode > elements = new ArrayList <>();
183184 for (String value : values ) {
184185 elements .add (makeLiteral (value ));
185186 }
Original file line number Diff line number Diff line change 88import java .util .ArrayList ;
99import java .util .List ;
1010
11- /** Core logic for internal `append` function to collect elements from list of args. */
11+ /**
12+ * Core logic for `mvappend` and internal `append` function to collect elements from list of args.
13+ */
1214public class AppendCore {
1315
1416 /**
1517 * Collect non-null elements from `args`. If an item is a list, it will collect non-null elements
1618 * of the list. See {@ref AppendFunctionImplTest} for detailed behavior.
1719 */
1820 public static Object collectElements (Object ... args ) {
21+ List <Object > elements = collectElementsToList (args );
22+
23+ if (elements .isEmpty ()) {
24+ return null ;
25+ } else if (elements .size () == 1 ) {
26+ // return the element in case of single element
27+ return elements .get (0 );
28+ } else {
29+ return elements ;
30+ }
31+ }
32+
33+ /**
34+ * Collect non-null elements from `args`. If an item is a list, it will collect non-null elements.
35+ */
36+ public static List <Object > collectElementsToList (Object ... args ) {
1937 List <Object > elements = new ArrayList <>();
2038
2139 for (Object arg : args ) {
@@ -28,14 +46,7 @@ public static Object collectElements(Object... args) {
2846 }
2947 }
3048
31- if (elements .isEmpty ()) {
32- return null ;
33- } else if (elements .size () == 1 ) {
34- // return the element in case of single element
35- return elements .get (0 );
36- } else {
37- return elements ;
38- }
49+ return elements ;
3950 }
4051
4152 private static void addListElements (List <?> list , List <Object > elements ) {
Original file line number Diff line number Diff line change 77
88import static org .apache .calcite .sql .type .SqlTypeUtil .createArrayType ;
99
10- import java .util .ArrayList ;
1110import java .util .List ;
1211import org .apache .calcite .adapter .enumerable .NotNullImplementor ;
1312import org .apache .calcite .adapter .enumerable .NullPolicy ;
@@ -106,26 +105,7 @@ public static Object mvappend(Object... args) {
106105 * of the list. See {@ref MVAppendFunctionImplTest} for detailed behavior.
107106 */
108107 public static List <Object > collectElements (Object ... args ) {
109- List <Object > elements = new ArrayList <>();
110-
111- for (Object arg : args ) {
112- if (arg == null ) {
113- continue ;
114- } else if (arg instanceof List ) {
115- addListElements ((List <?>) arg , elements );
116- } else {
117- elements .add (arg );
118- }
119- }
120-
121- return elements .size () == 0 ? null : elements ;
122- }
123-
124- private static void addListElements (List <?> list , List <Object > elements ) {
125- for (Object item : list ) {
126- if (item != null ) {
127- elements .add (item );
128- }
129- }
108+ List <Object > elements = AppendCore .collectElementsToList (args );
109+ return elements .isEmpty () ? null : elements ;
130110 }
131111}
You can’t perform that action at this time.
0 commit comments