Merge pull request #9692 from dataease/pr@dev-v2@fix_ds_count

fix(数据集): 修复数据集预览总数不正确的问题
This commit is contained in:
Junjun 2024-05-17 10:42:18 +08:00 committed by GitHub
commit e108dfc322
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -231,28 +231,32 @@ public class DatasetDataManage {
map.put("allFields", fieldList); map.put("allFields", fieldList);
} }
map.put("sql", Base64.getEncoder().encodeToString(querySQL.getBytes())); map.put("sql", Base64.getEncoder().encodeToString(querySQL.getBytes()));
map.put("total", getDatasetTotal(datasetGroupInfoDTO)); map.put("total", getDatasetTotal(datasetGroupInfoDTO, SqlUtils.rebuildSQL(SQLProvider.createQuerySQL(sqlMeta, false, false, needOrder), sqlMeta, crossDs, dsMap)));
return map; return map;
} }
public Long getDatasetTotal(Long datasetGroupId) throws Exception { public Long getDatasetTotal(Long datasetGroupId) throws Exception {
DatasetGroupInfoDTO dto = datasetGroupManage.getForCount(datasetGroupId); DatasetGroupInfoDTO dto = datasetGroupManage.getForCount(datasetGroupId);
if (StringUtils.equalsIgnoreCase(dto.getNodeType(), "dataset")) { if (StringUtils.equalsIgnoreCase(dto.getNodeType(), "dataset")) {
return getDatasetTotal(dto); return getDatasetTotal(dto, null);
} }
return 0L; return 0L;
} }
public Long getDatasetTotal(DatasetGroupInfoDTO datasetGroupInfoDTO) throws Exception { public Long getDatasetTotal(DatasetGroupInfoDTO datasetGroupInfoDTO, String s) throws Exception {
Map<String, Object> sqlMap = datasetSQLManage.getUnionSQLForEdit(datasetGroupInfoDTO, null); Map<String, Object> sqlMap = datasetSQLManage.getUnionSQLForEdit(datasetGroupInfoDTO, null);
String sql = (String) sqlMap.get("sql");
Map<Long, DatasourceSchemaDTO> dsMap = (Map<Long, DatasourceSchemaDTO>) sqlMap.get("dsMap"); Map<Long, DatasourceSchemaDTO> dsMap = (Map<Long, DatasourceSchemaDTO>) sqlMap.get("dsMap");
String sql;
if (StringUtils.isEmpty(s)) {
sql = (String) sqlMap.get("sql");
boolean crossDs = Utils.isCrossDs(dsMap); boolean crossDs = Utils.isCrossDs(dsMap);
if (!crossDs) { if (!crossDs) {
sql = Utils.replaceSchemaAlias(sql, dsMap); sql = Utils.replaceSchemaAlias(sql, dsMap);
} }
} else {
sql = s;
}
String querySQL = "SELECT COUNT(*) FROM (" + sql + ") t_a_0"; String querySQL = "SELECT COUNT(*) FROM (" + sql + ") t_a_0";
logger.info("calcite data count sql: " + querySQL); logger.info("calcite data count sql: " + querySQL);