Skip to content

[Followup] fix text function IT for locate and strcmp #3482

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

Merged
merged 1 commit into from
Mar 27, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public Object eval(Object... args) {
return new IllegalArgumentException(
"Invalid number of arguments, locate function expects 2 or 3 arguments");
}
String stringText = (String) args[0];
String targetText = (String) args[1];
String stringText = (String) args[1];
String targetText = (String) args[0];
if (stringText == null || targetText == null) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ static List<RexNode> translateArgument(
context.rexBuilder.makeLiteral(" ")));
RTrimArgs.addAll(argList);
return RTrimArgs;
case "STRCMP":
List<RexNode> StrcmpArgs = List.of(argList.get(1), argList.get(0));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wonder why some function's arguments are swapped in this method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the order in compareTo between V2 and Calcite is different:
V2:

Integer.compare(str1.stringValue().compareTo(str2.stringValue()), 0)))

Calcite

return (int) Math.signum(s1.compareTo(s0));

return StrcmpArgs;
case "ATAN":
List<RexNode> AtanArgs = new ArrayList<>(argList);
if (AtanArgs.size() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

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

import org.junit.Ignore;
import org.opensearch.sql.calcite.remote.fallback.CalciteTextFunctionIT;

public class NonFallbackCalciteTextFunctionIT extends CalciteTextFunctionIT {
Expand All @@ -14,28 +13,4 @@ public void init() throws Exception {
super.init();
disallowCalciteFallback();
}

@Ignore("https://github.com/opensearch-project/sql/issues/3467")
@Override
public void testAscii() {}

@Ignore("https://github.com/opensearch-project/sql/issues/3467")
@Override
public void testLeft() {}

@Ignore("https://github.com/opensearch-project/sql/issues/3467")
@Override
public void testLocate() {}

@Ignore("https://github.com/opensearch-project/sql/issues/3467")
@Override
public void testReplace() {}

@Ignore("https://github.com/opensearch-project/sql/issues/3467")
@Override
public void testStrcmp() {}

@Ignore("https://github.com/opensearch-project/sql/issues/3467")
@Override
public void testSubstr() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void testLocate() {
JSONObject actual =
executeQuery(
String.format(
"source=%s | where locate(name, 'Ja')=1 | fields name, age",
"source=%s | where locate('Ja', name)=1 | fields name, age",
TEST_INDEX_STATE_COUNTRY_WITH_NULL));

verifySchema(actual, schema("name", "string"), schema("age", "integer"));
Expand Down
Loading