lidavidm commented on a change in pull request #11274:
URL: https://github.com/apache/arrow/pull/11274#discussion_r718824824
##########
File path: cpp/src/arrow/compute/exec/plan_test.cc
##########
@@ -664,6 +664,45 @@ TEST(ExecPlanExecution,
SourceFilterProjectGroupedSumOrderBy) {
}
}
+TEST(ExecPlanExecution, SourceFilterProjectGroupedSumTopK) {
+ for (bool parallel : {false, true}) {
+ SCOPED_TRACE(parallel ? "parallel/merged" : "serial");
+
+ int batch_multiplicity = parallel ? 100 : 1;
+ auto input = MakeGroupableBatches(/*multiplicity=*/batch_multiplicity);
+
+ ASSERT_OK_AND_ASSIGN(auto plan, ExecPlan::Make());
+ AsyncGenerator<util::optional<ExecBatch>> sink_gen;
+
+ SelectKOptions options = SelectKOptions::TopKDefault(/*k=*/2, {"str"});
+ ASSERT_OK(
+ Declaration::Sequence(
+ {
+ {"source",
+ SourceNodeOptions{input.schema, input.gen(parallel,
/*slow=*/false)}},
+ {"filter",
+ FilterNodeOptions{greater_equal(field_ref("i32"),
literal(0))}},
+ {"project", ProjectNodeOptions{{
+ field_ref("str"),
+ call("multiply", {field_ref("i32"),
literal(2)}),
+ }}},
+ {"aggregate",
AggregateNodeOptions{/*aggregates=*/{{"hash_sum", nullptr}},
+ /*targets=*/{"multiply(i32,
2)"},
+
/*names=*/{"sum(multiply(i32, 2))"},
+ /*keys=*/{"str"}}},
+ {"filter",
FilterNodeOptions{greater(field_ref("sum(multiply(i32, 2))"),
+ literal(10 *
batch_multiplicity))}},
+ {"select_k_sink", SelectKSinkNodeOptions{options, &sink_gen}},
+ })
+ .AddToPlan(plan.get()));
+
+ ASSERT_THAT(StartAndCollect(plan.get(), sink_gen),
+ Finishes(ResultWith(ElementsAreArray({ExecBatchFromJSON(
+ {int64(), utf8()}, parallel ? R"([[2000, "beta"], [3600,
"alfa"]])"
+ : R"([[20, "beta"], [36,
"alfa"]])")}))));
Review comment:
Given the results/pipeline are exactly the same as the test immediately
above, it's a little hard to be sure that the select_k worked as intended
(after all, in this case, an order by would give the exact same results). Maybe
we could remove the aggregate or a filter or something, so that it's clearer
that we are actually getting a TopK? Or change k to 1.
##########
File path: cpp/src/arrow/compute/exec/select_k.cc
##########
@@ -0,0 +1,74 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/compute/exec/select_k.h"
+
+#include <functional>
+#include <memory>
+#include <mutex>
+#include <vector>
+#include "arrow/compute/api_vector.h"
+#include "arrow/compute/exec/options.h"
+#include "arrow/record_batch.h"
+#include "arrow/result.h"
+#include "arrow/status.h"
+#include "arrow/table.h"
+#include "arrow/type.h"
+
+namespace arrow {
+namespace compute {
+
+class SelectKBasicImpl : public SelectKImpl {
Review comment:
Or really, looking at how similar the SelectK and OrderBy sink nodes
are, I wonder if the right strategy is to create a single sink node that can
then be templated on the final kernel to call, all in one file, if the worry is
code reuse. (After all, it seems the InputReceived implementation and
everything else is going to be essentially identical, while a streaming TopK is
going to necessarily be implemented entirely differently.)
##########
File path: cpp/src/arrow/compute/exec/select_k.cc
##########
@@ -0,0 +1,74 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/compute/exec/select_k.h"
+
+#include <functional>
+#include <memory>
+#include <mutex>
+#include <vector>
+#include "arrow/compute/api_vector.h"
+#include "arrow/compute/exec/options.h"
+#include "arrow/record_batch.h"
+#include "arrow/result.h"
+#include "arrow/status.h"
+#include "arrow/table.h"
+#include "arrow/type.h"
+
+namespace arrow {
+namespace compute {
+
+class SelectKBasicImpl : public SelectKImpl {
Review comment:
Is this really worth breaking out instead of inlining into the node
itself?
--
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]