-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: code generation for missing pg catalog tables #58519
sql: code generation for missing pg catalog tables #58519
Conversation
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. Before a member of our team reviews your PR, I have some potential action items for you:
I have added a few people who may be able to assist in reviewing: 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
c68d2a6
to
4709d4f
Compare
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
4709d4f
to
558e46c
Compare
558e46c
to
3c667f2
Compare
8704d08
to
2afa951
Compare
2afa951
to
abc72c1
Compare
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. |
f836002
to
962b06c
Compare
2d6a869
to
22c9045
Compare
pkg/sql/virtual_schema.go
Outdated
@@ -176,6 +177,7 @@ func (t virtualSchemaTable) initVirtualTableDesc( | |||
tree.PersistencePermanent, | |||
) | |||
if err != nil { | |||
log.Errorf(ctx, "initVirtualDesc problem: %v\n%s", err, t.schema) |
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.
Do we need this extra here? Shouldn't the return err handle it, we can also wrap the error instead.
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.
The problem of not having this is that the error is eventually wrapped and manipulated later in the code. During my tests I end up having a bad create table that I was unable to find which definition until I did some debugging of the code.
I strongly recommend to leave that log, in a production environment I don't believe it gets printed.
pkg/sql/pg_catalog_test.go
Outdated
pgCatalogIDConstant = "PgCatalogID" | ||
tableIDSuffix = "TableID" | ||
tableDefsDeclaration = `tableDefs: map[descpb.ID]virtualSchemaDef{` | ||
tableDefsClosure = `},` |
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.
Rename to tableDefCloseBracket (not sure Closure is the right word 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.
I named it closure because I was thinking of the function "printsBeforeClosure" probably closure is not the right word,
What printsBeforeClosure does:
It will read and skips all the lines (Except comments) until find the "closure" line, then it will print the s text and the "closure" text.
Please let me know if you believe there is a better word for this.
6e056c1
to
eb82260
Compare
3be0a18
to
8cbb7e4
Compare
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mnovelodou, @rafiss, and @RichardJCai)
pkg/sql/pg_catalog_diff.go, line 191 at r4 (raw file):
} // getNotImplementedTables retrieves tables that are not yet part of crdb
Would like this comment to be more specific, I guess in this case it would be retrieves PGCatalog tables that are not yet part of CRDB.
Also in general comments should finished off with periods (valid sentences)
pkg/sql/pg_catalog_diff.go, line 202 at r4 (raw file):
} //AreAllTypesImplemented verifies that all the types are implemented in cockroach db
Missing space from comment to first word.
Also the function name should be updated in the comment.
pkg/sql/pg_catalog_test.go, line 72 at r5 (raw file):
Closure
I suggest we just name it tableDefCloseBracket
it's more clear in my opinion.
pkg/sql/pg_catalog_test.go, line 373 at r5 (raw file):
push back
Sure, I'm okay with leaving it if it is a big effort.
pkg/sql/virtual_schema.go, line 180 at r5 (raw file):
Previously, mnovelodou (Miguel Novelo) wrote…
The problem of not having this is that the error is eventually wrapped and manipulated later in the code. During my tests I end up having a bad create table that I was unable to find which definition until I did some debugging of the code.
I strongly recommend to leave that log, in a production environment I don't believe it gets printed.
Instead of logging here, would it be alright to wrap the returned error?
We can do errors.Wrapf(err, "initVirtualDesc problem: %s", t.schema)
If the returned error is unclear, I think we should make it clear instead of adding a log.
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss and @RichardJCai)
pkg/sql/pg_catalog_diff.go, line 191 at r4 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
Would like this comment to be more specific, I guess in this case it would be retrieves PGCatalog tables that are not yet part of CRDB.
Also in general comments should finished off with periods (valid sentences)
Done.
pkg/sql/pg_catalog_diff.go, line 202 at r4 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
Missing space from comment to first word.
Also the function name should be updated in the comment.
Done.
pkg/sql/pg_catalog_test.go, line 72 at r5 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
Closure
I suggest we just name it
tableDefCloseBracket
it's more clear in my opinion.
Done.
pkg/sql/pg_catalog_test.go, line 373 at r5 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
push back
Sure, I'm okay with leaving it if it is a big effort.
Done.
pkg/sql/virtual_schema.go, line 180 at r5 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
Instead of logging here, would it be alright to wrap the returned error?
We can doerrors.Wrapf(err, "initVirtualDesc problem: %s", t.schema)
If the returned error is unclear, I think we should make it clear instead of adding a log.
Done.
8cbb7e4
to
f3d4ad8
Compare
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mnovelodou, @rafiss, and @RichardJCai)
pkg/sql/pg_metadata_test.go, line 78 at r6 (raw file):
tableIDSuffix = "TableID" tableDefsDeclaration = `tableDefs: map[descpb.ID]virtualSchemaDef{` tableDefsCloseBracket = `},`
Maybe we should name this tableDefsTerminal
pkg/sql/pg_metadata_test.go, line 80 at r6 (raw file):
tableDefsCloseBracket = `},` allTableNamesDeclaration = `allTableNames: buildStringSet(` allTableNamesClose = `),`
allTablesNameTerminal
pkg/sql/pg_metadata_test.go, line 318 at r6 (raw file):
// printBeforeTerminalString will skip all the lines and print `s` text when finds the terminal string. func printBeforeTerminalString(
I realized both "TerminalStrings" are actually chars (just a close bracket) I think we can rename this to printBeforeTerminalChar
pkg/sql/pg_metadata_test.go, line 675 at r6 (raw file):
if *addMissingTables { notImplemented := diffs.getUnimplementedTables(pgTables)
notImplemented -> unimplemented
pkg/sql/virtual_schema.go, line 180 at r6 (raw file):
) if err != nil { err = errors.Wrapf(err, "initVirtualDesc problem: %v\n%s", err, t.schema)
I think this is wrapping the error twice. errors.Wrapf will wrap the error for you, so we don't need to pass the err the second time.
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss and @RichardJCai)
pkg/sql/pg_metadata_test.go, line 78 at r6 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
Maybe we should name this tableDefsTerminal
Done.
pkg/sql/pg_metadata_test.go, line 80 at r6 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
allTablesNameTerminal
Done.
pkg/sql/pg_metadata_test.go, line 318 at r6 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
I realized both "TerminalStrings" are actually chars (just a close bracket) I think we can rename this to
printBeforeTerminalChar
Not Really, tableDefsTerminal is ),
and all tableDefsTerminal is ),
(Both have commas) and they check the trimmed entire line (This is not looking at a single character).
If you look at the function this terminalString is compared with trimText which is a line read from the file without blank spaces at beginning and end of the string.
pkg/sql/pg_metadata_test.go, line 675 at r6 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
notImplemented -> unimplemented
Done.
pkg/sql/virtual_schema.go, line 180 at r6 (raw file):
Previously, RichardJCai (Richard Cai) wrote…
I think this is wrapping the error twice. errors.Wrapf will wrap the error for you, so we don't need to pass the err the second time.
Done.
Previously, programmer had to add missing table manually, This was inadequate because postgress added a lot of tables and manual process can lead to coding mistakes or gaps To address this, diff tool now have the hability to generate the missing code Release note: None Fixes cockroachdb#58001 Release justification: non-production code changes
f3d4ad8
to
25aeb98
Compare
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.
One thing I just realized is that the allTableNames
list for schema definitions is not actually the source of truth for what tables we implement. Ie we don't implement pg_sequence but it's listed there.
I think this is fine to merge as is since tables that appear in allTableNames
will return an unimplemented error if they're used and we already merged tables using this tool.
#61801 I opened an issue here.
What we can do to actually check which tables we implement is getting the tables using NewVirtualSchemaHolder
in virtual_schema.go. This way we can check what actually works.
Either way I'm okay with merging this and iterating since this solution implements the tables that we did not list in allTableNames
, we just have to change the soltuion to also add tables that we don't implement but also appear in allTableNames
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss and @RichardJCai)
bors r+ |
Build succeeded: |
Previously, programmer had to add missing table manually,
This was inadequate because postgress added a lot of tables and
manual process can lead to coding mistakes or gaps
To address this, diff tool now have the hability to generate the
missing code
Release note: None
Fixes #58001