public static boolean shouldIgnoreStatistics(String createdBy, PrimitiveTypeName columnType) {

    if (columnType != PrimitiveTypeName.BINARY && columnType != PrimitiveTypeName.FIXED_LEN_BYTE_ARRAY) {
      // the bug only applies to binary columns
      return false;
    }

    if (Strings.isNullOrEmpty(createdBy)) {
      // created_by is not populated, which could have been caused by
      // parquet-mr during the same time as PARQUET-251, see PARQUET-297
      warnOnce("Ignoring statistics because created_by is null or empty! See PARQUET-251 and PARQUET-297");
      return true;
    }

    try {
      ParsedVersion version = VersionParser.parse(createdBy);

      if (!"parquet-mr".equals(version.application)) {
        // assume other applications don't have this bug
        return false;
      }

      if (Strings.isNullOrEmpty(version.version)) {
        warnOnce("Ignoring statistics because created_by did not contain a semver (see PARQUET-251): "
            + createdBy);
        return true;
      }

      SemanticVersion semver = SemanticVersion.parse(version.version);

      if (semver.compareTo(PARQUET_251_FIXED_VERSION) < 0
          && !(semver.compareTo(CDH_5_PARQUET_251_FIXED_START) >= 0
              && semver.compareTo(CDH_5_PARQUET_251_FIXED_END) < 0)) {
        warnOnce("Ignoring statistics because this file was created prior to "
            + PARQUET_251_FIXED_VERSION
            + ", see PARQUET-251");
        return true;
      }

      // this file was created after the fix
      return false;
    } catch (RuntimeException | SemanticVersionParseException | VersionParseException e) {
      // couldn't parse the created_by field, log what went wrong, don't trust the stats,
      // but don't make this fatal.
      warnParseErrorOnce(createdBy, e);
      return true;
    }
  }
@Test
  public void testCorruptStatistics() {
    assertTrue(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.6.0 (build abcd)", PrimitiveTypeName.BINARY));
    assertTrue(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.4.2 (build abcd)", PrimitiveTypeName.BINARY));
    assertTrue(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.6.100 (build abcd)", PrimitiveTypeName.BINARY));
    assertTrue(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.7.999 (build abcd)", PrimitiveTypeName.BINARY));
    assertTrue(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.6.22rc99 (build abcd)", PrimitiveTypeName.BINARY));
    assertTrue(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.6.22rc99-SNAPSHOT (build abcd)", PrimitiveTypeName.BINARY));
    assertTrue(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.6.1-SNAPSHOT (build abcd)", PrimitiveTypeName.BINARY));
    assertTrue(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.6.0t-01-abcdefg (build abcd)", PrimitiveTypeName.BINARY));

    assertTrue(CorruptStatistics.shouldIgnoreStatistics("unparseable string", PrimitiveTypeName.BINARY));

    // missing semver
    assertTrue(
        CorruptStatistics.shouldIgnoreStatistics("parquet-mr version (build abcd)", PrimitiveTypeName.BINARY));
    assertTrue(
        CorruptStatistics.shouldIgnoreStatistics("parquet-mr version  (build abcd)", PrimitiveTypeName.BINARY));

    // missing build hash
    assertTrue(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.6.0 (build )", PrimitiveTypeName.BINARY));
    assertTrue(
        CorruptStatistics.shouldIgnoreStatistics("parquet-mr version 1.6.0 (build)", PrimitiveTypeName.BINARY));
    assertTrue(CorruptStatistics.shouldIgnoreStatistics("parquet-mr version (build)", PrimitiveTypeName.BINARY));

    assertFalse(CorruptStatistics.shouldIgnoreStatistics(
        "imapla version 1.6.0 (build abcd)", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics(
        "imapla version 1.10.0 (build abcd)", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.8.0 (build abcd)", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.8.1 (build abcd)", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.8.1rc3 (build abcd)", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.8.1rc3-SNAPSHOT (build abcd)", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.9.0 (build abcd)", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 2.0.0 (build abcd)", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics(
        "parquet-mr version 1.9.0t-01-abcdefg (build abcd)", PrimitiveTypeName.BINARY));

    // missing semver
    assertFalse(CorruptStatistics.shouldIgnoreStatistics("impala version (build abcd)", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics("impala version  (build abcd)", PrimitiveTypeName.BINARY));

    // missing build hash
    assertFalse(
        CorruptStatistics.shouldIgnoreStatistics("impala version 1.6.0 (build )", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics("impala version 1.6.0 (build)", PrimitiveTypeName.BINARY));
    assertFalse(CorruptStatistics.shouldIgnoreStatistics("impala version (build)", PrimitiveTypeName.BINARY));
  }