justinmclean opened a new issue, #10625:
URL: https://github.com/apache/gravitino/issues/10625

   ### What would you like to be improved?
   
   CustomStatistic.value() in StatisticManager.java (line 387) returns 
Optional.of(value). If a statistic entry has a null value, this throws a 
NullPointerException while reading partition statistics. That turns a missing 
statistic value into an unexpected runtime failure instead of an empty optional.
   
   ### How should we improve?
   
   Change the implementation to return Optional.ofNullable(value) so 
null-backed statistics are handled safely. It would also be worth adding a unit 
test covering a statistic with a null value to prevent regressions.
   
   Here's soem tests to help:
   ```
    @Test
     public void testCustomStatisticReturnsEmptyOptionalForNullValue() {
       StatisticManager.CustomStatistic statistic =
           new StatisticManager.CustomStatistic(
               "custom_test_stat", null, Mockito.mock(AuditInfo.class));
   
       Assertions.assertTrue(
           statistic.value().isEmpty(), "Null statistic values should be 
exposed as empty optional.");
     }
   
     @Test
     public void testPartitionStatisticNullValueReturnsEmptyOptional() {
       StatisticManager statisticManager = new StatisticManager(entityStore, 
idGenerator, config);
   
       MetadataObject tableObject =
           MetadataObjects.of(Lists.newArrayList(CATALOG, SCHEMA, TABLE), 
MetadataObject.Type.TABLE);
       Map<String, StatisticValue<?>> stats = Maps.newHashMap();
       stats.put("custom_null_stat", null);
   
       List<PartitionStatisticsUpdate> partitionStatistics = 
Lists.newArrayList();
       partitionStatistics.add(PartitionStatisticsModification.update("p_null", 
stats));
       statisticManager.updatePartitionStatistics(METALAKE, tableObject, 
partitionStatistics);
   
       List<PartitionStatistics> statistics =
           statisticManager.listPartitionStatistics(
               METALAKE,
               tableObject,
               PartitionRange.between(
                   "p_null",
                   PartitionRange.BoundType.CLOSED,
                   "p_null_next",
                   PartitionRange.BoundType.OPEN));
   
       Assertions.assertEquals(1, statistics.size());
       Assertions.assertEquals(1, statistics.get(0).statistics().length);
       Assertions.assertEquals("custom_null_stat", 
statistics.get(0).statistics()[0].name());
       Assertions.assertTrue(
           statistics.get(0).statistics()[0].value().isEmpty(),
           "Null persisted statistic values should be exposed as empty 
optional.");
     }
   ```


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to