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

Added a new detector for catching unsupported COPY command structure #2106

Merged
merged 12 commits into from
Dec 26, 2024

Conversation

ShivanshGahlot
Copy link
Collaborator

@ShivanshGahlot ShivanshGahlot commented Dec 19, 2024

Describe the changes in this pull request

Reporting two unsupported query constructs related to COPY command:

Added a new detector CopyCommandUnsupportedConstructsDetector in detectors.go to report both these constructs

Currently the PR also contains changes related to pg_query_go v6 upgrades. Will rebase the PR to main once I merge that PR

Describe if there are any user-facing changes

The assessment report now reports these constructs under UQC:
image

How was this pull request tested?

Added new unit tests for these copy constructs in:
parser_issue_detector_test.go
issue_dml_test.go
detectors_test.go

An end to end test for the same construct needs to be added

Does your PR have changes that can cause upgrade issues?

Component Breaking changes?
MetaDB No
Name registry json No
Data File Descriptor Json No
Export Snapshot Status Json No
Import Data State No
Export Status Json No
Data .sql files of tables No
Export and import data queue No
Schema Dump No
AssessmentDB No
Sizing DB No
Migration Assessment Report Json No
Callhome Json No
YugabyteD Tables No
TargetDB Metadata Tables No

@ShivanshGahlot ShivanshGahlot force-pushed the shivansh/unsupported-pg-report branch from 48f6f7c to c0f2b77 Compare December 20, 2024 05:02
@ShivanshGahlot ShivanshGahlot marked this pull request as ready for review December 20, 2024 10:35
return nil // Not a COPY statement, nothing to detect
}

// Check for COPY FROM ... WHERE clause
Copy link
Collaborator

Choose a reason for hiding this comment

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

Simplified code from what I was discussing in the morning:
I tried running your tests and they all passed, but do take a deeper look!
cc: @sanyamsinghal @priyanshi-yb

	protoMsg := msg.Interface().(proto.Message)
	copyStmt := protoMsg.(*pg_query.CopyStmt)

	if copyStmt.IsFrom && copyStmt.WhereClause != nil {
		d.copyFromWhereConstructDetected = true
	}
	for _, option := range copyStmt.Options {
		defElemNode := option.GetDefElem()
		if defElemNode != nil {
			if defElemNode.Defname == "on_error" {
				d.copyOnErrorConstructDetected = true
				break
			}
		}
	}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think yes this makes sense. It reduces the number of lines and readable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets stick to protomsg for this codepath, reason being the required info is not directly availabe in the struct and extraction of defElem can be generic and reused multiple times.

It can be simplified like this using existing helper functions:

FromField := GetMessageField(msg, "is_from")
whereField := GetMessageField(msg, "where_clause")
if FromField != nil && whereField != nil {
     d.copyFromWhereConstructDetected = true
}

defNames := TraverseAndExtractDefNamesFromDefElem(msg)
if slices.Contains(defNames, "on_error") {
    d.copyOnErrorConstructDetected = true
}

Refer my PR for TraverseAndExtractDefNamesFromDefElem

Copy link
Collaborator

Choose a reason for hiding this comment

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

just to be on the same page, there are two different issues here.

For the first one, isFrom and whereClause are directly available in CopyStmt struct, so would prefer dealing with the struct directly for that issue. But GetMessageField(msg, "is_from" isn't too bad either from a readability standpoint. I'll leave it up to you.

For the DefElem one, we can use the new function that Sanyam is introducing, but then you'll have to wait until that PR is merged.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had to add a new function GetBoolField() for the is_from clause. I have used the GetMessageField and GetBoolField approach rn for the first one.
For the second one, I have used Sanyam's function in my PR.

@ShivanshGahlot ShivanshGahlot force-pushed the shivansh/unsupported-pg-report branch from 788e744 to 2967e80 Compare December 23, 2024 05:44
return nil // Not a COPY statement, nothing to detect
}

// Check for COPY FROM ... WHERE clause
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets stick to protomsg for this codepath, reason being the required info is not directly availabe in the struct and extraction of defElem can be generic and reused multiple times.

It can be simplified like this using existing helper functions:

FromField := GetMessageField(msg, "is_from")
whereField := GetMessageField(msg, "where_clause")
if FromField != nil && whereField != nil {
     d.copyFromWhereConstructDetected = true
}

defNames := TraverseAndExtractDefNamesFromDefElem(msg)
if slices.Contains(defNames, "on_error") {
    d.copyOnErrorConstructDetected = true
}

Refer my PR for TraverseAndExtractDefNamesFromDefElem

@sanyamsinghal
Copy link
Collaborator

Also please add some simple end to end tests, just to cover - final assessment report is getting populated with the required info.

@ShivanshGahlot ShivanshGahlot force-pushed the shivansh/unsupported-pg-report branch 3 times, most recently from 937711e to 8ce2110 Compare December 24, 2024 12:44
@ShivanshGahlot ShivanshGahlot force-pushed the shivansh/unsupported-pg-report branch from 9ccf2c6 to 3a6915f Compare December 24, 2024 13:54
Copy link
Collaborator

@sanyamsinghal sanyamsinghal left a comment

Choose a reason for hiding this comment

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

LGTM.
If you are planning to add end-to-end tests later, then do file a ticket for that.

@@ -649,3 +649,42 @@ func TestRegexFunctionsIssue(t *testing.T) {
}

}

func TestCopyUnsupportedConstructIssuesDetected(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

see if the tests for this can be at one place only either in detectors.go or parse_issue_detector_test.go

Currently we have the tests distributed among these two files, but since they are essentially testing the same thing, we can just have it one place.

Copy link
Collaborator Author

@ShivanshGahlot ShivanshGahlot Dec 26, 2024

Choose a reason for hiding this comment

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

Yeah for now I have added the tests but commented out the sql of CREATE ... ON_ERROR since it is supported only on PG17. Have added a ticket to do the same:
#2119

Copy link
Collaborator Author

@ShivanshGahlot ShivanshGahlot Dec 26, 2024

Choose a reason for hiding this comment

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

Removed the tests from detectors_test.go. The tests are same anyways. They were helpful in development.

@ShivanshGahlot ShivanshGahlot merged commit f19b943 into main Dec 26, 2024
43 checks passed
@ShivanshGahlot ShivanshGahlot deleted the shivansh/unsupported-pg-report branch December 26, 2024 10:38
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