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

planner, json: restore cast flag after substitute column in cast #39997

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,22 @@ func TestAggregationBuiltinJSONObjectAgg(t *testing.T) {
result.Check(testkit.Rows(`{"first": "json_objectagg_test"}`))
result = tk.MustQuery("select json_objectagg(a, null) from t group by a order by a;")
result.Check(testkit.Rows(`{"1": null}`))

// For issue: https://github.com/pingcap/tidb/issues/39806
// Optimization shouldn't rewrite the flag of `castStringAsJson`.
tk.MustQuery(`
select a from (
select JSON_OBJECT('number', number, 'name', name) 'a' from
(
select 1 as number, 'name-1' as name union
(select 2, 'name-2' ) union
(select 3, 'name-3' ) union
(select 4, 'name-4' ) union
(select 5, 'name-5' ) union
(select 6, 'name-2' )
) temp1
) temp
where a ->> '$.number' = 1`).Check(testkit.Rows(`{"name": "name-1", "number": 1}`))
YangKeao marked this conversation as resolved.
Show resolved Hide resolved
}

func TestOtherBuiltin(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions expression/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,10 @@ func ColumnSubstituteImpl(expr Expression, schema *Schema, newExprs []Expression
return substituted, hasFail, v
}
if substituted {
flag := v.RetType.GetFlag()
e := BuildCastFunction(v.GetCtx(), newArg, v.RetType)
e.SetCoercibility(v.Coercibility())
e.GetType().SetFlag(flag)
return true, false, e
}
return false, false, v
Expand Down