xuchuanyin / workbench

0 stars 0 forks source link

2018-05-08 增加bloom_ffp #39

Open xuchuanyin opened 6 years ago

xuchuanyin commented 6 years ago
/**
   * validate bloom DataMap BLOOM_FFP
   * 1. BLOOM_FFP property is optional, 0.001 will be the default value.
   * 2. BLOOM_FFP should be (0, 1)
   */
  private double validateAndGetBloomFilterFfp(DataMapSchema dmSchema)
      throws MalformedDataMapCommandException {
    String bloomFilterFfpStr = dmSchema.getProperties().get(BLOOM_FFP);
    if (StringUtils.isBlank(bloomFilterFfpStr)) {
      LOGGER.warn(
          String.format("Bloom filter FFP is not configured for datamap %s, use default value %f",
              dataMapName, DEFAULT_BLOOM_FFP_VALUE));
      return DEFAULT_BLOOM_FFP_VALUE;
    }
    double bloomFilterFfp;
    try {
      bloomFilterFfp = Double.parseDouble(bloomFilterFfpStr);
    } catch (NumberFormatException e) {
      throw new MalformedDataMapCommandException(
          String.format("Invalid value of bloom filter ffp '%s', it should be an numeric",
              bloomFilterFfpStr));
    }
    if (bloomFilterFfp < 0 || bloomFilterFfp - 1 >= 0) {
      throw new MalformedDataMapCommandException(
          String.format("Invalid value of bloom filter ffp '%s', it should be in range 0~1",
              bloomFilterFfpStr));
    }
    return bloomFilterFfp;
  }