File tree 2 files changed +20
-1
lines changed
main/java/org/opensearch/sql/legacy/utils
test/java/org/opensearch/sql/legacy/unittest/utils
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -90,12 +90,26 @@ public static String unquoteSingleField(String text) {
90
90
* @return A string whose each dot-separated field has been unquoted from back-ticks (if any)
91
91
*/
92
92
public static String unquoteFullColumn (String text , String quote ) {
93
+ boolean startsWithPeriod = false ;
94
+ if (text .startsWith (quote + "." )) {
95
+ startsWithPeriod = true ;
96
+ text = quote + text .substring (2 );
97
+ }
93
98
String [] strs = text .split ("\\ ." );
94
99
for (int i = 0 ; i < strs .length ; i ++) {
95
100
String unquotedSubstr = unquoteSingleField (strs [i ], quote );
96
101
strs [i ] = unquotedSubstr ;
97
102
}
98
- return String .join ("." , strs );
103
+ if (startsWithPeriod ) {
104
+ String s = String .join ("." , strs );
105
+ if (s .startsWith (quote )) {
106
+ return new StringBuilder (s ).insert (1 , "." ).toString ();
107
+ } else {
108
+ return "." + s ;
109
+ }
110
+ } else {
111
+ return String .join ("." , strs );
112
+ }
99
113
}
100
114
101
115
public static String unquoteFullColumn (String text ) {
Original file line number Diff line number Diff line change @@ -23,20 +23,25 @@ public class BackticksUnquoterTest {
23
23
public void assertNotQuotedStringShouldKeepTheSame () {
24
24
assertThat (unquoteSingleField ("identifier" ), equalTo ("identifier" ));
25
25
assertThat (unquoteFullColumn ("identifier" ), equalTo ("identifier" ));
26
+ assertThat (unquoteFullColumn (".identifier" ), equalTo (".identifier" ));
26
27
}
27
28
28
29
@ Test
29
30
public void assertStringWithOneBackTickShouldKeepTheSame () {
30
31
assertThat (unquoteSingleField ("`identifier" ), equalTo ("`identifier" ));
31
32
assertThat (unquoteFullColumn ("`identifier" ), equalTo ("`identifier" ));
33
+ assertThat (unquoteFullColumn ("`.identifier" ), equalTo ("`.identifier" ));
32
34
}
33
35
34
36
@ Test
35
37
public void assertBackticksQuotedStringShouldBeUnquoted () {
36
38
assertThat ("identifier" , equalTo (unquoteSingleField ("`identifier`" )));
39
+ assertThat (".identifier" , equalTo (unquoteSingleField ("`.identifier`" )));
37
40
38
41
assertThat (
39
42
"identifier1.identifier2" , equalTo (unquoteFullColumn ("`identifier1`.`identifier2`" )));
40
43
assertThat ("identifier1.identifier2" , equalTo (unquoteFullColumn ("`identifier1`.identifier2" )));
44
+ assertThat (
45
+ ".identifier1.identifier2" , equalTo (unquoteFullColumn ("`.identifier1`.`identifier2`" )));
41
46
}
42
47
}
You can’t perform that action at this time.
0 commit comments