Skip to content

Commit

Permalink
Add aclexplode function json
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunlol committed Jan 9, 2025
1 parent 8612ba4 commit 6278ad8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/parser_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ func (parser *ParserFunction) RemapArrayToString(functionCall *pgQuery.FuncCall)
return functionCall
}

// aclexplode() -> json()
func (parser *ParserFunction) RemapAclExplode(functionCall *pgQuery.FuncCall) *pgQuery.FuncCall {
functionCall.Funcname = []*pgQuery.Node{pgQuery.MakeStrNode("json")}
return functionCall
}

func (parser *ParserFunction) OverrideFunctionCallArg(functionCall *pgQuery.FuncCall, index int, node *pgQuery.Node) {
functionCall.Args[index] = node
}
1 change: 1 addition & 0 deletions src/pg_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
PG_FUNCTION_QUOTE_INDENT = "quote_ident"
PG_FUNCTION_ROW_TO_JSON = "row_to_json"
PG_FUNCTION_SET_CONFIG = "set_config"
PG_FUNCTION_ACLEXPLODE = "aclexplode"

PG_TABLE_PG_AUTH_MEMBERS = "pg_auth_members"
PG_TABLE_PG_CLASS = "pg_class"
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 @@ -107,6 +107,11 @@ func TestHandleQuery(t *testing.T) {
"types": {Uint32ToString(pgtype.TextOID)},
"values": {""},
},
"SELECT (d).grantee AS grantee, (d).grantor AS grantor, (d).is_grantable AS is_grantable, (d).privilege_type AS privilege_type FROM (SELECT pg_catalog.aclexplode(db.datacl) AS d FROM pg_catalog.pg_database db WHERE db.oid = 16388::OID) a": {
"description": {"grantee", "grantor", "is_grantable", "privilege_type"},
"types": {Uint32ToString(pgtype.TextOID), Uint32ToString(pgtype.TextOID), Uint32ToString(pgtype.TextOID), Uint32ToString(pgtype.TextOID)},
"values": {"", "", "", ""},
},

// PG system tables
"SELECT oid, typname AS typename FROM pg_type WHERE typname='geometry' OR typname='geography'": {
Expand Down
4 changes: 4 additions & 0 deletions src/query_remapper_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func (remapper *QueryRemapperSelect) remappedFunctionName(functionCall *pgQuery.
case schemaFunction.Function == PG_FUNCTION_ROW_TO_JSON:
return remapper.parserFunction.RemapRowToJson(functionCall)

// aclexplode(acl) -> json
case schemaFunction.Function == PG_FUNCTION_ACLEXPLODE:
return remapper.parserFunction.RemapAclExplode(functionCall)

default:
return nil
}
Expand Down

0 comments on commit 6278ad8

Please sign in to comment.