mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 04:27:39 +00:00
(fix)(headless) fix sql parsing error containning with as (#1494)
This commit is contained in:
@@ -776,24 +776,25 @@ public class SqlSelectHelper {
|
|||||||
|
|
||||||
private static void getFieldsWithSubQuery(PlainSelect plainSelect, Map<String, Set<String>> fields) {
|
private static void getFieldsWithSubQuery(PlainSelect plainSelect, Map<String, Set<String>> fields) {
|
||||||
if (plainSelect.getFromItem() instanceof Table) {
|
if (plainSelect.getFromItem() instanceof Table) {
|
||||||
boolean isWith = false;
|
List<String> withAlias = new ArrayList<>();
|
||||||
if (!CollectionUtils.isEmpty(plainSelect.getWithItemsList())) {
|
if (!CollectionUtils.isEmpty(plainSelect.getWithItemsList())) {
|
||||||
for (WithItem withItem : plainSelect.getWithItemsList()) {
|
for (WithItem withItem : plainSelect.getWithItemsList()) {
|
||||||
if (Objects.nonNull(withItem.getSelect())) {
|
if (Objects.nonNull(withItem.getSelect())) {
|
||||||
getFieldsWithSubQuery(withItem.getSelect().getPlainSelect(), fields);
|
getFieldsWithSubQuery(withItem.getSelect().getPlainSelect(), fields);
|
||||||
isWith = true;
|
withAlias.add(withItem.getAlias().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isWith) {
|
|
||||||
Table table = (Table) plainSelect.getFromItem();
|
Table table = (Table) plainSelect.getFromItem();
|
||||||
|
String tableName = table.getFullyQualifiedName();
|
||||||
|
if (!withAlias.contains(tableName)) {
|
||||||
if (!fields.containsKey(table.getFullyQualifiedName())) {
|
if (!fields.containsKey(table.getFullyQualifiedName())) {
|
||||||
fields.put(table.getFullyQualifiedName(), new HashSet<>());
|
fields.put(tableName, new HashSet<>());
|
||||||
}
|
}
|
||||||
List<String> sqlFields = getFieldsByPlainSelect(plainSelect).stream().map(f -> f.replaceAll("`", ""))
|
List<String> sqlFields = getFieldsByPlainSelect(plainSelect).stream().map(f -> f.replaceAll("`", ""))
|
||||||
.collect(
|
.collect(
|
||||||
Collectors.toList());
|
Collectors.toList());
|
||||||
fields.get(table.getFullyQualifiedName()).addAll(sqlFields);
|
fields.get(tableName).addAll(sqlFields);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plainSelect.getFromItem() instanceof ParenthesedSelect) {
|
if (plainSelect.getFromItem() instanceof ParenthesedSelect) {
|
||||||
|
|||||||
Reference in New Issue
Block a user