Fix case of functions in select statement in SimpleSQLParser

This commit is contained in:
Travis Burtrum 2017-06-19 23:50:59 -04:00
parent 68c1c0482e
commit f66c8429fb
2 changed files with 3 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import java.util.regex.Pattern;
public class SimpleSQLParser extends AbstractSQLParser {
private static final Pattern aliasPattern = Pattern.compile("^.*\\.");
private static final Pattern parenPattern = Pattern.compile("\\([^)]+\\)");
public SimpleSQLParser() {
super(null, false);
@ -24,7 +25,7 @@ public class SimpleSQLParser extends AbstractSQLParser {
final boolean isSelect = sql.startsWith("SELECT");
String[] columnNames = null;
if (isSelect) {
final String columns = sql.substring(sql.indexOf("SELECT") + 6, sql.indexOf("FROM")).trim();
final String columns = parenPattern.matcher(sql.substring(sql.indexOf("SELECT") + 6, sql.indexOf("FROM"))).replaceAll("").trim();
final String[] splitColumns = columns.split(",");
columnNames = new String[splitColumns.length + 1];
int index = 0;

View File

@ -29,6 +29,7 @@ public class SimpleSQLParserTest {
"select bob, tom from tom"
, "select some_bob bob, some_tom as tom from tom"
, "select tom.bob, some_tom as tom from tom"
, "select tom.bob, COALESCE(some_tom, 'UNKNOWN') as tom from tom"
}) {
final SQLParser ret = getFactory().parse(sql);
assertTrue(ret.isSelect());