Skip to content

Commit

Permalink
fix: fix regression of new compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashigeru committed Jul 3, 2024
1 parent 4f67bbf commit 3d70411
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 11 deletions.
10 changes: 0 additions & 10 deletions include/mizugaki/analyzer/sql_analyzer_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,13 @@ class sql_analyzer_result {
*/
template<kind_type Kind>
[[nodiscard]] typename unwrap_if_unique_ptr<element_type<Kind>>::reference element() {
if constexpr (Kind == kind_type::diagnostics) { // NOLINT
if (entity_.index() == std::variant_npos) {
return {};
}
}
unwrap_if_unique_ptr<element_type<Kind>> unwrap;
return unwrap(std::get<static_cast<std::size_t>(Kind)>(entity_));
}

/// @copydoc element()
template<kind_type Kind>
[[nodiscard]] typename unwrap_if_unique_ptr<element_type<Kind>>::const_reference element() const {
if constexpr (Kind == kind_type::diagnostics) { // NOLINT
if (entity_.index() == std::variant_npos) {
return {};
}
}
unwrap_if_unique_ptr<element_type<Kind>> unwrap;
return unwrap(std::get<static_cast<std::size_t>(Kind)>(entity_));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ class engine {
auto r = context_.resolve(expression, true);
return static_cast<bool>(r);
}
return false;
return true;
}
};

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ add_test_executable(mizugaki/parser/sql_parser_type_test.cpp)
add_test_executable(mizugaki/parser/sql_parser_misc_test.cpp)

# SQL analyzer
add_test_executable(mizugaki/analyzer/sql_analyzer_test.cpp)
add_analyzer_test_executable(mizugaki/analyzer/details/analyze_literal_test.cpp)
add_analyzer_test_executable(mizugaki/analyzer/details/analyze_name_test.cpp)
add_analyzer_test_executable(mizugaki/analyzer/details/analyze_type_test.cpp)
Expand Down
130 changes: 130 additions & 0 deletions test/mizugaki/analyzer/sql_analyzer_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include <mizugaki/analyzer/sql_analyzer.h>

#include <gtest/gtest.h>

#include <yugawara/schema/catalog.h>

#include <yugawara/schema/declaration.h>
#include <yugawara/schema/configurable_provider.h>

#include <yugawara/storage/table.h>
#include <yugawara/storage/index.h>
#include <yugawara/storage/configurable_provider.h>

#include <yugawara/variable/declaration.h>
#include <yugawara/variable/configurable_provider.h>

#include <yugawara/aggregate/declaration.h>
#include <yugawara/aggregate/configurable_provider.h>

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

#include <mizugaki/ast/query/table_value_constructor.h>

#include <mizugaki/ast/statement/insert_statement.h>

#include "utils.h"

namespace mizugaki::analyzer {

using namespace testing;

class sql_analyzer_test : public ::testing::Test {
protected:
[[nodiscard]] std::string diagnostics(sql_analyzer_result const& result) {
if (result.is_valid()) {
return {};
}
::takatori::util::string_builder buffer;
for (auto&& e : result.element<sql_analyzer_result_kind::diagnostics>()) {
buffer << e << "\n";
}
return buffer.str();
}

std::shared_ptr<::yugawara::storage::configurable_provider> storages_{
std::make_shared<::yugawara::storage::configurable_provider>()
};
std::shared_ptr<::yugawara::aggregate::configurable_provider> set_functions_{
std::make_shared<::yugawara::aggregate::configurable_provider>()
};
std::shared_ptr<::yugawara::schema::configurable_provider> schemas_{
std::make_shared<::yugawara::schema::configurable_provider>()
};
std::shared_ptr<::yugawara::schema::catalog> catalog_{
std::make_shared<::yugawara::schema::catalog>(
"tsurugi",
std::nullopt,
schemas_)
};
std::shared_ptr<::yugawara::schema::declaration> default_schema_ =
std::make_shared<::yugawara::schema::declaration>(
"public",
std::nullopt,
storages_,
std::shared_ptr<::yugawara::variable::provider> {},
std::shared_ptr<::yugawara::function::provider> {},
set_functions_);
std::shared_ptr<::yugawara::schema::search_path> search_path_ {
std::make_shared<::yugawara::schema::search_path>(
::yugawara::schema::search_path::vector_type { default_schema_ })
};
sql_analyzer_options options_ {
catalog_,
search_path_,
default_schema_,
};
placeholder_map placeholders_ {};
::yugawara::variable::configurable_provider host_parameters_ {};
};

TEST_F(sql_analyzer_test, insert_charcter_into_int_column) {
auto table = storages_->add_table(::yugawara::storage::table {
"t",
{
{
"c0",
ttype::int8 {},
},
{
"c1",
ttype::float8 {},
},
},
});
storages_->add_index(::yugawara::storage::index {
table,
".t",
{
{
table->columns()[0],
::yugawara::storage::index::key::direction_type::ascendant,
},
},
{},
{
::yugawara::storage::index_feature::find,
::yugawara::storage::index_feature::scan,
::yugawara::storage::index_feature::primary,
::yugawara::storage::index_feature::unique,
},
});
sql_analyzer analyzer;
auto result = analyzer(
options_,
ast::statement::insert_statement {
id("t"),
{
id("c0")
},
ast::query::table_value_constructor {
ast::scalar::value_constructor {
literal(string("'p'"))
},
},
}
);
ASSERT_TRUE(result) << diagnostics(result);
}

} // namespace mizugaki::analyzer

0 comments on commit 3d70411

Please sign in to comment.