improved odps sql parser. bug fixed for issue #1375

This commit is contained in:
wenshao
2016-08-21 13:58:38 +08:00
parent 0565f9c1a9
commit 103ee3e1a3
8 changed files with 381 additions and 28 deletions
@@ -352,4 +352,8 @@ public class OdpsLexer extends Lexer {
protected final void scanString() {
scanString2();
}
protected final void scanAlias() {
scanAlias2();
}
}
@@ -881,10 +881,31 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
if (text == null) {
print0(ucase ? "NULL" : "null");
} else {
print('\'');
String text2 = text.replaceAll("\\'", "\\\\'");
print0(text2);
print('\'');
StringBuilder buf = new StringBuilder(text.length() + 2);
buf.append('\'');
for (int i = 0; i < text.length(); ++i) {
char ch = text.charAt(i);
switch (ch) {
case '\\':
buf.append("\\\\");
break;
case '\'':
buf.append("\\'");
break;
case '\0':
buf.append("\\0");
break;
case '\n':
buf.append("\\n");
break;
default:
buf.append(ch);
break;
}
}
buf.append('\'');
print0(buf.toString());
}
return false;