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: refactoring virtualSchemaTable.allTableNames into undefinedTables #63144

Merged
merged 1 commit into from
Apr 13, 2021

Conversation

mnovelodou
Copy link
Contributor

@mnovelodou mnovelodou commented Apr 6, 2021

Previously, allTableNames have implemented and unimplemented tableNames
This was inadequate because the duplicity makes difficult to maintain
To address this, this patch refactors allTableNames into
undefinedTables to keep only the tables that are not in tableDefs

Release note: None

Fixes #61801

@mnovelodou mnovelodou requested a review from RichardJCai April 6, 2021 14:04
@blathers-crl
Copy link

blathers-crl bot commented Apr 6, 2021

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl blathers-crl bot added the O-community Originated from the community label Apr 6, 2021
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@mnovelodou mnovelodou force-pushed the unimplemented-tables branch from a2ecdac to cc0c22b Compare April 6, 2021 14:46
@blathers-crl
Copy link

blathers-crl bot commented Apr 6, 2021

Thank you for updating your pull request.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

Copy link
Contributor

@RichardJCai RichardJCai left a comment

Choose a reason for hiding this comment

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

One thought I had was instead of referring to these tables as unimplementedTables, maybe we should use undefinedTables since we have tables that are defined but technically not implemented as well.

These tables can strictly be the ones that are undefined. Thoughts?

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


pkg/sql/pg_metadata_test.go, line 82 at r1 (raw file):

	tableDefsDeclaration               = `tableDefs: map[descpb.ID]virtualSchemaDef{`
	tableDefsTerminal                  = `},`
	unimplementedTableNamesDeclaration = `unimplementedTableNames: buildStringSet(`

One thing I just thought of is if we change the code in pg_catalog.go, if we rename this variable again for whatever reason, we might miss updating the corresponding code here.

Is there a test or anything that keeps this in check? I definitely see this getting or some part of this code being updated in the future.
What happens right now if we update the variable name for unimplementedTableNames without changing this code here?


pkg/sql/pg_metadata_test.go, line 515 at r1 (raw file):

// getTableNameFromCreateTable uses pkg/sql/parser to analize CREATE TABLE
// statement to retrieve table name

nit: Missing period


pkg/sql/virtual_schema_test.go, line 12 at r1 (raw file):

// VirtualSchemaTest validates virtualSchema that unimplementedTableNames
// only have tables that do not have a virtualSchemaTable defined.

nit: only has tables

Copy link
Contributor Author

@mnovelodou mnovelodou left a comment

Choose a reason for hiding this comment

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

Love it, I've been having difficulties to separate what is a unimplemented and undefined. Let me work on that change.

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


pkg/sql/pg_metadata_test.go, line 82 at r1 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

One thing I just thought of is if we change the code in pg_catalog.go, if we rename this variable again for whatever reason, we might miss updating the corresponding code here.

Is there a test or anything that keeps this in check? I definitely see this getting or some part of this code being updated in the future.
What happens right now if we update the variable name for unimplementedTableNames without changing this code here?

If you don't change the code here, it will break the code in charge of modifying the unimplementedTableNames, I mean, no actual production code will break here, What I can do is to create a goTest that validates this unimplementedTableNamesDeclaration is a field of virtualSchema, I think I can do some reflection here.


pkg/sql/pg_metadata_test.go, line 515 at r1 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

nit: Missing period

Done.


pkg/sql/virtual_schema_test.go, line 12 at r1 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

nit: only has tables

Done.

@mnovelodou mnovelodou force-pushed the unimplemented-tables branch from cc0c22b to a36c541 Compare April 7, 2021 19:29
@mnovelodou mnovelodou changed the title sql: refactoring virtualSchemaTable.allTableNames into unimplementedTableNames sql: refactoring virtualSchemaTable.allTableNames into undefinedTables Apr 7, 2021
@mnovelodou mnovelodou force-pushed the unimplemented-tables branch 2 times, most recently from 5fd3d46 to b1b1659 Compare April 8, 2021 19:02
@mnovelodou mnovelodou requested a review from RichardJCai April 8, 2021 19:32
Copy link
Contributor

@RichardJCai RichardJCai left a comment

Choose a reason for hiding this comment

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

Looks pretty much good to me, small nits.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mnovelodou and @RichardJCai)


pkg/sql/pg_metadata_test.go, line 515 at r2 (raw file):

}

// getTableNameFromCreateTable uses pkg/sql/parser to analize CREATE TABLE

analize -> analyze


pkg/sql/pg_metadata_test.go, line 529 at r2 (raw file):

// getUndefinedTablesText retrieves pgCatalog.undefinedTables, then it merges the
// new table names and formats the replacement text.
func getUndefinedTablesText(notImplemented PGMetadataTables, vs virtualSchema) (string, error) {

I think notImplemented should become undefinedTables here


pkg/sql/pg_metadata_test.go, line 543 at r2 (raw file):

	removeTables := make(map[string]struct{})
	for _, table := range vs.tableDefs {
		tableName, err := getTableNameFromCreateTable(table.getSchema())

I'm surprised we have to do all this work to grab the name of the table, we probably shoulda added a name field and populated it upstream but I don't want to introduce more work here right now since that would be fairly tedious.

@mnovelodou mnovelodou force-pushed the unimplemented-tables branch from b1b1659 to f1f3607 Compare April 9, 2021 16:14
Copy link
Contributor Author

@mnovelodou mnovelodou left a comment

Choose a reason for hiding this comment

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

Done.

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


pkg/sql/pg_metadata_test.go, line 515 at r2 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

analize -> analyze

Done.


pkg/sql/pg_metadata_test.go, line 529 at r2 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

I think notImplemented should become undefinedTables here

Actually, they are notImplemented that will be defined as tableDefs after this process ran, so here it is correct, but I will rename it as newTables for better readability


pkg/sql/pg_metadata_test.go, line 543 at r2 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

I'm surprised we have to do all this work to grab the name of the table, we probably shoulda added a name field and populated it upstream but I don't want to introduce more work here right now since that would be fairly tedious.

I don't feel it like a lot of work, initially in this file I was using a regular expression, here I am just reusing code that parses the CREATE TABLE but I don't feel it is really a big deal. I think this isn't likely to fail due to a refactoring unless you stop using "CREATE TABLE" for this.

By the way adding a name might do this code more prone for human failure as there is CREATE TABLE name and there would be another tableName field.

Previously, allTableNames have implemented and unimplemented tableNames
This was inadequate because the duplicity makes difficult to maintain
To address this, this patch refactors allTableNames into
undefinedTables to keep only the tables that are not in tableDefs

Release note: None

Fixes cockroachdb#61801
@mnovelodou mnovelodou force-pushed the unimplemented-tables branch from f1f3607 to 345f9d7 Compare April 9, 2021 16:17
@mnovelodou mnovelodou requested a review from RichardJCai April 9, 2021 19:56
Copy link
Contributor

@RichardJCai RichardJCai left a comment

Choose a reason for hiding this comment

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

Thanks for this! Overall looks good to me

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @mnovelodou and @RichardJCai)


pkg/sql/pg_metadata_test.go, line 543 at r2 (raw file):

Previously, mnovelodou (Miguel Novelo) wrote…

I don't feel it like a lot of work, initially in this file I was using a regular expression, here I am just reusing code that parses the CREATE TABLE but I don't feel it is really a big deal. I think this isn't likely to fail due to a refactoring unless you stop using "CREATE TABLE" for this.

By the way adding a name might do this code more prone for human failure as there is CREATE TABLE name and there would be another tableName field.

Yeah that's fair


pkg/sql/pg_metadata_test.go, line 741 at r3 (raw file):

	propertyIndex := strings.IndexRune(undefinedTablesDeclaration, ':')
	property := undefinedTablesDeclaration[:propertyIndex]
	// Using pgCatalog but information_schema is a virtualSchema as well

Reading off your comment here, should we check information_schema as well?

Copy link
Contributor Author

@mnovelodou mnovelodou left a comment

Choose a reason for hiding this comment

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

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


pkg/sql/pg_metadata_test.go, line 543 at r2 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

Yeah that's fair

Done.


pkg/sql/pg_metadata_test.go, line 741 at r3 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

Reading off your comment here, should we check information_schema as well?

I don't think so, this is checking the type, not a particular object, I coudn't see how to just use the type for doing this, so I am passing pg_catalog, if you have a suggestion, I can check using another way.

@RichardJCai
Copy link
Contributor

Sounds good to me

bors r+

@craig
Copy link
Contributor

craig bot commented Apr 13, 2021

Build succeeded:

@craig craig bot merged commit 1068d19 into cockroachdb:master Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: organize / track better which vtables are implemented
3 participants