From 7aff518767f3180b7e16b897703d3ff9e24ec119 Mon Sep 17 00:00:00 2001 From: Suguru ARAKAWA Date: Mon, 1 Jul 2024 11:50:19 +0900 Subject: [PATCH] fix: select must propagate column names. --- .../analyzer/details/analyze_query_expression.cpp | 11 ++++++++++- .../details/analyze_query_expression_select_test.cpp | 3 +-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/mizugaki/analyzer/details/analyze_query_expression.cpp b/src/mizugaki/analyzer/details/analyze_query_expression.cpp index 524853c..aaf9af1 100644 --- a/src/mizugaki/analyzer/details/analyze_query_expression.cpp +++ b/src/mizugaki/analyzer/details/analyze_query_expression.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -613,13 +614,21 @@ class engine { if (!result) { return {}; } + std::string name; + if (auto n = maybe_name(elem.name())) { + name = std::move(*n); + } else if (name.empty() && elem.value()->node_kind() == ast::scalar::variable_reference::tag) { + auto&& var = unsafe_downcast(*elem.value()); + name = var.name()->last_identifier(); + } + auto column = factory_.stream_variable(maybe_name(elem.name()).value_or("")); column.region() = result.value().region(); target.columns().emplace_back(column, result.release()); info.add({ {}, std::move(column), - maybe_name(elem.name()), + std::move(name), true, }); return { true, result.saw_aggregate() }; diff --git a/test/mizugaki/analyzer/details/analyze_query_expression_select_test.cpp b/test/mizugaki/analyzer/details/analyze_query_expression_select_test.cpp index 7e3bc64..b8ccbc6 100644 --- a/test/mizugaki/analyzer/details/analyze_query_expression_select_test.cpp +++ b/test/mizugaki/analyzer/details/analyze_query_expression_select_test.cpp @@ -64,8 +64,7 @@ TEST_F(analyze_query_expression_select_test, simple) { ASSERT_EQ(relation_columns.size(), 1); { auto&& column = relation_columns[0]; - // FIXME: check spec - // EXPECT_EQ(column.identifier(), "v"); + EXPECT_EQ(column.identifier(), "v"); EXPECT_TRUE(column.exported()); }