Skip to content

Commit 6750e15

Browse files
authored
SQL: Ignore H2 comparative tests for uppercasing/lowercasing string functions (#32604)
Skip the comparative tests using lowercasing/uppercasing against H2 (which considers the Locale). ES-SQL is, so far, ignoring the Locale. Still, the same queries are executed against ES-SQL alone and results asserted to be correct.
1 parent e162127 commit 6750e15

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/string/StringFunctionProcessorTests.java

+26
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.xpack.sql.expression.function.scalar.string.StringProcessor.StringOperation;
1212

1313
import java.io.IOException;
14+
import java.util.Locale;
1415

1516
public class StringFunctionProcessorTests extends AbstractWireSerializingTestCase<StringProcessor> {
1617
public static StringProcessor randomStringFunctionProcessor() {
@@ -73,6 +74,19 @@ public void testLCase() {
7374

7475
stringCharInputValidation(proc);
7576
}
77+
78+
public void testLCaseWithTRLocale() {
79+
Locale.setDefault(Locale.forLanguageTag("tr"));
80+
StringProcessor proc = new StringProcessor(StringOperation.LCASE);
81+
82+
// ES-SQL is not locale sensitive (so far). The obvious test for this is the Turkish language, uppercase letter I conversion
83+
// in non-Turkish locale the lowercasing would create i and an additional dot, while in Turkish Locale it would only create "i"
84+
// unicode 0069 = i
85+
assertEquals("\u0069\u0307", proc.process("\u0130"));
86+
// unicode 0049 = I (regular capital letter i)
87+
// in Turkish locale this would be lowercased to a "i" without dot (unicode 0131)
88+
assertEquals("\u0069", proc.process("\u0049"));
89+
}
7690

7791
public void testUCase() {
7892
StringProcessor proc = new StringProcessor(StringOperation.UCASE);
@@ -81,9 +95,21 @@ public void testUCase() {
8195
assertEquals("SOMELOWERCASE", proc.process("SomeLoweRCasE"));
8296
assertEquals("FULLUPPERCASE", proc.process("FULLUPPERCASE"));
8397
assertEquals("A", proc.process('a'));
98+
99+
// special uppercasing for small letter sharp "s" resulting "SS"
100+
assertEquals("\u0053\u0053", proc.process("\u00df"));
84101

85102
stringCharInputValidation(proc);
86103
}
104+
105+
public void testUCaseWithTRLocale() {
106+
Locale.setDefault(Locale.forLanguageTag("tr"));
107+
StringProcessor proc = new StringProcessor(StringOperation.UCASE);
108+
109+
// ES-SQL is not Locale sensitive (so far).
110+
// in Turkish locale, small letter "i" is uppercased to "I" with a dot above (unicode 130), otherwise in "i" (unicode 49)
111+
assertEquals("\u0049", proc.process("\u0069"));
112+
}
87113

88114
public void testLength() {
89115
StringProcessor proc = new StringProcessor(StringOperation.LENGTH);

x-pack/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/SqlSpecTestCase.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
99

10+
import org.junit.Assume;
1011
import org.junit.ClassRule;
1112

1213
import java.sql.Connection;
1314
import java.sql.ResultSet;
1415
import java.util.ArrayList;
1516
import java.util.List;
17+
import java.util.Locale;
1618

1719
/**
1820
* Tests comparing sql queries executed against our jdbc client
@@ -25,7 +27,7 @@ public abstract class SqlSpecTestCase extends SpecBaseIntegrationTestCase {
2527
public static LocalH2 H2 = new LocalH2((c) -> c.createStatement().execute("RUNSCRIPT FROM 'classpath:/setup_test_emp.sql'"));
2628

2729
@ParametersFactory(argumentFormatting = PARAM_FORMATTING)
28-
public static List<Object[]> readScriptSpec() throws Exception {
30+
public static List<Object[]> readScriptSpec() throws Exception {
2931
Parser parser = specParser();
3032
List<Object[]> tests = new ArrayList<>();
3133
tests.addAll(readScriptSpec("/select.sql-spec", parser));
@@ -35,6 +37,7 @@ public static List<Object[]> readScriptSpec() throws Exception {
3537
tests.addAll(readScriptSpec("/agg.sql-spec", parser));
3638
tests.addAll(readScriptSpec("/arithmetic.sql-spec", parser));
3739
tests.addAll(readScriptSpec("/string-functions.sql-spec", parser));
40+
tests.addAll(readScriptSpec("/case-functions.sql-spec", parser));
3841
return tests;
3942
}
4043

@@ -56,6 +59,12 @@ public SqlSpecTestCase(String fileName, String groupName, String testName, Integ
5659

5760
@Override
5861
protected final void doTest() throws Throwable {
62+
boolean goodLocale = !(Locale.getDefault().equals(new Locale.Builder().setLanguageTag("tr").build())
63+
|| Locale.getDefault().equals(new Locale.Builder().setLanguageTag("tr-TR").build()));
64+
if (fileName.startsWith("case-functions")) {
65+
Assume.assumeTrue(goodLocale);
66+
}
67+
5968
try (Connection h2 = H2.get();
6069
Connection es = esJdbc()) {
6170

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Next 4 SELECTs in this file are related to https://github.com/elastic/elasticsearch/issues/32589
2+
// H2 is Locale sensitive, while ES-SQL is not (so far)
3+
selectInsertWithLcaseAndLengthWithOrderBy
4+
SELECT "first_name" origFN, "last_name" origLN, INSERT(UCASE("first_name"),LENGTH("first_name")+1,123,LCASE("last_name")) modified FROM "test_emp" WHERE ASCII("first_name")=65 ORDER BY "first_name" ASC, "last_name" ASC LIMIT 10;
5+
6+
upperCasingTheSecondLetterFromTheRightFromFirstName
7+
SELECT CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) f FROM "test_emp" ORDER BY "first_name" LIMIT 10;
8+
9+
upperCasingTheSecondLetterFromTheRightFromFirstNameWithOrderByAndGroupBy
10+
SELECT CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) f, COUNT(*) c FROM "test_emp" GROUP BY CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) ORDER BY CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) LIMIT 10;
11+
12+
upperCasingTheSecondLetterFromTheRightFromFirstNameWithWhere
13+
SELECT CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) f, COUNT(*) c FROM "test_emp" WHERE CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1))='AlejandRo' GROUP BY CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) ORDER BY CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) LIMIT 10;

x-pack/qa/sql/src/main/resources/string-functions.sql-spec

+2-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ SELECT LCASE(first_name) lc, CHAR(ASCII(LCASE(first_name))) chr FROM "test_emp"
2222
ltrimFilter
2323
SELECT LTRIM(first_name) lt FROM "test_emp" WHERE LTRIM(first_name) = 'Bob';
2424

25-
//Unsupported yet
25+
// Unsupported yet
26+
// Functions combined with 'LIKE' should perform the match inside a Painless script, whereas at the moment it's handled as a regular `match` query in ES.
2627
//ltrimFilterWithLike
2728
//SELECT LTRIM("first_name") lt FROM "test_emp" WHERE LTRIM("first_name") LIKE '%a%';
2829

@@ -93,10 +94,6 @@ SELECT "first_name" orig, REPEAT("first_name",2) reps FROM "test_emp" WHERE ASCI
9394
selectInsertWithLcase
9495
SELECT "first_name" orig, INSERT("first_name",2,1000,LCASE("first_name")) modified FROM "test_emp" WHERE ASCII("first_name")=65 ORDER BY "first_name" ASC LIMIT 10;
9596

96-
// AWAITS FIX for https://github.com/elastic/elasticsearch/issues/32589
97-
// selectInsertWithLcaseAndLengthWithOrderBy
98-
//SELECT "first_name" origFN, "last_name" origLN, INSERT(UCASE("first_name"),LENGTH("first_name")+1,123,LCASE("last_name")) modified FROM "test_emp" WHERE ASCII("first_name")=65 ORDER BY "first_name" ASC, "last_name" ASC LIMIT 10;
99-
10097
selectInsertWithUcaseWithGroupByAndOrderBy
10198
SELECT INSERT(UCASE("first_name"),2,123000,INSERT(UCASE("last_name"),2,500,' ')) modified, COUNT(*) count FROM "test_emp" WHERE ASCII("first_name")=65 GROUP BY INSERT(UCASE("first_name"),2,123000,INSERT(UCASE("last_name"),2,500,' ')) ORDER BY INSERT(UCASE("first_name"),2,123000,INSERT(UCASE("last_name"),2,500,' ')) ASC LIMIT 10;
10299

@@ -141,14 +138,3 @@ SELECT RIGHT("first_name",2) f FROM "test_emp" ORDER BY "first_name" LIMIT 10;
141138

142139
selectRightWithGroupByAndOrderBy
143140
SELECT RIGHT("first_name",2) f, COUNT(*) count FROM "test_emp" GROUP BY RIGHT("first_name",2) ORDER BY RIGHT("first_name",2) LIMIT 10;
144-
145-
// AWAITS FIX for https://github.com/elastic/elasticsearch/issues/32589
146-
// upperCasingTheSecondLetterFromTheRightFromFirstName
147-
// SELECT CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) f FROM "test_emp" ORDER BY "first_name" LIMIT 10;
148-
149-
// AWAITS FIX for https://github.com/elastic/elasticsearch/issues/32589
150-
// upperCasingTheSecondLetterFromTheRightFromFirstNameWithOrderByAndGroupBy
151-
// SELECT CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) f, COUNT(*) c FROM "test_emp" GROUP BY CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) ORDER BY CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) LIMIT 10;
152-
153-
upperCasingTheSecondLetterFromTheRightFromFirstNameWithWhere
154-
SELECT CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) f, COUNT(*) c FROM "test_emp" WHERE CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1))='AlejandRo' GROUP BY CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) ORDER BY CONCAT(CONCAT(SUBSTRING("first_name",1,LENGTH("first_name")-2),UCASE(LEFT(RIGHT("first_name",2),1))),RIGHT("first_name",1)) LIMIT 10;

0 commit comments

Comments
 (0)