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

Early validate json path. #1896

Merged
Merged
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
4 changes: 1 addition & 3 deletions ydb/library/yql/core/type_ann/type_ann_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,7 @@ namespace NTypeAnnImpl {
return false;
}

// second argument must be "Utf8" type
const auto& jsonPathArg = function.JsonPath().Ref();
if (!EnsureSpecificDataType(jsonPathArg, EDataSlot::Utf8, ctx.Expr)) {
if (!EnsureValidJsonPath(function.JsonPath().Ref(), ctx.Expr)) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/core/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ PEERDIR(
ydb/library/yql/core/url_lister/interface
ydb/library/yql/core/url_preprocessing/interface
ydb/library/yql/minikql
ydb/library/yql/minikql/jsonpath
ydb/library/yql/protos
ydb/library/yql/public/udf
ydb/library/yql/public/udf/tz
Expand Down
20 changes: 20 additions & 0 deletions ydb/library/yql/core/yql_expr_type_annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <ydb/library/yql/public/udf/udf_data_type.h>
#include <ydb/library/yql/minikql/dom/json.h>
#include <ydb/library/yql/minikql/dom/yson.h>
#include <ydb/library/yql/minikql/jsonpath/jsonpath.h>
#include <ydb/library/yql/core/sql_types/simple_types.h>
#include "ydb/library/yql/parser/pg_catalog/catalog.h"
#include <ydb/library/yql/parser/pg_wrapper/interface/utils.h>
Expand Down Expand Up @@ -6047,6 +6048,25 @@ bool EnsureScalarType(TPositionHandle position, const TTypeAnnotationNode& type,
return true;
}

bool EnsureValidJsonPath(const TExprNode& node, TExprContext& ctx) {
if (!EnsureSpecificDataType(node, EDataSlot::Utf8, ctx))
return false;

if (node.IsCallable("Utf8")) {
if (TIssues issues; !NJsonPath::ParseJsonPath(node.Tail().Content(), issues, 7U)) {
TIssue issue(ctx.GetPosition(node.Pos()), TStringBuilder() << "Invalid json path: " << node.Tail().Content());
if (bool(issues)) {
for (const auto& i : issues) {
issue.AddSubIssue(new TIssue(i));
}
}
ctx.AddError(issue);
return false;
}
}
return true;
}

const TTypeAnnotationNode* GetBlockItemType(const TTypeAnnotationNode& type, bool& isScalar) {
YQL_ENSURE(type.IsBlockOrScalar());
const auto kind = type.GetKind();
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/core/yql_expr_type_annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ bool EnsureDryType(TPositionHandle position, const TTypeAnnotationNode& type, TE
bool EnsureDryType(const TExprNode& node, TExprContext& ctx);
bool EnsureDictType(const TExprNode& node, TExprContext& ctx);
bool EnsureDictType(TPositionHandle position, const TTypeAnnotationNode& type, TExprContext& ctx);
bool EnsureValidJsonPath(const TExprNode& node, TExprContext& ctx);

bool IsVoidType(const TExprNode& node, TExprContext& ctx);
bool EnsureVoidType(const TExprNode& node, TExprContext& ctx);
Expand Down
2 changes: 1 addition & 1 deletion ydb/library/yql/minikql/jsonpath/jsonpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const TAstNodePtr ParseJsonPathAst(const TStringBuf path, TIssues& issues, size_
}

google::protobuf::Arena arena;
const google::protobuf::Message* rawAst;
const google::protobuf::Message* rawAst = nullptr;
{
#if defined(_tsan_enabled_)
TGuard<TMutex> guard(SanitizerJsonPathTranslationMutex);
Expand Down
Loading