Skip to content

Commit caafbf2

Browse files
committed
Merge remote-tracking branch 'upstream/main' into issues/3418
2 parents 803baf6 + fd41858 commit caafbf2

File tree

13 files changed

+70
-59
lines changed

13 files changed

+70
-59
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
import com.google.common.collect.ImmutableList;
1616
import com.google.common.collect.Iterables;
1717
import java.util.ArrayList;
18+
import java.util.HashSet;
1819
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Objects;
2122
import java.util.Optional;
23+
import java.util.Set;
2224
import java.util.stream.Collectors;
2325
import org.apache.calcite.plan.RelOptTable;
2426
import org.apache.calcite.plan.ViewExpanders;
@@ -145,6 +147,7 @@ public RelNode visitProject(Project node, CalcitePlanContext context) {
145147
visitChildren(node, context);
146148
List<RexNode> projectList;
147149
if (node.getProjectList().stream().anyMatch(e -> e instanceof AllFields)) {
150+
tryToRemoveNestedFields(context);
148151
return context.relBuilder.peek();
149152
} else {
150153
projectList =
@@ -160,6 +163,23 @@ public RelNode visitProject(Project node, CalcitePlanContext context) {
160163
return context.relBuilder.peek();
161164
}
162165

166+
/** See logic in {@link org.opensearch.sql.analysis.symbol.SymbolTable#lookupAllFields} */
167+
private void tryToRemoveNestedFields(CalcitePlanContext context) {
168+
Set<String> allFields = new HashSet<>(context.relBuilder.peek().getRowType().getFieldNames());
169+
List<RexNode> duplicatedNestedFields =
170+
allFields.stream()
171+
.filter(
172+
field -> {
173+
int lastDot = field.lastIndexOf(".");
174+
return -1 != lastDot && allFields.contains(field.substring(0, lastDot));
175+
})
176+
.map(field -> (RexNode) context.relBuilder.field(field))
177+
.toList();
178+
if (!duplicatedNestedFields.isEmpty()) {
179+
context.relBuilder.projectExcept(duplicatedNestedFields);
180+
}
181+
}
182+
163183
@Override
164184
public RelNode visitRename(Rename node, CalcitePlanContext context) {
165185
visitChildren(node, context);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ public RexNode visitQualifiedName(QualifiedName node, CalcitePlanContext context
236236
}
237237
}
238238

239+
// TODO: Need to support nested fields https://github.com/opensearch-project/sql/issues/3459
239240
// 2. resolve QualifiedName in non-join condition
240241
String qualifiedName = node.toString();
241242
List<String> currentFields = context.relBuilder.peek().getRowType().getFieldNames();

core/src/main/java/org/opensearch/sql/calcite/udf/textUDF/LocateFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public Object eval(Object... args) {
1414
return new IllegalArgumentException(
1515
"Invalid number of arguments, locate function expects 2 or 3 arguments");
1616
}
17-
String stringText = (String) args[0];
18-
String targetText = (String) args[1];
17+
String stringText = (String) args[1];
18+
String targetText = (String) args[0];
1919
if (stringText == null || targetText == null) {
2020
return null;
2121
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ static List<RexNode> translateArgument(
249249
context.rexBuilder.makeLiteral(" ")));
250250
RTrimArgs.addAll(argList);
251251
return RTrimArgs;
252+
case "STRCMP":
253+
List<RexNode> StrcmpArgs = List.of(argList.get(1), argList.get(0));
254+
return StrcmpArgs;
252255
case "ATAN":
253256
List<RexNode> AtanArgs = new ArrayList<>(argList);
254257
if (AtanArgs.size() == 1) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public static RelDataType convertExprTypeToRelDataType(ExprType fieldType, boole
105105
return TYPE_FACTORY.createArrayType(
106106
TYPE_FACTORY.createSqlType(SqlTypeName.ANY, nullable), -1);
107107
case STRUCT:
108+
// TODO: should use RelRecordType instead of MapSqlType here
109+
// https://github.com/opensearch-project/sql/issues/3459
108110
final RelDataType relKey = TYPE_FACTORY.createSqlType(SqlTypeName.VARCHAR);
109111
return TYPE_FACTORY.createMapType(
110112
relKey, TYPE_FACTORY.createSqlType(SqlTypeName.BINARY), nullable);

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package org.opensearch.sql.data.model;
77

8+
import static org.opensearch.sql.utils.ExpressionUtils.PATH_SEP;
9+
810
import inet.ipaddr.IPAddress;
911
import java.sql.Date;
1012
import java.sql.Time;
@@ -215,4 +217,18 @@ public static IPAddress getIpValue(ExprValue exprValue) {
215217
public static Boolean getBooleanValue(ExprValue exprValue) {
216218
return exprValue.booleanValue();
217219
}
220+
221+
public static ExprValue resolveRefPaths(ExprValue value, List<String> paths) {
222+
ExprValue wholePathValue = value.keyValue(String.join(PATH_SEP, paths));
223+
// For array types only first index currently supported.
224+
if (value.type().equals(ExprCoreType.ARRAY)) {
225+
wholePathValue = value.collectionValue().getFirst().keyValue(paths.getFirst());
226+
}
227+
228+
if (!wholePathValue.isMissing() || paths.size() == 1) {
229+
return wholePathValue;
230+
} else {
231+
return resolveRefPaths(value.keyValue(paths.getFirst()), paths.subList(1, paths.size()));
232+
}
233+
}
218234
}

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55

66
package org.opensearch.sql.expression;
77

8-
import static org.opensearch.sql.utils.ExpressionUtils.PATH_SEP;
9-
108
import java.util.Arrays;
119
import java.util.List;
1210
import lombok.EqualsAndHashCode;
1311
import lombok.Getter;
1412
import lombok.RequiredArgsConstructor;
1513
import org.opensearch.sql.data.model.ExprTupleValue;
1614
import org.opensearch.sql.data.model.ExprValue;
17-
import org.opensearch.sql.data.type.ExprCoreType;
15+
import org.opensearch.sql.data.model.ExprValueUtils;
1816
import org.opensearch.sql.data.type.ExprType;
1917
import org.opensearch.sql.expression.env.Environment;
2018

@@ -102,20 +100,6 @@ public String toString() {
102100
* </pre>
103101
*/
104102
public ExprValue resolve(ExprTupleValue value) {
105-
return resolve(value, paths);
106-
}
107-
108-
private ExprValue resolve(ExprValue value, List<String> paths) {
109-
ExprValue wholePathValue = value.keyValue(String.join(PATH_SEP, paths));
110-
// For array types only first index currently supported.
111-
if (value.type().equals(ExprCoreType.ARRAY)) {
112-
wholePathValue = value.collectionValue().get(0).keyValue(paths.get(0));
113-
}
114-
115-
if (!wholePathValue.isMissing() || paths.size() == 1) {
116-
return wholePathValue;
117-
} else {
118-
return resolve(value.keyValue(paths.get(0)), paths.subList(1, paths.size()));
119-
}
103+
return ExprValueUtils.resolveRefPaths(value, paths);
120104
}
121105
}

integ-test/src/test/java/org/opensearch/sql/calcite/remote/fallback/CalciteObjectFieldOperateIT.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
package org.opensearch.sql.calcite.remote.fallback;
77

8-
import org.junit.Ignore;
98
import org.opensearch.sql.ppl.ObjectFieldOperateIT;
109

11-
@Ignore("https://github.com/opensearch-project/sql/issues/3452")
1210
public class CalciteObjectFieldOperateIT extends ObjectFieldOperateIT {
1311
@Override
1412
public void init() throws Exception {

integ-test/src/test/java/org/opensearch/sql/calcite/remote/nonfallback/NonFallbackCalciteObjectFieldOperateIT.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
package org.opensearch.sql.calcite.remote.nonfallback;
77

8-
import org.junit.Ignore;
98
import org.opensearch.sql.calcite.remote.fallback.CalciteObjectFieldOperateIT;
109

11-
@Ignore("https://github.com/opensearch-project/sql/issues/3452")
1210
public class NonFallbackCalciteObjectFieldOperateIT extends CalciteObjectFieldOperateIT {
1311
@Override
1412
public void init() throws Exception {

integ-test/src/test/java/org/opensearch/sql/calcite/remote/nonfallback/NonFallbackCalciteTextFunctionIT.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package org.opensearch.sql.calcite.remote.nonfallback;
77

8-
import org.junit.Ignore;
98
import org.opensearch.sql.calcite.remote.fallback.CalciteTextFunctionIT;
109

1110
public class NonFallbackCalciteTextFunctionIT extends CalciteTextFunctionIT {
@@ -14,28 +13,4 @@ public void init() throws Exception {
1413
super.init();
1514
disallowCalciteFallback();
1615
}
17-
18-
@Ignore("https://github.com/opensearch-project/sql/issues/3467")
19-
@Override
20-
public void testAscii() {}
21-
22-
@Ignore("https://github.com/opensearch-project/sql/issues/3467")
23-
@Override
24-
public void testLeft() {}
25-
26-
@Ignore("https://github.com/opensearch-project/sql/issues/3467")
27-
@Override
28-
public void testLocate() {}
29-
30-
@Ignore("https://github.com/opensearch-project/sql/issues/3467")
31-
@Override
32-
public void testReplace() {}
33-
34-
@Ignore("https://github.com/opensearch-project/sql/issues/3467")
35-
@Override
36-
public void testStrcmp() {}
37-
38-
@Ignore("https://github.com/opensearch-project/sql/issues/3467")
39-
@Override
40-
public void testSubstr() {}
4116
}

0 commit comments

Comments
 (0)