Skip to content

Commit

Permalink
Skip incompatible feature ordering configuration
Browse files Browse the repository at this point in the history
Summary: Skip incompatible feature ordering configuration to avoid writer failures in case of mismatch in the schema or flat map configuration.

Differential Revision: D68024263
  • Loading branch information
sdruzkin authored and facebook-github-bot committed Jan 10, 2025
1 parent e098251 commit e5ddf7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
28 changes: 16 additions & 12 deletions dwio/nimble/velox/LayoutPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,23 @@ std::vector<Stream> DefaultLayoutPlanner::getLayout(
orderedFlatMapOffsets.reserve(flatMapFeatureOrder_.size() * 3);

for (const auto& flatMapFeatures : flatMapFeatureOrder_) {
NIMBLE_CHECK(
std::get<0>(flatMapFeatures) < root.childrenCount(),
fmt::format(
"Column ordinal {} for feature ordering is out of range. "
"Top-level row has {} columns.",
std::get<0>(flatMapFeatures),
root.childrenCount()));
if (std::get<0>(flatMapFeatures) >= root.childrenCount()) {
LOG(WARNING) << fmt::format(
"Column ordinal {} for feature ordering is out of range. "
"Top-level row has {} columns.",
std::get<0>(flatMapFeatures),
root.childrenCount());
continue;
}

auto& column = root.childAt(std::get<0>(flatMapFeatures));
NIMBLE_CHECK(
column.kind() == Kind::FlatMap,
fmt::format(
"Column '{}' for feature ordering is not a flat map.",
root.nameAt(std::get<0>(flatMapFeatures))));

if (column.kind() != Kind::FlatMap) {
LOG(WARNING) << fmt::format(
"Column '{}' for feature ordering is not a flat map.",
root.nameAt(std::get<0>(flatMapFeatures)));
continue;
}

auto& flatMap = column.asFlatMap();

Expand Down
21 changes: 4 additions & 17 deletions dwio/nimble/velox/tests/LayoutPlannerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ TEST(DefaultLayoutPlannerTests, NoFeatureReordering) {
testStreamLayout(rng, planner, std::move(streams), std::move(expected));
}

TEST(DefaultLayoutPlannerTests, IncompatibleOrdinals) {
TEST(DefaultLayoutPlannerTests, IncompatibleOrdinalsAreIgnored) {
nimble::SchemaBuilder builder;

nimble::test::FlatMapChildAdder fm1;
Expand Down Expand Up @@ -422,17 +422,10 @@ TEST(DefaultLayoutPlannerTests, IncompatibleOrdinals) {
nimble::DefaultLayoutPlanner planner{
[&]() { return builder.getRoot(); },
{{{1, {3, 42, 9, 2, 21}}, {2, {3, 2, 42, 21}}}}};
try {
planner.getLayout({});
FAIL() << "Factory should have failed.";
} catch (const nimble::NimbleUserError& e) {
EXPECT_THAT(
e.what(),
::testing::HasSubstr("for feature ordering is not a flat map"));
}
planner.getLayout({});
}

TEST(DefaultLayoutPlannerTests, OrdinalOutOfRange) {
TEST(DefaultLayoutPlannerTests, OrdinalOutOfRangeAreIgnored) {
nimble::SchemaBuilder builder;

nimble::test::FlatMapChildAdder fm1;
Expand Down Expand Up @@ -460,13 +453,7 @@ TEST(DefaultLayoutPlannerTests, OrdinalOutOfRange) {
nimble::DefaultLayoutPlanner planner{
[&]() { return builder.getRoot(); },
{{{6, {3, 42, 9, 2, 21}}, {3, {3, 2, 42, 21}}}}};
try {
planner.getLayout({});
FAIL() << "Factory should have failed.";
} catch (const nimble::NimbleUserError& e) {
EXPECT_THAT(
e.what(), ::testing::HasSubstr("for feature ordering is out of range"));
}
planner.getLayout({});
}

TEST(DefaultLayoutPlannerTests, IncompatibleSchema) {
Expand Down

0 comments on commit e5ddf7f

Please sign in to comment.