-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add null checks in DruidSchema #6830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
234afd3
32c8475
de9711a
0d45ec5
00c1b37
92517fa
c6f0a69
8c6f2e6
0fa6861
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ | |
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| public class DruidSchemaTest extends CalciteTestBase | ||
| { | ||
|
|
@@ -237,4 +238,38 @@ 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> segmentMetadatas = schema.getSegmentMetadata(); | ||
| Set<DataSegment> segments = segmentMetadatas.keySet(); | ||
| Assert.assertEquals(segments.size(), 3); | ||
| // segments contains two segments with datasource "foo" and one with datasource "foo2" | ||
| // let's remove the only segment with datasource "foo2" | ||
| final DataSegment segmentToRemove = segments.stream().filter(segment -> segment.getDataSource().equals("foo2")).findFirst().orElse(null); | ||
| Assert.assertFalse(segmentToRemove == null); | ||
| schema.removeSegment(segmentToRemove); | ||
| schema.refreshSegments(segments); // can cause NPE without dataSourceSegments null check in DruidSchema#refreshSegmentsForDataSource | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unclear that we remove the only segment of 'foo2' datasource (and not a segment from
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, changed to get segment with datasource 'foo2' |
||
| segmentMetadatas = schema.getSegmentMetadata(); | ||
| segments = segmentMetadatas.keySet(); | ||
| Assert.assertEquals(segments.size(), 2); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNullSegmentMetadataHolder() throws IOException | ||
| { | ||
| Map<DataSegment, SegmentMetadataHolder> segmentMetadatas = schema.getSegmentMetadata(); | ||
| Set<DataSegment> segments = segmentMetadatas.keySet(); | ||
| Assert.assertEquals(segments.size(), 3); | ||
| //remove one of the segments with datasource "foo" | ||
| final DataSegment segmentToRemove = segments.stream().filter(segment -> segment.getDataSource().equals("foo")).findFirst().orElse(null); | ||
| Assert.assertFalse(segmentToRemove == null); | ||
| schema.removeSegment(segmentToRemove); | ||
| schema.refreshSegments(segments); // can cause NPE without holder null check in SegmentMetadataHolder#from | ||
| segmentMetadatas = schema.getSegmentMetadata(); | ||
| segments = segmentMetadatas.keySet(); | ||
| Assert.assertEquals(segments.size(), 2); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
@VisibleForTestingto newly exposed methods.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, forgot to add. Will do.