Skip to content

Commit

Permalink
Add support for pg_collation
Browse files Browse the repository at this point in the history
  • Loading branch information
exAspArk committed Feb 11, 2025
1 parent 345bcb1 commit 1610378
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/parser_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func (parser *ParserTable) MakePgExtensionNode(alias string) *pgQuery.Node {
return parser.utils.MakeSubselectWithRowsNode(PG_TABLE_PG_EXTENSION, tableDef, [][]string{tableDef.Values}, alias)
}

// pg_catalog.pg_collation -> VALUES(values...) t(columns...)
func (parser *ParserTable) MakePgCollationNode(alias string) *pgQuery.Node {
tableDef := PG_COLLATION_DEFINITION
return parser.utils.MakeSubselectWithRowsNode(PG_TABLE_PG_COLLATION, tableDef, [][]string{tableDef.Values}, alias)
}

// pg_catalog.pg_database -> VALUES(values...) t(columns...)
func (parser *ParserTable) MakePgDatabaseNode(database string, alias string) *pgQuery.Node {
tableDef := PG_DATABASE_DEFINITION
Expand Down
32 changes: 32 additions & 0 deletions src/pg_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
PG_TABLE_PG_ATTRIBUTE = "pg_attribute"
PG_TABLE_PG_AUTH_MEMBERS = "pg_auth_members"
PG_TABLE_PG_CLASS = "pg_class"
PG_TABLE_PG_COLLATION = "pg_collation"
PG_TABLE_PG_DATABASE = "pg_database"
PG_TABLE_PG_EXTENSION = "pg_extension"
PG_TABLE_PG_INHERITS = "pg_inherits"
Expand Down Expand Up @@ -252,6 +253,37 @@ var PG_EXTENSION_DEFINITION = TableDefinition{
},
}

var PG_COLLATION_DEFINITION = TableDefinition{
Columns: []ColumnDefinition{
{"oid", "oid"},
{"collname", "text"},
{"collnamespace", "oid"},
{"collowner", "oid"},
{"collprovider", "text"},
{"collisdeterministic", "bool"},
{"collencoding", "int4"},
{"collcollate", "text"},
{"collctype", "text"},
{"colliculocale", "text"},
{"collicurules", "text"},
{"collversion", "text"},
},
Values: []string{
"100",
"default",
"11",
"10",
"d",
"TRUE",
"-1",
"NULL",
"NULL",
"NULL",
"NULL",
"NULL",
},
}

var PG_STAT_USER_TABLES_DEFINITION = TableDefinition{
Columns: []ColumnDefinition{
{"relid", "oid"},
Expand Down
5 changes: 5 additions & 0 deletions src/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ func TestHandleQuery(t *testing.T) {
"description": {"schemaname", "viewname", "viewowner", "definition"},
"types": {Uint32ToString(pgtype.TextOID), Uint32ToString(pgtype.TextOID), Uint32ToString(pgtype.TextOID), Uint32ToString(pgtype.TextOID)},
},
"SELECT oid FROM pg_collation": {
"description": {"oid"},
"types": {Uint32ToString(pgtype.OIDOID)},
"values": {"100"},
},
"SELECT schemaname, relname, n_live_tup FROM pg_stat_user_tables": {
"description": {"schemaname", "relname", "n_live_tup"},
"types": {Uint32ToString(pgtype.TextOID), Uint32ToString(pgtype.TextOID), Uint32ToString(pgtype.Int8OID)},
Expand Down
4 changes: 4 additions & 0 deletions src/query_remapper_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func (remapper *QueryRemapperTable) RemapTable(node *pgQuery.Node) *pgQuery.Node
case PG_TABLE_PG_STAT_USER_TABLES:
return parser.MakePgStatUserTablesNode(remapper.icebergSchemaTables, qSchemaTable.Alias)

// pg_collation -> return hard-coded collation (encoding) info
case PG_TABLE_PG_COLLATION:
return parser.MakePgCollationNode(qSchemaTable.Alias)

// pg_catalog.pg_* other system tables -> return as is
default:
return node
Expand Down

0 comments on commit 1610378

Please sign in to comment.