list_sample.sql 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* yt can not */
  2. $list = ListFromRange(1, 101);
  3. $test = ($probability, $dependsOn) -> {
  4. $sample = ListCollect(ListSample($list, $probability, $dependsOn));
  5. RETURN
  6. (
  7. ListSort(DictKeys(ToSet($sample))) == ListSort($sample),
  8. (ListLength($sample), $probability * 100),
  9. SetIncludes(ToSet($list), $sample)
  10. );
  11. };
  12. SELECT
  13. ListSample(NULL , 1.0) IS NULL AS mustBeTrue1,
  14. ListSample(Nothing(OptionalType(ListType(DataType("Uint64")))), 1.0) IS NULL AS mustBeTrue2,
  15. ListSample([] , 1.0) == [] AS mustBeTrue3,
  16. ListSample($list, NULL ) == $list AS mustBeTrue4,
  17. ListSample($list, Nothing(OptionalType(DataType("Double")))) == $list AS mustBeTrue5,
  18. ListSample($list, 0.5, 123) == ListSample($list, 0.5, 123) AS mustBeTrue6,
  19. $test(0.2, 1) AS result1,
  20. $test(0.2, 2) AS result2,
  21. $test(0.2, 3) AS result3,
  22. $test(0.2, 4) AS result4,
  23. $test(0.2, 5) AS result5,
  24. $test(0.5, 6) AS result6,
  25. $test(0.8, 7) AS result7,
  26. $test(1.0, 8) AS result8,
  27. $test(0.0, 9) AS result9,
  28. ListSample($list , 0.1 , 10) AS result10,
  29. ListSample(Just($list), 0.1 , 11) AS result11,
  30. ListSample($list , Just(0.1), 12) AS result12,
  31. ListSample(Just($list), Just(0.1), 13) AS result13;