aucahuasi commented on a change in pull request #11257:
URL: https://github.com/apache/arrow/pull/11257#discussion_r718538630
##########
File path: cpp/src/arrow/compute/kernels/aggregate_test.cc
##########
@@ -873,6 +873,65 @@ TYPED_TEST(TestRandomNumericCountKernel, RandomArrayCount)
{
}
}
+//
+// Count Distinct
+//
+
+class TestCountDistinctKernel : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ only_valid = CountOptions(CountOptions::ONLY_VALID);
+ only_null = CountOptions(CountOptions::ONLY_NULL);
+ all = CountOptions(CountOptions::ALL);
+ }
+
+ const Datum& expected(int64_t value) {
+ expected_values[value] = Datum(static_cast<int64_t>(value));
+ return expected_values.at(value);
+ }
+
+ CountOptions only_valid;
+ CountOptions only_null;
+ CountOptions all;
+
+ private:
+ std::map<int64_t, Datum> expected_values;
+};
+
+TEST_F(TestCountDistinctKernel, NumericArrowTypesWithNulls) {
+ auto sample = "[1, 1, 2, 2, 5, 8, 9, 9, 9, 10, 6, 6]";
+ auto sample_nulls = "[null, 8, null, null, 6, null, 8]";
+ for (auto ty : NumericTypes()) {
+ auto input = ArrayFromJSON(ty, sample);
+ CheckScalar("count_distinct", {input}, expected(7), &only_valid);
+ CheckScalar("count_distinct", {input}, expected(0), &only_null);
+ CheckScalar("count_distinct", {input}, expected(7), &all);
+ auto input_nulls = ArrayFromJSON(ty, sample_nulls);
+ CheckScalar("count_distinct", {input_nulls}, expected(2), &only_valid);
+ CheckScalar("count_distinct", {input_nulls}, expected(1), &only_null);
+ CheckScalar("count_distinct", {input_nulls}, expected(3), &all);
+ }
+}
+
+TEST_F(TestCountDistinctKernel, RandomValidsStdMap) {
+ UInt32Builder builder;
+ std::map<uint32_t, int64_t> hashmap;
Review comment:
Yes I was thinking about using a set too. That's better. Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]