You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2019/04/12 16:21:51 UTC

[GitHub] [incubator-druid] leventov commented on a change in pull request #7425: Add is_overshadowed column to sys.segments table

leventov commented on a change in pull request #7425: Add is_overshadowed column to sys.segments table
URL: https://github.com/apache/incubator-druid/pull/7425#discussion_r274968520
 
 

 ##########
 File path: server/src/main/java/org/apache/druid/server/http/MetadataResource.java
 ##########
 @@ -171,26 +175,67 @@ public Response getDatabaseSegments(
         .stream()
         .flatMap(t -> t.getSegments().stream());
 
-    final Function<DataSegment, Iterable<ResourceAction>> raGenerator = segment -> Collections.singletonList(
-        AuthorizationUtils.DATASOURCE_READ_RA_GENERATOR.apply(segment.getDataSource()));
+    if (includeOvershadowedStatus != null) {
+      final Set<SegmentId> overshadowedSegments = findOvershadowedSegments(druidDataSources);
+      //transform DataSegment to SegmentWithOvershadowedStatus objects
+      final Stream<SegmentWithOvershadowedStatus> segmentsWithOvershadowedStatus = metadataSegments
+          .map(
+              segment -> new SegmentWithOvershadowedStatus(
+                  segment,
+                  overshadowedSegments.contains(segment.getId())
+              )).collect(Collectors.toList()).stream();
 
-    final Iterable<DataSegment> authorizedSegments =
-        AuthorizationUtils.filterAuthorizedResources(req, metadataSegments::iterator, raGenerator, authorizerMapper);
+      final Function<SegmentWithOvershadowedStatus, Iterable<ResourceAction>> raGenerator = segment -> Collections.singletonList(
+          AuthorizationUtils.DATASOURCE_READ_RA_GENERATOR.apply(segment.getDataSegment().getDataSource()));
 
-    final StreamingOutput stream = outputStream -> {
-      final JsonFactory jsonFactory = jsonMapper.getFactory();
-      try (final JsonGenerator jsonGenerator = jsonFactory.createGenerator(outputStream)) {
-        jsonGenerator.writeStartArray();
-        for (DataSegment ds : authorizedSegments) {
-          jsonGenerator.writeObject(ds);
-          jsonGenerator.flush();
-        }
-        jsonGenerator.writeEndArray();
-      }
-    };
+      final Iterable<SegmentWithOvershadowedStatus> authorizedSegments =
+          AuthorizationUtils.filterAuthorizedResources(
+              req,
+              segmentsWithOvershadowedStatus::iterator,
+              raGenerator,
+              authorizerMapper
+          );
+      Response.ResponseBuilder builder = Response.status(Response.Status.OK);
+      return builder.entity(authorizedSegments).build();
+    } else {
 
-    Response.ResponseBuilder builder = Response.status(Response.Status.OK);
-    return builder.entity(stream).build();
+      final Function<DataSegment, Iterable<ResourceAction>> raGenerator = segment -> Collections.singletonList(
+          AuthorizationUtils.DATASOURCE_READ_RA_GENERATOR.apply(segment.getDataSource()));
 
 Review comment:
   Not formatted properly

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org