Fix case of functions in select statement in SimpleSQLParser

pull/2/head
Travis Burtrum 6 years ago
parent 68c1c0482e
commit f66c8429fb

@ -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;

@ -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());

Loading…
Cancel
Save