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: code generation for missing pg catalog tables #58519

Merged
merged 1 commit into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/sql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ go_test(
"@com_github_jackc_pgx//pgtype",
"@com_github_jackc_pgx_v4//:pgx",
"@com_github_lib_pq//:pq",
"@com_github_lib_pq//oid",
"@com_github_pmezard_go_difflib//difflib",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
Expand Down
30 changes: 29 additions & 1 deletion pkg/sql/pg_metadata_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"encoding/json"
"io"
"os"

"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/lib/pq/oid"
)

// GetPGMetadataSQL is a query uses udt_name::regtype instead of data_type column because
Expand Down Expand Up @@ -187,7 +190,8 @@ func (p PGMetadataTables) rewriteDiffs(diffFile string) error {
return nil
}

// Save have the purpose of storing all the data retrieved from postgres and useful information as postgres version
// Save have the purpose of storing all the data retrieved from postgres and
// useful information as postgres version.
func (f *PGMetadataFile) Save(writer io.Writer) {
byteArray, err := json.MarshalIndent(f, "", " ")
if err != nil {
Expand All @@ -198,3 +202,27 @@ func (f *PGMetadataFile) Save(writer io.Writer) {
panic(err)
}
}

//getUnimplementedTables retrieves the tables that are not yet part of CRDB.
func (p PGMetadataTables) getUnimplementedTables(source PGMetadataTables) PGMetadataTables {
notImplemented := make(PGMetadataTables)
for tableName := range p {
if len(p[tableName]) == 0 && len(source[tableName].getUnimplementedTypes()) == 0 {
notImplemented[tableName] = source[tableName]
}
}
return notImplemented
}

// getUnimplementedTypes verifies that all the types are implemented in cockroach db.
func (c PGMetadataColumns) getUnimplementedTypes() map[oid.Oid]string {
unimplemented := make(map[oid.Oid]string)
for _, column := range c {
typeOid := oid.Oid(column.Oid)
if _, ok := types.OidToType[typeOid]; !ok || typeOid == oid.T_anyarray {
unimplemented[typeOid] = column.DataType
}
}

return unimplemented
}
Loading