Skip to content

Commit

Permalink
fix: select must propagate column names.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashigeru committed Jul 1, 2024
1 parent e34107a commit 7aff518
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/mizugaki/analyzer/details/analyze_query_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <yugawara/binding/factory.h>

#include <mizugaki/ast/scalar/value_constructor.h>
#include <mizugaki/ast/scalar/variable_reference.h>

#include <mizugaki/ast/query/dispatch.h>
#include <mizugaki/ast/table/dispatch.h>
Expand Down Expand Up @@ -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<ast::scalar::variable_reference>(*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() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 7aff518

Please sign in to comment.