mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 05:43:51 +00:00
(improvement)(Headless) corrector supports subselect sql (#1006)
* [improvement] corrector support subselect sql --------- Co-authored-by: zuopengge
This commit is contained in:
@@ -206,6 +206,12 @@ public class SqlReplaceHelper {
|
||||
replaceAsName(fieldNameMap, selectItem);
|
||||
}
|
||||
|
||||
if (plainSelect.getFromItem() instanceof ParenthesedSelect) {
|
||||
ParenthesedSelect parenthesedSelect = (ParenthesedSelect) plainSelect.getFromItem();
|
||||
PlainSelect subPlainSelect = parenthesedSelect.getPlainSelect();
|
||||
replaceFieldsInPlainOneSelect(fieldNameMap, exactReplace, subPlainSelect);
|
||||
}
|
||||
|
||||
//3. replace oder by fields
|
||||
List<OrderByElement> orderByElements = plainSelect.getOrderByElements();
|
||||
if (!CollectionUtils.isEmpty(orderByElements)) {
|
||||
|
||||
@@ -122,19 +122,28 @@ public class SqlSelectHelper {
|
||||
List<PlainSelect> plainSelectList = new ArrayList<>();
|
||||
if (selectStatement instanceof PlainSelect) {
|
||||
PlainSelect plainSelect = (PlainSelect) selectStatement;
|
||||
plainSelectList.add(plainSelect);
|
||||
getSubPlainSelect(plainSelect, plainSelectList);
|
||||
} else if (selectStatement instanceof SetOperationList) {
|
||||
SetOperationList setOperationList = (SetOperationList) selectStatement;
|
||||
if (!CollectionUtils.isEmpty(setOperationList.getSelects())) {
|
||||
setOperationList.getSelects().forEach(subSelectBody -> {
|
||||
PlainSelect subPlainSelect = (PlainSelect) subSelectBody;
|
||||
plainSelectList.add(subPlainSelect);
|
||||
getSubPlainSelect(subPlainSelect, plainSelectList);
|
||||
});
|
||||
}
|
||||
}
|
||||
return plainSelectList;
|
||||
}
|
||||
|
||||
public static void getSubPlainSelect(PlainSelect plainSelect, List<PlainSelect> plainSelectList) {
|
||||
plainSelectList.add(plainSelect);
|
||||
if (plainSelect.getFromItem() instanceof ParenthesedSelect) {
|
||||
ParenthesedSelect parenthesedSelect = (ParenthesedSelect) plainSelect.getFromItem();
|
||||
PlainSelect subPlainSelect = parenthesedSelect.getPlainSelect();
|
||||
getSubPlainSelect(subPlainSelect, plainSelectList);
|
||||
}
|
||||
}
|
||||
|
||||
public static Select getSelect(String sql) {
|
||||
Statement statement = null;
|
||||
try {
|
||||
@@ -275,6 +284,14 @@ public class SqlSelectHelper {
|
||||
if (Objects.nonNull(where)) {
|
||||
where.accept(new FieldAndValueAcquireVisitor(result));
|
||||
}
|
||||
if (plainSelect.getFromItem() instanceof ParenthesedSelect) {
|
||||
ParenthesedSelect parenthesedSelect = (ParenthesedSelect) plainSelect.getFromItem();
|
||||
PlainSelect subPlainSelect = parenthesedSelect.getPlainSelect();
|
||||
Expression subWhere = subPlainSelect.getWhere();
|
||||
if (Objects.nonNull(subWhere)) {
|
||||
subWhere.accept(new FieldAndValueAcquireVisitor(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<>(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user