egor-ryashin commented on a change in pull request #6830: Add null checks in 
DruidSchema
URL: https://github.com/apache/incubator-druid/pull/6830#discussion_r252761635
 
 

 ##########
 File path: 
sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidSchemaTest.java
 ##########
 @@ -237,4 +238,36 @@ public void testGetTableMapFoo2()
     Assert.assertEquals("m1", fields.get(2).getName());
     Assert.assertEquals(SqlTypeName.BIGINT, 
fields.get(2).getType().getSqlTypeName());
   }
+
+  @Test
+  public void testNullDatasource() throws IOException
+  {
+    Map<DataSegment, SegmentMetadataHolder> segmentsMetadata = 
schema.getSegmentMetadata();
+    Set<DataSegment> segments = segmentsMetadata.keySet();
+    Assert.assertEquals(segments.size(), 3);
+    final DataSegment segmentToRemove = 
segments.stream().findFirst().orElse(null);
+    Assert.assertFalse(segmentToRemove == null);
+    schema.removeSegment(segmentToRemove);
+    schema.refreshSegments(segments); // can cause NPE without 
dataSourceSegments null check in DruidSchema#refreshSegmentsForDataSource
 
 Review comment:
   It's unclear that we remove the only segment of 'foo2' datasource (and not a 
segment from `foo` datasource) as `getSegmentMetadata` returned Map doesn't 
guarantee order. Which means it's unclear if we test for `dataSourceSegments == 
null`

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


With regards,
Apache Git Services

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

Reply via email to