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

View File

@ -10,11 +10,11 @@ public class UtilRepository {
this.dao = dao; this.dao = dao;
} }
public EntitiesCount getAllEntitiesCount() { public EntitiesCount getAllEntitiesCount(ListFilter filter) {
return dao.getAggregatedEntitiesCount(); return dao.getAggregatedEntitiesCount(filter.getCondition());
} }
public ServicesCount getAllServicesCount() { public ServicesCount getAllServicesCount(ListFilter filter) {
return dao.getAggregatedServicesCount(); 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.annotations.Api;
import io.swagger.v3.oas.annotations.Operation; 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.Content;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import java.util.Objects; import java.util.Objects;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.openmetadata.schema.type.Include;
import org.openmetadata.schema.util.EntitiesCount; import org.openmetadata.schema.util.EntitiesCount;
import org.openmetadata.schema.util.ServicesCount; import org.openmetadata.schema.util.ServicesCount;
import org.openmetadata.service.jdbi3.CollectionDAO; import org.openmetadata.service.jdbi3.CollectionDAO;
import org.openmetadata.service.jdbi3.ListFilter;
import org.openmetadata.service.jdbi3.UtilRepository; import org.openmetadata.service.jdbi3.UtilRepository;
import org.openmetadata.service.resources.Collection; import org.openmetadata.service.resources.Collection;
import org.openmetadata.service.security.Authorizer; import org.openmetadata.service.security.Authorizer;
@ -51,8 +56,16 @@ public class UtilResource {
description = "List of Entities Count", description = "List of Entities Count",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = EntitiesCount.class))) content = @Content(mediaType = "application/json", schema = @Schema(implementation = EntitiesCount.class)))
}) })
public EntitiesCount listEntitiesCount(@Context UriInfo uriInfo) { public EntitiesCount listEntitiesCount(
return utilRepository.getAllEntitiesCount(); @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 @GET
@ -68,7 +81,15 @@ public class UtilResource {
description = "List of Services Count", description = "List of Services Count",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ServicesCount.class))) content = @Content(mediaType = "application/json", schema = @Schema(implementation = ServicesCount.class)))
}) })
public ServicesCount listServicesCount(@Context UriInfo uriInfo) { public ServicesCount listServicesCount(
return utilRepository.getAllServicesCount(); @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);
} }
} }