Skip to content
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
15 changes: 13 additions & 2 deletions velox/core/PlanConsistencyChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

class Checker : public PlanNodeVisitor {
public:
explicit Checker(PlanNodeId rootId) : rootId_{std::move(rootId)} {}

Check warning on line 32 in velox/core/PlanConsistencyChecker.cpp

View workflow job for this annotation

GitHub Actions / Build with GCC / Linux release with adapters

misc-include-cleaner

no header providing "std::move" is directly included

Check warning on line 32 in velox/core/PlanConsistencyChecker.cpp

View workflow job for this annotation

GitHub Actions / Build with GCC / Linux release with adapters

misc-include-cleaner

no header providing "facebook::velox::core::PlanNodeId" is directly included

void visit(const AggregationNode& node, PlanNodeVisitorContext& ctx)

Check warning on line 34 in velox/core/PlanConsistencyChecker.cpp

View workflow job for this annotation

GitHub Actions / Build with GCC / Linux release with adapters

misc-include-cleaner

no header providing "facebook::velox::core::PlanNodeVisitorContext" is directly included

Check warning on line 34 in velox/core/PlanConsistencyChecker.cpp

View workflow job for this annotation

GitHub Actions / Build with GCC / Linux release with adapters

misc-include-cleaner

no header providing "facebook::velox::core::AggregationNode" is directly included
const override {
const auto& rowType = node.sources().at(0)->outputType();
for (const auto& expr : node.groupingKeys()) {
Expand Down Expand Up @@ -200,7 +202,11 @@
checkInputs(expr, rowType);
}

verifyOutputNames(node);
// The root ProjectNode may have empty or duplicate output names when used
// to apply user-specified column aliases (e.g. SELECT 1 as x, 2 as x).
if (node.id() != rootId_) {
verifyOutputNames(node);
}

visitSources(&node, ctx);
}
Expand Down Expand Up @@ -333,13 +339,18 @@
checkInputs(input, rowType);
}
}

// ID of the root node. Used to skip output name validation on the root
// ProjectNode, which may have user-specified aliases that are empty or
// duplicated.
const PlanNodeId rootId_;
};
} // namespace

void PlanConsistencyChecker::check(const core::PlanNodePtr& plan) {
ExceptionContextSetter exceptionContext({planNodeMessage, (void*)plan.get()});
PlanNodeVisitorContext ctx;
Checker checker;
Checker checker{plan->id()};

Check warning on line 353 in velox/core/PlanConsistencyChecker.cpp

View workflow job for this annotation

GitHub Actions / Build with GCC / Linux release with adapters

misc-const-correctness

variable 'checker' of type 'Checker' can be declared 'const'
plan->accept(checker, ctx);
}
}; // namespace facebook::velox::core
59 changes: 38 additions & 21 deletions velox/core/tests/PlanConsistencyCheckerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,49 @@
auto valuesNode =
std::make_shared<ValuesNode>(nextId(), std::vector<RowVectorPtr>{});

auto projectNode = std::make_shared<ProjectNode>(
nextId(),
std::vector<std::string>{"a", "b", "c"},
std::vector<TypedExprPtr>{Lit(true), Lit(1), Lit(0.1)},
valuesNode);
ASSERT_NO_THROW(PlanConsistencyChecker::check(projectNode));
{
auto projectNode = std::make_shared<ProjectNode>(
nextId(),
std::vector<std::string>{"a", "b", "c"},
std::vector<TypedExprPtr>{Lit(true), Lit(1), Lit(0.1)},
valuesNode);
ASSERT_NO_THROW(PlanConsistencyChecker::check(projectNode));
}

// Duplicate output name.
projectNode = std::make_shared<ProjectNode>(
nextId(),
std::vector<std::string>{"a", "a", "c"},
std::vector<TypedExprPtr>{Lit(true), Lit(1), Lit(0.1)},
valuesNode);
{
// Duplicate output name in the root ProjectNode is allowed. This is used to
// apply user-specified column aliases (e.g. SELECT 1 AS x, 2 AS x).
auto projectNode = std::make_shared<ProjectNode>(
nextId(),
std::vector<std::string>{"a", "a", "c"},
std::vector<TypedExprPtr>{Lit(true), Lit(1), Lit(0.1)},
valuesNode);
ASSERT_NO_THROW(PlanConsistencyChecker::check(projectNode));

VELOX_ASSERT_THROW(
PlanConsistencyChecker::check(projectNode), "Duplicate output column: a");
// Duplicate output name in a non-root ProjectNode is not allowed.
auto outputProject = std::make_shared<ProjectNode>(
nextId(),
std::vector<std::string>{"x", "y", "z"},
std::vector<TypedExprPtr>{
Col(BOOLEAN(), "a"), Col(BOOLEAN(), "a"), Col(DOUBLE(), "c")},

Check warning on line 129 in velox/core/tests/PlanConsistencyCheckerTest.cpp

View workflow job for this annotation

GitHub Actions / Build with GCC / Linux release with adapters

misc-include-cleaner

no header providing "facebook::velox::DOUBLE" is directly included
projectNode);

VELOX_ASSERT_THROW(
PlanConsistencyChecker::check(outputProject),
"Duplicate output column: a");
}

// Wrong column name.
projectNode = std::make_shared<ProjectNode>(
nextId(),
std::vector<std::string>{"a", "a", "c"},
std::vector<TypedExprPtr>{Lit(true), Col(REAL(), "x"), Lit(0.1)},
valuesNode);
{
auto projectNode = std::make_shared<ProjectNode>(
nextId(),
std::vector<std::string>{"a", "a", "c"},
std::vector<TypedExprPtr>{Lit(true), Col(REAL(), "x"), Lit(0.1)},

Check warning on line 142 in velox/core/tests/PlanConsistencyCheckerTest.cpp

View workflow job for this annotation

GitHub Actions / Build with GCC / Linux release with adapters

misc-include-cleaner

no header providing "facebook::velox::REAL" is directly included
valuesNode);

VELOX_ASSERT_THROW(
PlanConsistencyChecker::check(projectNode), "Field not found: x");
VELOX_ASSERT_THROW(
PlanConsistencyChecker::check(projectNode), "Field not found: x");
}
}

TEST_F(PlanConsistencyCheckerTest, aggregation) {
Expand Down
Loading