Skip to content

Commit

Permalink
Allow combination expression remaps
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunlol committed Dec 20, 2024
1 parent 85474c2 commit f1074a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ func TestHandleQuery(t *testing.T) {
"description": {"type"},
"values": {""},
},
"SELECT roles.oid AS id, roles.rolname AS name, roles.rolsuper AS is_superuser, CASE WHEN roles.rolsuper THEN true ELSE false END AS can_create_role FROM pg_catalog.pg_roles roles WHERE rolname = current_user": {
"description": {"id", "name", "is_superuser", "can_create_role"},
"values": {},
},
// WHERE pg functions
"SELECT gss_authenticated, encrypted FROM (SELECT false, false, false, false, false WHERE false) t(pid, gss_authenticated, principal, encrypted, credentials_delegated) WHERE pid = pg_backend_pid()": {
"description": {"gss_authenticated", "encrypted"},
Expand Down
12 changes: 1 addition & 11 deletions src/select_remapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (selectRemapper *SelectRemapper) remapSelectStatement(selectStatement *pgQu
// CASE
if hasCaseExpr := selectRemapper.hasCaseExpressions(selectStatement); hasCaseExpr {
selectRemapper.traceTreeTraversal("CASE expressions", indentLevel)
return selectRemapper.remapCaseExpressions(selectStatement, indentLevel)
selectRemapper.remapCaseExpressions(selectStatement, indentLevel)
}

// UNION
Expand All @@ -74,16 +74,11 @@ func (selectRemapper *SelectRemapper) remapSelectStatement(selectStatement *pgQu
selectRemapper.traceTreeTraversal("UNION right", indentLevel)
rightSelectStatement := selectStatement.Rarg
rightSelectStatement = selectRemapper.remapSelectStatement(rightSelectStatement, indentLevel+1) // self-recursion

return selectStatement
}

// JOIN
if len(selectStatement.FromClause) > 0 && selectStatement.FromClause[0].GetJoinExpr() != nil {
// SELECT
selectStatement = selectRemapper.remapSelect(selectStatement, indentLevel) // recursive
selectStatement.FromClause[0] = selectRemapper.remapJoinExpressions(selectStatement, selectStatement.FromClause[0], indentLevel+1) // recursive with self-recursion
return selectStatement
}

// WHERE
Expand All @@ -93,10 +88,6 @@ func (selectRemapper *SelectRemapper) remapSelectStatement(selectStatement *pgQu

// FROM
if len(selectStatement.FromClause) > 0 {
// SELECT
selectStatement = selectRemapper.remapSelect(selectStatement, indentLevel) // recursive

// FROM
for i, fromNode := range selectStatement.FromClause {
if fromNode.GetRangeVar() != nil {
// WHERE
Expand All @@ -118,7 +109,6 @@ func (selectRemapper *SelectRemapper) remapSelectStatement(selectStatement *pgQu
selectStatement.FromClause[i] = selectRemapper.remapTableFunction(fromNode, indentLevel+1) // recursive
}
}
return selectStatement
}

selectStatement = selectRemapper.remapSelect(selectStatement, indentLevel) // recursive
Expand Down

0 comments on commit f1074a2

Please sign in to comment.