Skip to content

Commit

Permalink
Modify PG SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
jerqi committed Sep 19, 2024
1 parent 0e6b040 commit 0a0d6b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,16 @@ public String listCombinedUserPOsByMetalakeId(@Param("metalakeId") Long metalake
+ " JSON_ARRAYAGG(rot.role_id) as roleIds"
+ " FROM "
+ USER_TABLE_NAME
+ " ut JOIN "
+ " ut LEFT OUTER JOIN "
+ USER_ROLE_RELATION_TABLE_NAME
+ " rt ON rt.user_id = ut.user_id"
+ " JOIN "
+ " LEFT OUTER JOIN "
+ ROLE_TABLE_NAME
+ " rot ON rot.role_id = rt.role_id"
+ " WHERE "
+ " ut.deleted_at = 0 AND rot.deleted_at = 0 AND rt.deleted_at = 0 AND ut.metalake_id = #{metalakeId}"
+ " ut.deleted_at = 0 AND"
+ " (rot.deleted_at = 0 OR rot.deleted_at is NULL) AND"
+ " (rt.deleted_at = 0 OR rt.deleted_at is NULL) AND ut.metalake_id = #{metalakeId}"
+ " GROUP BY ut.user_id";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.gravitino.storage.relational.mapper.postgresql;

import static org.apache.gravitino.storage.relational.mapper.RoleMetaMapper.ROLE_TABLE_NAME;
import static org.apache.gravitino.storage.relational.mapper.UserMetaMapper.USER_ROLE_RELATION_TABLE_NAME;
import static org.apache.gravitino.storage.relational.mapper.UserRoleRelMapper.USER_TABLE_NAME;

import org.apache.gravitino.storage.relational.mapper.UserMetaBaseSQLProvider;
Expand Down Expand Up @@ -66,4 +68,28 @@ public String insertUserMetaOnDuplicateKeyUpdate(UserPO userPO) {
+ " last_version = #{userMeta.lastVersion},"
+ " deleted_at = #{userMeta.deletedAt}";
}

@Override
public String listCombinedUserPOsByMetalakeId(Long metalakeId) {
return "SELECT ut.user_id as userId, ut.user_name as userName,"
+ " ut.metalake_id as metalakeId,"
+ " ut.audit_info as auditInfo,"
+ " ut.current_version as currentVersion, ut.last_version as lastVersion,"
+ " ut.deleted_at as deletedAt,"
+ " JSON_AGG(rot.role_name) as roleNames,"
+ " JSON_AGG(rot.role_id) as roleIds"
+ " FROM "
+ USER_TABLE_NAME
+ " ut LEFT OUTER JOIN "
+ USER_ROLE_RELATION_TABLE_NAME
+ " rt ON rt.user_id = ut.user_id"
+ " LEFT OUTER JOIN "
+ ROLE_TABLE_NAME
+ " rot ON rot.role_id = rt.role_id"
+ " WHERE "
+ " ut.deleted_at = 0 AND"
+ " (rot.deleted_at = 0 OR rot.deleted_at is NULL) AND"
+ " (rt.deleted_at = 0 OR rt.deleted_at is NULL) AND ut.metalake_id = #{metalakeId}"
+ " GROUP BY ut.user_id";
}
}

0 comments on commit 0a0d6b3

Please sign in to comment.