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

cdc: support geometry types with the validator #134749

Merged
merged 1 commit into from
Nov 13, 2024
Merged

Conversation

wenyihu6
Copy link
Contributor

@wenyihu6 wenyihu6 commented Nov 9, 2024

This patch supports geometry,geography and array types.
We recognize there may be uncovered edge cases, but
we’ve chosen a lenient approach as this is for
testing purposes, and we want to avoid a potential
time sink. We plan to revisit and refine this as
we progress with the randomized testing framework.

Release note: none
Part of: #124146

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@wenyihu6 wenyihu6 changed the title cdc: make validator work for geometry types cdc: make validator work for geometry Nov 9, 2024
@wenyihu6 wenyihu6 changed the title cdc: make validator work for geometry cdc: support geometry types with the validator Nov 9, 2024
@wenyihu6 wenyihu6 force-pushed the rt branch 7 times, most recently from 0d7a4b1 to db6d239 Compare November 12, 2024 01:13

func TestExtractFieldFromJSON(t *testing.T) {
defer leaktest.AfterTest(t)()
skip.WithIssue(t, 134904)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this test is skipped with #134904.

@wenyihu6 wenyihu6 marked this pull request as ready for review November 12, 2024 14:18
@wenyihu6 wenyihu6 requested a review from a team as a code owner November 12, 2024 14:18
@wenyihu6 wenyihu6 requested review from asg0451 and rharding6373 and removed request for a team November 12, 2024 14:18
if err != nil {
return err
}
afterDatums, err := parseJSON(afterJson)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: naming: these arent datums, they're "go values"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed this offline. The name for Datums was adopted because we pass it as a RowDatum

field string, primaryKeyDatums []interface{}, rowDatums map[string]interface{}, ts hlc.Timestamp,
here. So we are cool with leaving Datums. I renamed this to afterValueDatums to be a bit clearer.

return ret, err
}

func parseJSON(d json.JSON) (map[string]interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't love this function's name -- it takes an already parsed crdb json and transforms it into go datatypes, including some weird geometry parsing stuff. can you update the name to reflect this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed it to convertJSONToMap. Do you like this more?

return nil, nil
}
ret := make(map[string]interface{})
switch d.Type() {
Copy link
Contributor

Choose a reason for hiding this comment

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

also, the way this function is used means that the input is always an object. can you simplify it using this? i'm also not convinced using the crdb json stuff is adding value here over just using gojson. if so you could just pass a map[string]any into here and greatly simplify things

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed this offline as well. Usually we take in Object, but we take in Null JSON sometimes as well. Addressed it by adding a case specifically for case json.NullJSONType:.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm also not convinced using the crdb json stuff is adding value here over just using gojson.

Chatted this offline as well. It is a bit tricky here since parsing it using gojson would require us to parse it to an interface first and then convert this interface back to a JSON type so that we can use geo.ParseGeographyFromGeoJSON if this interface turns out to be for a geometry type. We decided to just keep it this way for now and will revisit and see if there is a better way to handle this in the future.

"github.com/cockroachdb/cockroach/pkg/workload/rand"
)

func extractFieldFromJSON(d json.JSON) (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you make this name more descriptive or add a comment about what it's doing? maybe like attempts to coerce json data into a known go type, including geo or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Added a comment.

@wenyihu6 wenyihu6 force-pushed the rt branch 2 times, most recently from 56e679d to 5870660 Compare November 12, 2024 20:55
@wenyihu6 wenyihu6 requested a review from asg0451 November 12, 2024 21:01
This patch supports geometry.geography and array types.
We recognize there may be uncovered edge cases, but
we’ve chosen a lenient approach as this is for
testing purposes, and we want to avoid a potential
time sink. We plan to revisit and refine this as
we progress with the randomized testing framework.

Release note: none
Part of: cockroachdb#124146
@wenyihu6
Copy link
Contributor Author

Friendly ping for reviews here : )

Copy link
Contributor

@asg0451 asg0451 left a comment

Choose a reason for hiding this comment

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

i'm literally looking at it right now ;)

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rharding6373)

Copy link
Contributor

@asg0451 asg0451 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @rharding6373)

@wenyihu6
Copy link
Contributor Author

lol i will be more patient next time TFTR!

bors r=asg0451

@craig craig bot merged commit 0428ef9 into cockroachdb:master Nov 13, 2024
23 checks passed
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.

3 participants