Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve duplicated key error message #9374

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions velox/dwio/dwrf/test/ColumnWriterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,22 +1215,41 @@ TEST_F(ColumnWriterTest, TestMapWriterInt64Key) {
testMapWriterNumericKey<int64_t>(/* useFlatMap */ true, /* useStruct */ true);
}

TEST_F(ColumnWriterTest, TestMapWriterDuplicatedInt64Key) {
using T = int64_t;
using b = MapBuilder<T, T>;

auto pool = memory::memoryManager()->addLeafPool();
auto batch = b::create(
*pool, {typename b::row{typename b::pair{5, 3}, typename b::pair{5, 4}}});

EXPECT_THAT(
([&]() { testMapWriter<T, T>(*pool, batch, /* useFlatMap */ true); }),
Throws<
facebook::velox::dwio::common::exception::LoggedException>(Property(
&facebook::velox::dwio::common::exception::LoggedException::message,
HasSubstr("Duplicated key in map: 5"))));
}

TEST_F(ColumnWriterTest, TestMapWriterInt32Key) {
testMapWriterNumericKey<int32_t>(/* useFlatMap */ false);
testMapWriterNumericKey<int32_t>(/* useFlatMap */ true);
testMapWriterNumericKey<int32_t>(/* useFlatMap */ true, /* useStruct */ true);
testMapWriterNumericKey<int32_t>(
/* useFlatMap */ true, /* useStruct */ true);
}

TEST_F(ColumnWriterTest, TestMapWriterInt16Key) {
testMapWriterNumericKey<int16_t>(/* useFlatMap */ false);
testMapWriterNumericKey<int16_t>(/* useFlatMap */ true);
testMapWriterNumericKey<int16_t>(/* useFlatMap */ true, /* useStruct */ true);
testMapWriterNumericKey<int16_t>(
/* useFlatMap */ true, /* useStruct */ true);
}

TEST_F(ColumnWriterTest, TestMapWriterInt8Key) {
testMapWriterNumericKey<int8_t>(/* useFlatMap */ false);
testMapWriterNumericKey<int8_t>(/* useFlatMap */ true);
testMapWriterNumericKey<int8_t>(/* useFlatMap */ true, /* useStruct */ true);
testMapWriterNumericKey<int8_t>(
/* useFlatMap */ true, /* useStruct */ true);
}

TEST_F(ColumnWriterTest, TestMapWriterStringKey) {
Expand All @@ -1250,6 +1269,26 @@ TEST_F(ColumnWriterTest, TestMapWriterStringKey) {
*pool_, batch, /* useFlatMap */ true, true, /* useStruct */ true);
}

TEST_F(ColumnWriterTest, TestMapWriterDuplicatedStringKey) {
using keyType = StringView;
using valueType = StringView;
using b = MapBuilder<keyType, valueType>;

auto pool = memory::memoryManager()->addLeafPool();
auto batch = b::create(
*pool_,
{b::row{b::pair{"2", "5"}, b::pair{"2", "8"}}}); // Duplicated key: 2

EXPECT_THAT(
([&]() {
testMapWriter<keyType, valueType>(*pool_, batch, /* useFlatMap */ true);
}),
Throws<
facebook::velox::dwio::common::exception::LoggedException>(Property(
&facebook::velox::dwio::common::exception::LoggedException::message,
HasSubstr("Duplicated key in map: 2"))));
}

TEST_F(ColumnWriterTest, TestMapWriterDifferentNumericKeyValue) {
using keyType = float;
using valueType = int32_t;
Expand Down
8 changes: 7 additions & 1 deletion velox/dwio/dwrf/writer/FlatMapColumnWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ class ValueWriter {

void addOffset(uint64_t offset, uint64_t inMapIndex) {
if (UNLIKELY(inMapBuffer_[inMapIndex])) {
DWIO_RAISE("Duplicate key in map");
std::string duplicatedKey = "<unknown>";
if (keyInfo_.has_byteskey()) {
duplicatedKey = keyInfo_.byteskey();
} else if (keyInfo_.has_intkey()) {
duplicatedKey = std::to_string(keyInfo_.intkey());
}
DWIO_RAISE("Duplicated key in map: ", duplicatedKey);
}

ranges_.add(offset, offset + 1);
Expand Down
Loading