public boolean validatePatternIfPresent(Retention retention, TableUri tableUri, String schema) {
    if (retention.getColumnPattern() != null) {
      if (retention.getColumnPattern().getColumnName() != null
          && !columnExists(
              getSchemaFromSchemaJson(schema), retention.getColumnPattern().getColumnName())) {
        return false;
      }
      return isPatternValid(retention.getColumnPattern().getPattern(), tableUri);
    }

    return true;
  }
@Test
  void testValidatePatternPositive() {

    // With pattern
    RetentionColumnPattern pattern =
        RetentionColumnPattern.builder().pattern("yyyy-mm-dd-hh").columnName("aa").build();
    Retention retention1 =
        Retention.builder()
            .columnPattern(pattern)
            .count(1)
            .granularity(TimePartitionSpec.Granularity.DAY)
            .build();

    Assertions.assertTrue(
        validator.validatePatternIfPresent(
            retention1, TableUri.builder().build(), getSchemaJsonFromSchema(dummySchema)));

    // Without Pattern
    Retention retention2 =
        Retention.builder()
            .columnPattern(null)
            .count(10)
            .granularity(TimePartitionSpec.Granularity.DAY)
            .build();
    Assertions.assertTrue(
        validator.validatePatternIfPresent(
            retention2, TableUri.builder().build(), getSchemaJsonFromSchema(dummySchema)));

    // Able to find nested columns in the column existence check
    pattern =
        RetentionColumnPattern.builder().pattern("yyyy-mm-dd-hh").columnName("top1.aa").build();
    Retention retention3 =
        Retention.builder()
            .columnPattern(pattern)
            .count(1)
            .granularity(TimePartitionSpec.Granularity.DAY)
            .build();
    Assertions.assertTrue(
        validator.validatePatternIfPresent(
            retention3, TableUri.builder().build(), getSchemaJsonFromSchema(nestedSchema)));

    // Empty pattern is valid
    pattern = RetentionColumnPattern.builder().pattern("").columnName("top1.aa").build();
    Retention retention4 =
        Retention.builder()
            .columnPattern(pattern)
            .count(1)
            .granularity(TimePartitionSpec.Granularity.DAY)
            .build();
    Assertions.assertTrue(
        validator.validatePatternIfPresent(
            retention4, TableUri.builder().build(), getSchemaJsonFromSchema(nestedSchema)));
  }