【问题标题】:Can I use 0 and 1 values in quantilesExact我可以在 quantilesExact 中使用 0 和 1 值吗
【发布时间】:2020-01-17 09:19:00
【问题描述】:

来自quantile函数documentation

我们建议使用 [0.01, 0.99] 范围内的级别值。不要使用等于 0 或 1 的级别值 - 在这些情况下使用 min 和 max 函数。

这是否也适用于quantileExactquantilesExact 函数?

在我的实验中,我发现了quantileExact(0) = minquantileExact(1) = max,但不能确定。

【问题讨论】:

  • 主要适用于quantileExact和quantilesExact。 quantileExact(0) 总是 === min() 并且 quantileExact(1) = max
  • 可能在某些情况下 quantilesExact 会更快,例如你需要很多分位数Exact(0,.10,.20,.30,.40...1)

标签: clickhouse


【解决方案1】:

该建议不是关于准确性,而是关于分位数的复杂性*。 quantileExact 比 max min 重得多。 即使在小型数据集上,查看时间差,最小/最大速度也快 8 倍。

create table Speed Engine=MergeTree order by X  
as select number X from numbers(1000000000);

SELECT min(X), max(X) FROM Speed;
┌─min(X)─┬────max(X)─┐
│      0 │ 999999999 │
└────────┴───────────┘
1 rows in set. Elapsed: 1.040 sec. Processed 1.00 billion rows, 8.00 GB (961.32 million rows/s., 7.69 GB/s.)

SELECT quantileExact(0)(X), quantileExact(1)(X) FROM Speed;
┌─quantileExact(0)(X)─┬─quantileExact(1)(X)─┐
│                   0 │           999999999 │
└─────────────────────┴─────────────────────┘
1 rows in set. Elapsed: 8.561 sec. Processed 1.00 billion rows, 8.00 GB (116.80 million rows/s., 934.43 MB/s.) 

【讨论】:

    【解决方案2】:

    事实证明,对 quantileExactquantilesExact 函数使用 0 和 1 值是安全的。

    【讨论】:

      猜你喜欢
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 2017-11-20
      • 1970-01-01
      • 1970-01-01
      • 2011-02-16
      • 1970-01-01
      相关资源
      最近更新 更多