-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
…onstraint name as well
issues = append(issues, NewForeignKeyReferencesPartitionedTableIssue( | ||
TABLE_OBJECT_TYPE, | ||
table.GetObjectName(), | ||
"", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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..
partitionElements := createTableNode.CreateStmt.GetPartspec().GetPartParams() | ||
table.PartitionStrategy = createTableNode.CreateStmt.GetPartspec().GetStrategy() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
yb-voyager/src/utils/utils.go
Outdated
@@ -740,3 +740,7 @@ func CheckTools(tools ...string) []string { | |||
|
|||
return missingTools | |||
} | |||
|
|||
func GetObjectName(schemaName, objName string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: BuildObjectName
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
How was this pull request tested?
Added End-to-End tests, unit tests
Does your PR have changes that can cause upgrade issues?