From b8851d5103e0b56ac2781faa62680d3ae3188a1e Mon Sep 17 00:00:00 2001 From: Smith Cruise Date: Tue, 29 Oct 2024 16:26:14 +0800 Subject: [PATCH] [BugFix] Fix insert into blackhole() analyze error (#52422) Signed-off-by: Smith Cruise (cherry picked from commit d1a64078a57c0d1c3954184ee72d405fcb47897b) --- .../src/main/java/com/starrocks/sql/ast/InsertStmt.java | 7 ++++++- .../java/com/starrocks/sql/plan/DataCachePlanTest.java | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/ast/InsertStmt.java b/fe/fe-core/src/main/java/com/starrocks/sql/ast/InsertStmt.java index 8388264764634..8468779a81e08 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/ast/InsertStmt.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/ast/InsertStmt.java @@ -314,7 +314,12 @@ private List collectSelectedFieldsFromQueryStatement() { } public Table makeBlackHoleTable() { - return new BlackHoleTable(collectSelectedFieldsFromQueryStatement()); + List columns = collectSelectedFieldsFromQueryStatement(); + // rename each column's name, assign unique name + for (int i = 0; i < columns.size(); i++) { + columns.get(i).setName(columns.get(i).getName() + "_blackhole_" + i); + } + return new BlackHoleTable(columns); } public Table makeTableFunctionTable(SessionVariable sessionVariable) { diff --git a/fe/fe-core/src/test/java/com/starrocks/sql/plan/DataCachePlanTest.java b/fe/fe-core/src/test/java/com/starrocks/sql/plan/DataCachePlanTest.java index a1f6a676b67af..70aeace789d3c 100644 --- a/fe/fe-core/src/test/java/com/starrocks/sql/plan/DataCachePlanTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/sql/plan/DataCachePlanTest.java @@ -175,5 +175,9 @@ public void testBlackHoleTableSink() throws Exception { String sql = "insert into blackhole() select * from hive0.datacache_db.multi_partition_table " + "where l_shipdate>='1998-01-03'"; assertPlanContains(sql, "BLACKHOLE TABLE SINK"); + + sql = "insert into blackhole() select * from hive0.datacache_db.multi_partition_table join " + + "hive0.datacache_db.multi_partition_table as t"; + assertPlanContains(sql, "BLACKHOLE TABLE SINK"); } }