Skip to content

Commit

Permalink
sem/builtins: fix json_populate_record in an edge case
Browse files Browse the repository at this point in the history
This commit fixes `json_populate_record` builtin in an edge case. In
particular, this generator builtin calls `eval.PopulateRecordWithJSON`
which modifies the passed-in tuple in-place, and right now the builtin
passes the input tuple. This leads to modification of the Datum which is
not allowed. However, this is mostly philosophical bug that doesn't lead
to any actual issues since from a single input tuple the builtin only
generates a single output tuple. I noticed this problem when tried to
re-execute the distributed query as local, but the tuple was corrupted
for that second local execution.

Release note: None
  • Loading branch information
yuzefovich committed Jun 26, 2023
1 parent 7c9e0d1 commit be9a612
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/sql/sem/builtins/generator_builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -1760,10 +1760,12 @@ func (j *jsonPopulateRecordGenerator) Next(ctx context.Context) (bool, error) {

// Values is part of the tree.ValueGenerator interface.
func (j jsonPopulateRecordGenerator) Values() (tree.Datums, error) {
if err := eval.PopulateRecordWithJSON(j.ctx, j.evalCtx, j.target, j.input.ResolvedType(), j.input); err != nil {
output := tree.NewDTupleWithLen(j.input.ResolvedType(), j.input.D.Len())
copy(output.D, j.input.D)
if err := eval.PopulateRecordWithJSON(j.ctx, j.evalCtx, j.target, j.input.ResolvedType(), output); err != nil {
return nil, err
}
return j.input.D, nil
return output.D, nil
}

func makeJSONPopulateRecordSetGenerator(
Expand Down

0 comments on commit be9a612

Please sign in to comment.