malinjawi commented on code in PR #13357:
URL: https://github.com/apache/gluten/pull/13357#discussion_r4361906182
##########
cpp/velox/compute/WholeStageResultIterator.cc:
##########
@@ -497,17 +499,26 @@ void WholeStageResultIterator::collectMetrics() {
customStats[customMetric.first] = folly::dynamic::object("sum",
customMetric.second.sum)(
"count", customMetric.second.count)("min",
customMetric.second.min)("max", customMetric.second.max);
}
+ // Rows processed per Delta counter function, keyed by its slot name.
Project and filter
+ // operators export these only when the plan calls a counter.
+ folly::dynamic expressionStats = folly::dynamic::object();
+ for (const auto& exprStats : opStats->expressionStats) {
+ if (isIncrementMetricFunction(exprStats.first)) {
+ expressionStats[exprStats.first] = exprStats.second.numProcessedRows;
+ }
+ }
- operatorStats.push_back(folly::dynamic::object("inputRows",
opStats->inputRows)(
- "inputVectors", opStats->inputVectors)("inputBytes",
opStats->inputBytes)(
- "rawInputRows", opStats->rawInputRows)("rawInputBytes",
opStats->rawInputBytes)(
- "outputRows", opStats->outputRows)("outputVectors",
opStats->outputVectors)(
- "outputBytes", opStats->outputBytes)("cpuCount",
opStats->cpuWallTiming.count)(
- "wallNanos", opStats->cpuWallTiming.wallNanos)("peakMemoryBytes",
opStats->peakMemoryBytes)(
- "numMemoryAllocations",
opStats->numMemoryAllocations)("spilledInputBytes", opStats->spilledInputBytes)(
- "spilledBytes", opStats->spilledBytes)("spilledRows",
opStats->spilledRows)(
- "spilledPartitions", opStats->spilledPartitions)("spilledFiles",
opStats->spilledFiles)(
- "physicalWrittenBytes",
opStats->physicalWrittenBytes)("customStats", customStats));
+ operatorStats.push_back(
+ folly::dynamic::object("inputRows",
opStats->inputRows)("inputVectors", opStats->inputVectors)(
+ "inputBytes", opStats->inputBytes)("rawInputRows",
opStats->rawInputRows)(
+ "rawInputBytes", opStats->rawInputBytes)("outputRows",
opStats->outputRows)(
+ "outputVectors", opStats->outputVectors)("outputBytes",
opStats->outputBytes)(
+ "cpuCount", opStats->cpuWallTiming.count)("wallNanos",
opStats->cpuWallTiming.wallNanos)(
+ "peakMemoryBytes",
opStats->peakMemoryBytes)("numMemoryAllocations",
opStats->numMemoryAllocations)(
+ "spilledInputBytes", opStats->spilledInputBytes)("spilledBytes",
opStats->spilledBytes)(
+ "spilledRows", opStats->spilledRows)("spilledPartitions",
opStats->spilledPartitions)(
+ "spilledFiles", opStats->spilledFiles)("physicalWrittenBytes",
opStats->physicalWrittenBytes)(
+ "customStats", customStats)("expressionStats", expressionStats));
Review Comment:
Good point. It's added only when the operator has counter stats now
(f5248ebfd), so other operators' JSON is unchanged. The JVM side already reads
a missing key as empty.
##########
cpp/velox/operators/functions/IncrementMetricFunction.cc:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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 "operators/functions/IncrementMetricFunction.h"
+
+#include <memory>
+#include <vector>
+
+#include "velox/core/Expressions.h"
+#include "velox/core/QueryConfig.h"
+#include "velox/expression/EvalCtx.h"
+#include "velox/expression/FunctionSignature.h"
+#include "velox/expression/VectorFunction.h"
+
+namespace gluten {
+namespace {
+
+using namespace facebook::velox;
+
+/// Returns its only argument. See the header for why the name, not the body,
carries the meaning.
+class IncrementMetricFunction : public exec::VectorFunction {
+ public:
+ void apply(
+ const SelectivityVector& rows,
+ std::vector<VectorPtr>& args,
+ const TypePtr& /*outputType*/,
+ exec::EvalCtx& context,
+ VectorPtr& result) const override {
+ VELOX_CHECK_EQ(args.size(), 1);
+ context.moveOrCopyResult(args[0], rows, result);
+ }
+};
+
+bool callsIncrementMetric(const core::ITypedExpr& expr) {
+ if (const auto* call = dynamic_cast<const core::CallTypedExpr*>(&expr)) {
+ if (isIncrementMetricFunction(call->name())) {
+ return true;
+ }
+ }
+ if (const auto* lambda = dynamic_cast<const core::LambdaTypedExpr*>(&expr)) {
+ return lambda->body() != nullptr && callsIncrementMetric(*lambda->body());
+ }
+ for (const auto& input : expr.inputs()) {
+ if (input != nullptr && callsIncrementMetric(*input)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+} // namespace
+
+std::string incrementMetricFunctionName(int32_t slot) {
+ return std::string(kIncrementMetricFunctionPrefix) + std::to_string(slot);
+}
+
+bool isIncrementMetricFunction(const std::string& functionName) {
+ return functionName.rfind(kIncrementMetricFunctionPrefix, 0) == 0;
+}
Review Comment:
Agreed, fixed in f5248ebfd: only increment_metric_0 to increment_metric_31
match now. The test covers empty, out-of-range, negative, leading-zero and
non-numeric names.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]