fix: 支持解析多重小括号的sql

This commit is contained in:
taojinlong 2024-08-05 16:33:33 +08:00
parent a298652d65
commit 0180110e93
2 changed files with 36 additions and 22 deletions

View File

@ -101,6 +101,21 @@ public class SqlparserUtils {
private static void handleFromItems(PlainSelect plainSelect, String dsType) throws Exception {
FromItem fromItem = plainSelect.getFromItem();
if (fromItem instanceof ParenthesedSelect) {
handleParenthesedSelect(fromItem, dsType);
plainSelect.setFromItem(fromItem);
} else {
if (fromItem instanceof ParenthesedFromItem) {
fromItem = ((ParenthesedFromItem) fromItem).getFromItem();
while (fromItem instanceof ParenthesedFromItem) {
fromItem = ((ParenthesedFromItem) fromItem).getFromItem();
}
handleParenthesedSelect(fromItem, dsType);
}
plainSelect.setFromItem(fromItem);
}
}
private static void handleParenthesedSelect(FromItem fromItem, String dsType) throws Exception {
if (((ParenthesedSelect) fromItem).getSelect() instanceof SetOperationList) {
StringBuilder result = new StringBuilder();
SetOperationList setOperationList = (SetOperationList) ((ParenthesedSelect) fromItem).getSelect().getSelectBody();
@ -125,8 +140,6 @@ public class SqlparserUtils {
fromItem.setAlias(new Alias(fromItem.getAlias().toString(), false));
}
}
plainSelect.setFromItem(fromItem);
}
}
private static void handleJoins(PlainSelect plainSelect, String dsType) throws Exception {

View File

@ -30,6 +30,7 @@ public class FieldUtils {
case "DATETIMEOFFSET":
case "SMALLDATETIME":
case "DATETIME64":
case "_TIMESTAMPTZ":
return 1;// 时间
case "INT":
case "SMALLINT":