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

Reporting Foreign Key references Partitioned table in analyze and assessment #2145

Merged
merged 10 commits into from
Jan 6, 2025

Conversation

priyanshi-yb
Copy link
Contributor

@priyanshi-yb priyanshi-yb commented Jan 2, 2025

Describe the changes in this pull request

Fixes #1989

Describe if there are any user-facing changes

Added an Unsupported feature in assessment - Foreign key references partitioned table

Screenshot 2025-01-02 at 8 53 13 PM

How was this pull request tested?

Added End-to-End tests, unit tests

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

@priyanshi-yb priyanshi-yb marked this pull request as ready for review January 3, 2025 05:57
issues = append(issues, NewForeignKeyReferencesPartitionedTableIssue(
TABLE_OBJECT_TYPE,
table.GetObjectName(),
"",
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets add sqlstatement also here?
Moving forward(flattening of issues in assessment report), we will have this field for each issue and its good to have sql statement available in each case.

Copy link
Contributor Author

@priyanshi-yb priyanshi-yb Jan 6, 2025

Choose a reason for hiding this comment

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

SQL statement is already added for these later in the GetDDLIssues

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm.. not sure what is the reason of adding it there.
But adding at the time of issue creation makes more sense to me.
is the sql statement getting modified somewhere in between.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No not changing sql statement anywhere, it's just that skipping the overhead of passing the query to these ddl_detectors, so adding it in one go there itself.

@@ -273,6 +274,19 @@ func testSecurityInvokerView(t *testing.T) {
assertErrorCorrectlyThrownForIssueForYBVersion(t, err, "unrecognized parameter", securityInvokerViewIssue)
}

func testForeignKeyReferencesPartitionedTableIssue(t *testing.T) {
ctx := context.Background()
conn, err := getConn()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using the new testcontainers package in this test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we do it separately for these issues integration tests as it will require changes to all these tests to not use the connection string to run the SQL commands directly and assert the error instead use the ExecuteSqls of the testContainer

@@ -754,3 +754,56 @@ func TestCopyUnsupportedConstructIssuesDetected(t *testing.T) {
}
}
}

func TestForeignKeyReferencesPartitionedTableIssues(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.

can we remove any redundant test here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no redundant cases here all of them have different ways of defining the constraint and qualified or unqualified table names etc..

Comment on lines +129 to +130
partitionElements := createTableNode.CreateStmt.GetPartspec().GetPartParams()
table.PartitionStrategy = createTableNode.CreateStmt.GetPartspec().GetStrategy()
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider using protomsg approach here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the old code, so I haven't changed it. I am just using the already-written code in this case.

@@ -354,6 +375,9 @@ func (t *Table) addConstraint(conType pg_query.ConstrType, columns []string, spe
generatedConName := tc.generateConstraintName(t.TableName)
conName := lo.Ternary(specifiedConName == "", generatedConName, specifiedConName)
tc.ConstraintName = conName
if conType == FOREIGN_CONSTR_TYPE {
tc.ReferencedTable = lo.Ternary(referencedTable.Schemaname != "", referencedTable.Schemaname+"."+referencedTable.Relname, referencedTable.Relname)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: i think this operation of fetching qualified name is used at multiple places.
Consider writing a helper/util function for this.

@@ -354,6 +375,9 @@ func (t *Table) addConstraint(conType pg_query.ConstrType, columns []string, spe
generatedConName := tc.generateConstraintName(t.TableName)
conName := lo.Ternary(specifiedConName == "", generatedConName, specifiedConName)
tc.ConstraintName = conName
if conType == FOREIGN_CONSTR_TYPE {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why doing this in case of foreign key only. Can this be a unconditional step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reference table is only present in case of foreign keys so using the field only in that case as it will be nil in other cases

return table, nil
}

func (tableProcessor *TableProcessor) parseTableElts(tableElts []*pg_query.Node, table *Table) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Few summary comments about table processor related code will help here.

yb-voyager/src/query/queryparser/helpers_protomsg.go Outdated Show resolved Hide resolved
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

@@ -740,3 +740,7 @@ func CheckTools(tools ...string) []string {

return missingTools
}

func GetObjectName(schemaName, objName string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: BuildObjectName

@priyanshi-yb priyanshi-yb merged commit 5a50ec5 into main Jan 6, 2025
67 checks passed
@priyanshi-yb priyanshi-yb deleted the priyanshi/fk-referenced-part-table branch January 6, 2025 14:16
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.

Report foreign key reference to partitioned table as unsupported
2 participants