SuKi2cn commented on code in PR #335:
URL: https://github.com/apache/iceberg-cpp/pull/335#discussion_r2556969603


##########
src/iceberg/expression/aggregate.cc:
##########
@@ -0,0 +1,256 @@
+/*
+ * 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 "iceberg/expression/aggregate.h"
+
+#include <format>
+#include <optional>
+#include <vector>
+
+#include "iceberg/exception.h"
+#include "iceberg/expression/binder.h"
+#include "iceberg/row/struct_like.h"
+#include "iceberg/type.h"
+#include "iceberg/util/checked_cast.h"
+#include "iceberg/util/macros.h"
+
+namespace iceberg {
+
+namespace {
+
+Result<std::shared_ptr<PrimitiveType>> GetPrimitiveType(const BoundTerm& term) 
{
+  auto primitive = std::dynamic_pointer_cast<PrimitiveType>(term.type());
+  if (primitive == nullptr) {
+    return InvalidExpression("Aggregate requires primitive type, got {}",
+                             term.type()->ToString());
+  }
+  return primitive;
+}
+
+}  // namespace
+
+// -------------------- Bound aggregates --------------------
+
+BoundCountAggregate::BoundCountAggregate(Expression::Operation op, Mode mode,
+                                         std::shared_ptr<BoundTerm> term)
+    : BoundAggregate(op, std::move(term)), mode_(mode) {}
+
+std::string BoundCountAggregate::ToString() const {
+  if (mode_ == Mode::kStar) {
+    return "count(*)";
+  }
+  ICEBERG_DCHECK(term() != nullptr, "Bound count aggregate should have term");
+  switch (mode_) {
+    case Mode::kNull:
+      return std::format("count_null({})", term()->reference()->name());
+    case Mode::kNonNull:
+      return std::format("count({})", term()->reference()->name());
+    case Mode::kStar:
+      break;
+  }
+  std::unreachable();
+}
+
+Result<Literal> BoundCountAggregate::Evaluate(const StructLike& data) const {

Review Comment:
   Thanks for bringing this up.
   
   Between the two options:
   - a single CountAggregate keeps the class count smaller but relies more 
heavily on branching based on `op()`, which can make the semantics harder to 
follow;
   - dedicated subclasses more closely match the Java design, improve semantic 
clarity, and reduce internal conditional logic.
   
   Given that there isn’t a compelling reason to deviate, I’ll align with the 
Java approach and refactor this into dedicated subclasses for CountNull, 
CountNotNull and CountStar.
   



-- 
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]

Reply via email to