From 3d704111ef53f52011d6b970d9bc4db9f17d53fb Mon Sep 17 00:00:00 2001 From: Suguru ARAKAWA Date: Wed, 3 Jul 2024 14:57:22 +0900 Subject: [PATCH] fix: fix regression of new compiler. --- .../mizugaki/analyzer/sql_analyzer_result.h | 10 -- .../details/analyze_scalar_expression.cpp | 2 +- test/CMakeLists.txt | 1 + test/mizugaki/analyzer/sql_analyzer_test.cpp | 130 ++++++++++++++++++ 4 files changed, 132 insertions(+), 11 deletions(-) create mode 100644 test/mizugaki/analyzer/sql_analyzer_test.cpp diff --git a/include/mizugaki/analyzer/sql_analyzer_result.h b/include/mizugaki/analyzer/sql_analyzer_result.h index b9807c3..53be349 100644 --- a/include/mizugaki/analyzer/sql_analyzer_result.h +++ b/include/mizugaki/analyzer/sql_analyzer_result.h @@ -188,11 +188,6 @@ class sql_analyzer_result { */ template [[nodiscard]] typename unwrap_if_unique_ptr>::reference element() { - if constexpr (Kind == kind_type::diagnostics) { // NOLINT - if (entity_.index() == std::variant_npos) { - return {}; - } - } unwrap_if_unique_ptr> unwrap; return unwrap(std::get(Kind)>(entity_)); } @@ -200,11 +195,6 @@ class sql_analyzer_result { /// @copydoc element() template [[nodiscard]] typename unwrap_if_unique_ptr>::const_reference element() const { - if constexpr (Kind == kind_type::diagnostics) { // NOLINT - if (entity_.index() == std::variant_npos) { - return {}; - } - } unwrap_if_unique_ptr> unwrap; return unwrap(std::get(Kind)>(entity_)); } diff --git a/src/mizugaki/analyzer/details/analyze_scalar_expression.cpp b/src/mizugaki/analyzer/details/analyze_scalar_expression.cpp index 9802976..9cfe46c 100644 --- a/src/mizugaki/analyzer/details/analyze_scalar_expression.cpp +++ b/src/mizugaki/analyzer/details/analyze_scalar_expression.cpp @@ -557,7 +557,7 @@ class engine { auto r = context_.resolve(expression, true); return static_cast(r); } - return false; + return true; } }; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 845007d..f2056e8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/mizugaki/analyzer/sql_analyzer_test.cpp b/test/mizugaki/analyzer/sql_analyzer_test.cpp new file mode 100644 index 0000000..73f99dc --- /dev/null +++ b/test/mizugaki/analyzer/sql_analyzer_test.cpp @@ -0,0 +1,130 @@ +#include + +#include + +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include + +#include + +#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()) { + 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 \ No newline at end of file