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

sql: add json{,b}_populate_record{,set} #70115

Merged
merged 1 commit into from
Sep 20, 2021

Conversation

jordanlewis
Copy link
Member

Updates #69010
Updates #70037

These generator builtins permit type-safe transformation of JSON to
table data. They're added for compatibility with PostgreSQL.

Release note (sql change): add the json_populate_record,
jsonb_populate_record functions, json_populate_recordset, and
jsonb_populate_recordset functions, which transform JSON into row tuples
based on the labels in a record type.

@jordanlewis jordanlewis requested a review from a team September 13, 2021 13:12
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jordanlewis jordanlewis force-pushed the json-to-record branch 2 times, most recently from 36f78ec to a0a6d1a Compare September 14, 2021 13:47
pkg/sql/sem/tree/casts.go Outdated Show resolved Hide resolved
pkg/sql/logictest/testdata/logic_test/json Show resolved Hide resolved

func (j *jsonPopulateRecordGenerator) Start(_ context.Context, _ *kv.Txn) error {
if j.target != tree.DNull && j.target.(*tree.DJSON).JSON.Type() != json.ArrayJSONType {
return pgerror.Newf(pgcode.InvalidParameterValue, "argument of json_populate_recordset must be an array")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be moved to makeJSONPopulateRecordSetGenerator?

pkg/sql/sem/builtins/generator_builtins.go Outdated Show resolved Hide resolved
pkg/sql/sem/builtins/generator_builtins.go Show resolved Hide resolved
pkg/sql/sem/builtins/generator_builtins.go Outdated Show resolved Hide resolved
pkg/sql/sem/builtins/generator_builtins.go Show resolved Hide resolved
pkg/sql/sem/builtins/generator_builtins.go Show resolved Hide resolved
pkg/sql/sem/builtins/generator_builtins.go Outdated Show resolved Hide resolved
pkg/sql/sem/tree/overload.go Show resolved Hide resolved
@jordanlewis
Copy link
Member Author

Thanks for the suggestions, RFAL

These generator builtins permit type-safe transformation of JSON to
table data. They're added for compatibility with PostgreSQL.

Release note (sql change): add the json_populate_record,
jsonb_populate_record functions, json_populate_recordset, and
jsonb_populate_recordset functions, which transform JSON into row tuples
based on the labels in a record type.
Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@jordanlewis
Copy link
Member Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Sep 20, 2021

Build failed:

@jordanlewis
Copy link
Member Author

Flake

bors r+

@craig
Copy link
Contributor

craig bot commented Sep 20, 2021

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Sep 20, 2021

Build succeeded:

@craig craig bot merged commit fa61936 into cockroachdb:master Sep 20, 2021
mgartner added a commit to mgartner/cockroach that referenced this pull request Sep 24, 2021
The `Overload.GeneratorWithExprs` field was added in cockroachdb#70115. This commit
makes usage of this field safer by introducing the `IsGenerator` method
which can be used to determine if an overload is an SRF. This commit
also adds guardrails to prevent future issues with
`GeneratorWithExprs`in the `ConvertZipArraysToValues` normalization rule.

Release note: None
craig bot pushed a commit that referenced this pull request Sep 24, 2021
70699: sql: make builtin generators with GeneratorWithExprs safer r=mgartner a=mgartner

The `Overload.GeneratorWithExprs` field was added in #70115. This commit
makes usage of this field safer by introducing the `IsGenerator` method
which can be used to determine if an overload is an SRF. This commit
also adds guardrails to prevent future issues with
`GeneratorWithExprs`in the `ConvertZipArraysToValues` normalization rule.

Release note: None

Co-authored-by: Marcus Gartner <[email protected]>
@jordanlewis jordanlewis deleted the json-to-record branch September 26, 2021 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants