Skip to content

Commit 0170634

Browse files
committed
Remove unnecessary quotes from json path (#19501)
1 parent ad9862d commit 0170634

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

ydb/core/kqp/opt/physical/kqp_opt_phy_olap_filter.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,24 @@ TMaybeNode<TExprBase> SafeCastPredicatePushdown(const TCoFlatMap& inputFlatmap,
312312
return ComparisonPushdown(parameters, predicate, ctx, pos);
313313
}
314314

315+
namespace {
316+
317+
//Workarownd for #19125
318+
NYql::NNodes::TCoUtf8 RemoveJsonPathUnnecessaryQuote(const NYql::NNodes::TCoUtf8& node, TExprContext& ctx) {
319+
const std::string_view& path = node.Literal().StringValue();
320+
if (UTF8Detect(path) == ASCII && path.starts_with("$.\"") && path.substr(3).ends_with("\"")) {
321+
const auto& nakedPath = path.substr(3, path.length()-4);
322+
for (auto c: nakedPath) {
323+
if (!isalpha(c) && !isdigit(c) && c != '_') {
324+
return node;
325+
}
326+
}
327+
return Build<TCoUtf8>(ctx, node.Pos()).Literal().Build(TString("$.") + nakedPath).Done();
328+
}
329+
return node;
330+
}
331+
332+
} //namespace
315333

316334
std::vector<TExprBase> ConvertComparisonNode(const TExprBase& nodeIn, const TExprNode& argument, TExprContext& ctx, TPositionHandle pos, bool allowApply)
317335
{
@@ -346,7 +364,7 @@ std::vector<TExprBase> ConvertComparisonNode(const TExprBase& nodeIn, const TExp
346364

347365
auto builder = Build<TKqpOlapJsonValue>(ctx, pos)
348366
.Column(maybeColMember.Cast().Name())
349-
.Path(maybePathUtf8.Cast());
367+
.Path(RemoveJsonPathUnnecessaryQuote(maybePathUtf8.Cast(), ctx));
350368
if (maybeReturningType) {
351369
builder.ReturningType(maybeReturningType.Cast());
352370
} else {

ydb/core/kqp/ut/olap/json_ut.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,11 @@ Y_UNIT_TEST_SUITE(KqpOlapJson) {
654654
EXPECTED: [[4u;["{\"a\":\"a4\",\"b.c.d\":\"b4\"}"]];[14u;["{\"a\":\"a4\",\"b.c.d\":\"1b4\"}"]]]
655655
IDX_ND_SKIP_APPROVE: 0, 3, 2
656656
------
657+
READ: SELECT * FROM `/Root/ColumnTable` WHERE JSON_VALUE(Col2, "$.\"a\"") = "a4" ORDER BY Col1;
658+
EXPECTED: [[4u;["{\"a\":\"a4\",\"b.c.d\":\"b4\"}"]];[14u;["{\"a\":\"a4\",\"b.c.d\":\"1b4\"}"]]]
659+
IDX_ND_SKIP_APPROVE: 0, 3, 2
660+
------
661+
657662
READ: SELECT * FROM `/Root/ColumnTable` WHERE JSON_VALUE(Col2, "$.\"b.c.d111\"") = "1b5" ORDER BY Col1;
658663
EXPECTED: []
659664
IDX_ND_SKIP_APPROVE: 0, 5, 0

0 commit comments

Comments
 (0)