From 27a70de1be3711670c1528c6c0821910c0a36b89 Mon Sep 17 00:00:00 2001 From: jipeli <54889677+jipeli@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:34:08 +0800 Subject: [PATCH] (fix)(headless) fix sql parsing error containning with as (#1494) --- .../common/jsqlparser/SqlSelectHelper.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/tencent/supersonic/common/jsqlparser/SqlSelectHelper.java b/common/src/main/java/com/tencent/supersonic/common/jsqlparser/SqlSelectHelper.java index 6acd6ac7d..23bc459be 100644 --- a/common/src/main/java/com/tencent/supersonic/common/jsqlparser/SqlSelectHelper.java +++ b/common/src/main/java/com/tencent/supersonic/common/jsqlparser/SqlSelectHelper.java @@ -776,24 +776,25 @@ public class SqlSelectHelper { private static void getFieldsWithSubQuery(PlainSelect plainSelect, Map> fields) { if (plainSelect.getFromItem() instanceof Table) { - boolean isWith = false; + List withAlias = new ArrayList<>(); if (!CollectionUtils.isEmpty(plainSelect.getWithItemsList())) { for (WithItem withItem : plainSelect.getWithItemsList()) { if (Objects.nonNull(withItem.getSelect())) { 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())) { - fields.put(table.getFullyQualifiedName(), new HashSet<>()); + fields.put(tableName, new HashSet<>()); } List sqlFields = getFieldsByPlainSelect(plainSelect).stream().map(f -> f.replaceAll("`", "")) .collect( Collectors.toList()); - fields.get(table.getFullyQualifiedName()).addAll(sqlFields); + fields.get(tableName).addAll(sqlFields); } } if (plainSelect.getFromItem() instanceof ParenthesedSelect) {