Skip to content

Commit 0607095

Browse files
committed
[flinksql][sql解析失败][19739]
1 parent 78b3d42 commit 0607095

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

core/src/main/java/com/dtstack/flink/sql/util/DtStringUtil.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,40 @@ public static List<String> splitIgnoreQuota(String str, char delimiter){
5959
boolean inSingleQuotes = false;
6060
int bracketLeftNum = 0;
6161
StringBuilder b = new StringBuilder();
62-
for (char c : str.toCharArray()) {
63-
if(c == delimiter){
62+
char[] chars = str.toCharArray();
63+
int idx = 0;
64+
for (char c : chars) {
65+
char flag = 0;
66+
if (idx > 0) {
67+
flag = chars[idx - 1];
68+
}
69+
if (c == delimiter) {
6470
if (inQuotes) {
6571
b.append(c);
66-
} else if(inSingleQuotes){
72+
} else if (inSingleQuotes) {
6773
b.append(c);
68-
} else if(bracketLeftNum > 0){
74+
} else if (bracketLeftNum > 0) {
6975
b.append(c);
70-
}else {
76+
} else {
7177
tokensList.add(b.toString());
7278
b = new StringBuilder();
7379
}
74-
}else if(c == '\"'){
80+
} else if (c == '\"' && '\\' != flag && !inSingleQuotes) {
7581
inQuotes = !inQuotes;
7682
b.append(c);
77-
}else if(c == '\''){
83+
} else if (c == '\'' && '\\' != flag && !inQuotes) {
7884
inSingleQuotes = !inSingleQuotes;
7985
b.append(c);
80-
}else if(c == '('){
86+
} else if (c == '(' && !inSingleQuotes && !inQuotes) {
8187
bracketLeftNum++;
8288
b.append(c);
83-
}else if(c == ')'){
89+
} else if (c == ')' && !inSingleQuotes && !inQuotes) {
8490
bracketLeftNum--;
8591
b.append(c);
86-
}else{
92+
} else {
8793
b.append(c);
8894
}
95+
idx++;
8996
}
9097

9198
tokensList.add(b.toString());

0 commit comments

Comments
 (0)