From 484861571f50913420bb428b430d6504c523d69f Mon Sep 17 00:00:00 2001 From: lexluo09 <39718951+lexluo09@users.noreply.github.com> Date: Thu, 10 Oct 2024 21:53:29 +0800 Subject: [PATCH] [improvement][headless] Fix the issue with the query when using the with clause along with a join (#1779) --- .../supersonic/common/jsqlparser/SqlReplaceHelper.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/com/tencent/supersonic/common/jsqlparser/SqlReplaceHelper.java b/common/src/main/java/com/tencent/supersonic/common/jsqlparser/SqlReplaceHelper.java index f1c3a54f6..a150a73bc 100644 --- a/common/src/main/java/com/tencent/supersonic/common/jsqlparser/SqlReplaceHelper.java +++ b/common/src/main/java/com/tencent/supersonic/common/jsqlparser/SqlReplaceHelper.java @@ -439,16 +439,18 @@ public class SqlReplaceHelper { private static void replaceJoins(PlainSelect plainSelect, String tableName, List withNameList) { List joins = plainSelect.getJoins(); + TableNameReplaceVisitor fromItemVisitor = + new TableNameReplaceVisitor(tableName, new HashSet<>(withNameList)); if (!CollectionUtils.isEmpty(joins)) { for (Join join : joins) { if (join.getRightItem() instanceof ParenthesedFromItem) { List subPlainSelects = SqlSelectHelper.getPlainSelects( Collections.singletonList((PlainSelect) join.getRightItem())); - subPlainSelects.forEach(subPlainSelect -> subPlainSelect.getFromItem().accept( - new TableNameReplaceVisitor(tableName, new HashSet<>(withNameList)))); + subPlainSelects.forEach(subPlainSelect -> { + subPlainSelect.getFromItem().accept(fromItemVisitor); + }); } else if (join.getRightItem() instanceof Table) { - Table table = (Table) join.getRightItem(); - table.setName(tableName); + join.getRightItem().accept(fromItemVisitor); } } }