diff --git a/velox/type/fbhive/HiveTypeSerializer.cpp b/velox/type/fbhive/HiveTypeSerializer.cpp index e1a6859d3486..203a74af1910 100644 --- a/velox/type/fbhive/HiveTypeSerializer.cpp +++ b/velox/type/fbhive/HiveTypeSerializer.cpp @@ -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()); } } diff --git a/velox/type/fbhive/tests/CMakeLists.txt b/velox/type/fbhive/tests/CMakeLists.txt index d7c4c456d9ed..e94ac225051d 100644 --- a/velox/type/fbhive/tests/CMakeLists.txt +++ b/velox/type/fbhive/tests/CMakeLists.txt @@ -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) diff --git a/velox/type/fbhive/tests/HiveTypeSerializerTests.cpp b/velox/type/fbhive/tests/HiveTypeSerializerTests.cpp new file mode 100644 index 000000000000..f293fe6815a8 --- /dev/null +++ b/velox/type/fbhive/tests/HiveTypeSerializerTests.cpp @@ -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 +#include + +#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 type = velox::BIGINT(); + auto result = HiveTypeSerializer::serialize(type); + EXPECT_EQ(result, "bigint"); +} + +TEST(HiveTypeSerializer, opaque) { + std::shared_ptr type = velox::OPAQUE(); + EXPECT_THROW( + { + try { + HiveTypeSerializer::serialize(type); + } catch (const std::logic_error& e) { + // Check exception message + EXPECT_STREQ("unsupported type: OPAQUE", e.what()); + throw; + } + }, + std::logic_error); +} + +} // namespace facebook::velox::type::fbhive