Skip to content

handle JsonExists pushdown simularily to JsonValue #15151

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

Merged
merged 1 commit into from
Feb 27, 2025
Merged
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
25 changes: 13 additions & 12 deletions ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ TMaybeNode<TExprBase> YqlApplyPushdown(const TExprBase& apply, const TExprNode&
.Done();
}

TMaybeNode<TExprBase> JsonExistsPushdown(const TCoJsonExists& jsonExists, TExprContext& ctx, TPositionHandle pos)
{
auto columnName = jsonExists.Json().Cast<TCoMember>().Name();
return Build<TKqpOlapJsonExists>(ctx, pos)
.Column(columnName)
.Path(jsonExists.JsonPath().Cast<TCoUtf8>())
.Done();
}

std::vector<TExprBase> ConvertComparisonNode(const TExprBase& nodeIn, const TExprNode& argument, TExprContext& ctx, TPositionHandle pos)
{
std::vector<TExprBase> out;
Expand Down Expand Up @@ -249,6 +258,10 @@ std::vector<TExprBase> ConvertComparisonNode(const TExprBase& nodeIn, const TExp
return builder.Done();
}

if (auto maybeJsonExists = node.Maybe<TCoJsonExists>()) {
return JsonExistsPushdown(maybeJsonExists.Cast(), ctx, pos);
}

if (const auto maybeJust = node.Maybe<TCoJust>()) {
if (const auto params = ConvertComparisonNode(maybeJust.Cast().Input(), argument, ctx, pos); 1U == params.size()) {
return Build<TKqpOlapFilterUnaryOp>(ctx, node.Pos())
Expand Down Expand Up @@ -515,15 +528,6 @@ TMaybeNode<TExprBase> ExistsPushdown(const TCoExists& exists, TExprContext& ctx,
.Done();
}

TMaybeNode<TExprBase> JsonExistsPushdown(const TCoJsonExists& jsonExists, TExprContext& ctx, TPositionHandle pos)
{
auto columnName = jsonExists.Json().Cast<TCoMember>().Name();
return Build<TKqpOlapJsonExists>(ctx, pos)
.Column(columnName)
.Path(jsonExists.JsonPath().Cast<TCoUtf8>())
.Done();
}

TMaybeNode<TExprBase> SafeCastPredicatePushdown(const TCoFlatMap& inputFlatmap, const TExprNode& argument, TExprContext& ctx, TPositionHandle pos)
{
/*
Expand Down Expand Up @@ -572,10 +576,7 @@ TMaybeNode<TExprBase> CoalescePushdown(const TCoCoalesce& coalesce, const TExprN
return SafeCastPredicatePushdown(maybeFlatmap.Cast(), argument, ctx, pos);
} else if (auto maybePredicate = predicate.Maybe<TCoCompare>()) {
return SimplePredicatePushdown(maybePredicate.Cast(), argument, ctx, pos);
} else if (auto maybeJsonExists = predicate.Maybe<TCoJsonExists>()) {
return JsonExistsPushdown(maybeJsonExists.Cast(), ctx, pos);
}

return NullNode;
}

Expand Down
Loading