Fixed#8064: Count API should support include filter (#8079)

* Fixed#8064: Count API should support include filter

* Fixed#8064: Count API should support include filter
This commit is contained in:
Parth Panchal 2022-10-11 16:51:54 +05:30 committed by GitHub
parent 6b31132ae1
commit cf28194e1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 41 deletions

View File

@ -3047,47 +3047,47 @@ public interface CollectionDAO {
interface UtilDAO {
@ConnectionAwareSqlQuery(
value =
"SELECT (SELECT COUNT(*) FROM table_entity) as tableCount, "
+ "(SELECT COUNT(*) FROM topic_entity) as topicCount, "
+ "(SELECT COUNT(*) FROM dashboard_entity) as dashboardCount, "
+ "(SELECT COUNT(*) FROM pipeline_entity) as pipelineCount, "
+ "(SELECT COUNT(*) FROM ml_model_entity) as mlmodelCount, "
+ "(SELECT (SELECT COUNT(*) FROM database_entity) + "
+ "(SELECT COUNT(*) FROM messaging_service_entity)+ "
+ "(SELECT COUNT(*) FROM dashboard_service_entity)+ "
+ "(SELECT COUNT(*) FROM pipeline_service_entity)+ "
+ "(SELECT COUNT(*) FROM mlmodel_service_entity)) as servicesCount, "
+ "(SELECT COUNT(*) FROM user_entity WHERE JSON_EXTRACT(json, '$.isBot') IS NULL OR JSON_EXTRACT(json, '$.isBot') = FALSE) as userCount, "
+ "(SELECT COUNT(*) FROM team_entity) as teamCount, "
+ "(SELECT COUNT(*) FROM test_suite) as testSuiteCount",
"SELECT (SELECT COUNT(*) FROM table_entity <cond>) as tableCount, "
+ "(SELECT COUNT(*) FROM topic_entity <cond>) as topicCount, "
+ "(SELECT COUNT(*) FROM dashboard_entity <cond>) as dashboardCount, "
+ "(SELECT COUNT(*) FROM pipeline_entity <cond>) as pipelineCount, "
+ "(SELECT COUNT(*) FROM ml_model_entity <cond>) as mlmodelCount, "
+ "(SELECT (SELECT COUNT(*) FROM database_entity <cond>) + "
+ "(SELECT COUNT(*) FROM messaging_service_entity <cond>)+ "
+ "(SELECT COUNT(*) FROM dashboard_service_entity <cond>)+ "
+ "(SELECT COUNT(*) FROM pipeline_service_entity <cond>)+ "
+ "(SELECT COUNT(*) FROM mlmodel_service_entity <cond>)) as servicesCount, "
+ "(SELECT COUNT(*) FROM user_entity <cond> AND (JSON_EXTRACT(json, '$.isBot') IS NULL OR JSON_EXTRACT(json, '$.isBot') = FALSE)) as userCount, "
+ "(SELECT COUNT(*) FROM team_entity <cond>) as teamCount, "
+ "(SELECT COUNT(*) FROM test_suite <cond>) as testSuiteCount",
connectionType = MYSQL)
@ConnectionAwareSqlQuery(
value =
"SELECT (SELECT COUNT(*) FROM table_entity) as tableCount, "
+ "(SELECT COUNT(*) FROM topic_entity) as topicCount, "
+ "(SELECT COUNT(*) FROM dashboard_entity) as dashboardCount, "
+ "(SELECT COUNT(*) FROM pipeline_entity) as pipelineCount, "
+ "(SELECT COUNT(*) FROM ml_model_entity) as mlmodelCount, "
+ "(SELECT (SELECT COUNT(*) FROM database_entity) + "
+ "(SELECT COUNT(*) FROM messaging_service_entity)+ "
+ "(SELECT COUNT(*) FROM dashboard_service_entity)+ "
+ "(SELECT COUNT(*) FROM pipeline_service_entity)+ "
+ "(SELECT COUNT(*) FROM mlmodel_service_entity)) as servicesCount, "
+ "(SELECT COUNT(*) FROM user_entity WHERE json#>'{isBot}' IS NULL OR ((json#>'{isBot}')::boolean) = FALSE) as userCount, "
+ "(SELECT COUNT(*) FROM team_entity) as teamCount, "
+ "(SELECT COUNT(*) FROM test_suite) as testSuiteCount",
"SELECT (SELECT COUNT(*) FROM table_entity <cond>) as tableCount, "
+ "(SELECT COUNT(*) FROM topic_entity <cond>) as topicCount, "
+ "(SELECT COUNT(*) FROM dashboard_entity <cond>) as dashboardCount, "
+ "(SELECT COUNT(*) FROM pipeline_entity <cond>) as pipelineCount, "
+ "(SELECT COUNT(*) FROM ml_model_entity <cond>) as mlmodelCount, "
+ "(SELECT (SELECT COUNT(*) FROM database_entity <cond>) + "
+ "(SELECT COUNT(*) FROM messaging_service_entity <cond>)+ "
+ "(SELECT COUNT(*) FROM dashboard_service_entity <cond>)+ "
+ "(SELECT COUNT(*) FROM pipeline_service_entity <cond>)+ "
+ "(SELECT COUNT(*) FROM mlmodel_service_entity <cond>)) as servicesCount, "
+ "(SELECT COUNT(*) FROM user_entity <cond> AND (json#>'{isBot}' IS NULL OR ((json#>'{isBot}')::boolean) = FALSE)) as userCount, "
+ "(SELECT COUNT(*) FROM team_entity <cond>) as teamCount, "
+ "(SELECT COUNT(*) FROM test_suite <cond> ) as testSuiteCount",
connectionType = POSTGRES)
@RegisterRowMapper(EntitiesCountRowMapper.class)
EntitiesCount getAggregatedEntitiesCount() throws StatementException;
EntitiesCount getAggregatedEntitiesCount(@Define("cond") String cond) throws StatementException;
@SqlQuery(
"SELECT (SELECT COUNT(*) FROM database_entity) as databaseServiceCount, "
+ "(SELECT COUNT(*) FROM messaging_service_entity) as messagingServiceCount, "
+ "(SELECT COUNT(*) FROM dashboard_service_entity) as dashboardServiceCount, "
+ "(SELECT COUNT(*) FROM pipeline_service_entity) as pipelineServiceCount, "
+ "(SELECT COUNT(*) FROM mlmodel_service_entity) as mlModelServiceCount")
"SELECT (SELECT COUNT(*) FROM database_entity <cond>) as databaseServiceCount, "
+ "(SELECT COUNT(*) FROM messaging_service_entity <cond>) as messagingServiceCount, "
+ "(SELECT COUNT(*) FROM dashboard_service_entity <cond>) as dashboardServiceCount, "
+ "(SELECT COUNT(*) FROM pipeline_service_entity <cond>) as pipelineServiceCount, "
+ "(SELECT COUNT(*) FROM mlmodel_service_entity <cond>) as mlModelServiceCount")
@RegisterRowMapper(ServicesCountRowMapper.class)
ServicesCount getAggregatedServicesCount() throws StatementException;
ServicesCount getAggregatedServicesCount(@Define("cond") String cond) throws StatementException;
}
class SettingsRowMapper implements RowMapper<Settings> {

View File

@ -10,11 +10,11 @@ public class UtilRepository {
this.dao = dao;
}
public EntitiesCount getAllEntitiesCount() {
return dao.getAggregatedEntitiesCount();
public EntitiesCount getAllEntitiesCount(ListFilter filter) {
return dao.getAggregatedEntitiesCount(filter.getCondition());
}
public ServicesCount getAllServicesCount() {
return dao.getAggregatedServicesCount();
public ServicesCount getAllServicesCount(ListFilter filter) {
return dao.getAggregatedServicesCount(filter.getCondition());
}
}

View File

@ -2,21 +2,26 @@ package org.openmetadata.service.resources.util;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import java.util.Objects;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import lombok.extern.slf4j.Slf4j;
import org.openmetadata.schema.type.Include;
import org.openmetadata.schema.util.EntitiesCount;
import org.openmetadata.schema.util.ServicesCount;
import org.openmetadata.service.jdbi3.CollectionDAO;
import org.openmetadata.service.jdbi3.ListFilter;
import org.openmetadata.service.jdbi3.UtilRepository;
import org.openmetadata.service.resources.Collection;
import org.openmetadata.service.security.Authorizer;
@ -51,8 +56,16 @@ public class UtilResource {
description = "List of Entities Count",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = EntitiesCount.class)))
})
public EntitiesCount listEntitiesCount(@Context UriInfo uriInfo) {
return utilRepository.getAllEntitiesCount();
public EntitiesCount listEntitiesCount(
@Context UriInfo uriInfo,
@Parameter(
description = "Include all, deleted, or non-deleted entities.",
schema = @Schema(implementation = Include.class))
@QueryParam("include")
@DefaultValue("non-deleted")
Include include) {
ListFilter filter = new ListFilter(include);
return utilRepository.getAllEntitiesCount(filter);
}
@GET
@ -68,7 +81,15 @@ public class UtilResource {
description = "List of Services Count",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ServicesCount.class)))
})
public ServicesCount listServicesCount(@Context UriInfo uriInfo) {
return utilRepository.getAllServicesCount();
public ServicesCount listServicesCount(
@Context UriInfo uriInfo,
@Parameter(
description = "Include all, deleted, or non-deleted entities.",
schema = @Schema(implementation = Include.class))
@QueryParam("include")
@DefaultValue("non-deleted")
Include include) {
ListFilter filter = new ListFilter(include);
return utilRepository.getAllServicesCount(filter);
}
}