Skip to content

Commit

Permalink
Slow query repair (#672)
Browse files Browse the repository at this point in the history
Co-authored-by: “v_kkhuang” <“[email protected]”>
  • Loading branch information
v-kkhuang and “v_kkhuang” authored Dec 13, 2024
1 parent 46a1d1d commit af0b5e4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ List<String> getDbsByUserAndRoles(
*/
List<String> getAllDbs();

List<Map<String, Object>> getTablesByDbNameAndUserAndRoles(MetadataQueryParam queryParam);
List<Map<String, Object>> getTablesByDbNameAndUserAndRolesFromDbPrvs(
MetadataQueryParam queryParam);

List<Map<String, Object>> getTablesByDbNameAndUserAndRolesFromTblPrvs(
MetadataQueryParam queryParam);

List<Map<String, Object>> getTablesByDbName(MetadataQueryParam queryParam);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.fasterxml.jackson.databind.JsonNode;
import org.slf4j.Logger;
Expand Down Expand Up @@ -100,7 +101,13 @@ public List<Map<String, Object>> getTablesByDbNameAndOptionalUserName(
if (flag) {
List<String> roles = hiveMetaDao.getRolesByUser(queryParam.getUserName());
queryParam.withRoles(roles);
return hiveMetaDao.getTablesByDbNameAndUserAndRoles(queryParam);
List<Map<String, Object>> hiveTables =
hiveMetaDao.getTablesByDbNameAndUserAndRolesFromDbPrvs(queryParam);
hiveTables.addAll(
hiveMetaDao.getTablesByDbNameAndUserAndRolesFromTblPrvs(queryParam));
return hiveTables.stream()
.distinct()
.collect(Collectors.toList());
} else {
log.info("user {} to getTablesByDbName no permission control", queryParam.getUserName());
return hiveMetaDao.getTablesByDbName(queryParam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
GROUP BY NAME
order by NAME
</select>
<select id="getTablesByDbNameAndUserAndRoles" resultType="map" parameterType="map">
<select id="getTablesByDbNameAndUserAndRolesFromDbPrvs" resultType="map" parameterType="map">
select t2.TBL_NAME as NAME, t2.TBL_TYPE as TYPE, t2.CREATE_TIME as CREATE_TIME, t2.LAST_ACCESS_TIME as LAST_ACCESS_TIME, t2.OWNER as OWNER
from DB_PRIVS t1
inner join TBLS t2 on t1.DB_ID = t2.DB_ID and t1.DB_PRIV in ('SELECT','ALL')
Expand All @@ -110,7 +110,9 @@
#{id}
</foreach>)
</if>
union
order by NAME;
</select>
<select id="getTablesByDbNameAndUserAndRolesFromTblPrvs" resultType="map" parameterType="map">
select t2.TBL_NAME as NAME, t2.TBL_TYPE as TYPE, t2.CREATE_TIME as CREATE_TIME, t2.LAST_ACCESS_TIME as LAST_ACCESS_TIME, t2.OWNER as OWNER
from TBL_PRIVS t1
inner join TBLS t2 on t1.TBL_ID=t2.TBL_ID and t1.TBL_PRIV in ('SELECT','ALL')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public void getTablesByDbNameAndUserAndRolesTest() {
queryParam.setDbName("default");
queryParam.setTableName("employee");
queryParam.setUserName("admin");
List<Map<String, Object>> tables = hiveMetaDao.getTablesByDbNameAndUserAndRoles(queryParam);
List<Map<String, Object>> tables =
hiveMetaDao.getTablesByDbNameAndUserAndRolesFromDbPrvs(queryParam);
Assertions.assertTrue(tables.size() == 0);
}

Expand Down

0 comments on commit af0b5e4

Please sign in to comment.