Skip to content

Commit

Permalink
improve error msg of HiveTypeSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
kunigami committed Sep 27, 2024
1 parent 52750de commit 17a724d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion velox/type/fbhive/HiveTypeSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::string HiveTypeSerializer::visit(const Type& type) const {
case TypeKind::ROW:
return "struct<" + visitChildren(type.asRow()) + ">";
default:
throw std::logic_error("unknown batch type");
throw std::logic_error("unsupported type: " + type.toString());
}
}

Expand Down
15 changes: 15 additions & 0 deletions velox/type/fbhive/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ target_link_libraries(
GTest::gtest
GTest::gtest_main
GTest::gmock)

add_executable(velox_type_serializer_fbhive_test HiveTypeSerializerTests.cpp)

add_test(
NAME velox_type_serializer_fbhive_test
COMMAND velox_type_serializer_fbhive_test
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(
velox_type_serializer_fbhive_test
velox_type_fbhive
velox_type
GTest::gtest
GTest::gtest_main
GTest::gmock)
51 changes: 51 additions & 0 deletions velox/type/fbhive/tests/HiveTypeSerializerTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <memory>
#include <stdexcept>

#include "gtest/gtest-message.h"
#include "gtest/gtest-test-part.h"
#include "gtest/gtest.h"
#include "velox/common/base/tests/GTestUtils.h"
#include "velox/type/fbhive/HiveTypeSerializer.h"

using facebook::velox::TypeKind;

namespace facebook::velox::type::fbhive {

TEST(HiveTypeSerializer, primitive) {
std::shared_ptr<const velox::Type> type = velox::BIGINT();
auto result = HiveTypeSerializer::serialize(type);
EXPECT_EQ(result, "bigint");
}

TEST(HiveTypeSerializer, opaque) {
std::shared_ptr<const velox::Type> type = velox::OPAQUE<bool>();
EXPECT_THROW(
{
try {
HiveTypeSerializer::serialize(type);
} catch (const std::logic_error& e) {
// Check exception message
EXPECT_STREQ("unsupported type: OPAQUE<bool>", e.what());
throw;
}
},
std::logic_error);
}

} // namespace facebook::velox::type::fbhive

0 comments on commit 17a724d

Please sign in to comment.