wwj6591812 commented on code in PR #5270:
URL: https://github.com/apache/paimon/pull/5270#discussion_r1992457682


##########
paimon-core/src/main/java/org/apache/paimon/table/source/DataSplit.java:
##########
@@ -141,6 +144,44 @@ public long mergedRowCount() {
         return partialMergedRowCount();
     }
 
+    public Object minValue(DataField dataField) {
+        Object minValue = null;
+        for (int i = 0; i < dataFiles().size(); i++) {

Review Comment:
   for (DataFileMeta dataFile : dataFiles)



##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/aggregate/AggFuncEvaluator.scala:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+package org.apache.paimon.spark.aggregate
+
+import org.apache.paimon.data.BinaryString
+import org.apache.paimon.predicate.CompareUtils
+import org.apache.paimon.spark.SparkTypeUtils
+import org.apache.paimon.table.source.DataSplit
+import org.apache.paimon.types.DataField
+
+import org.apache.spark.sql.types.{DataType, LongType}
+import org.apache.spark.unsafe.types.UTF8String
+
+trait AggFuncEvaluator[T] {
+  def update(dataSplit: DataSplit): Unit
+
+  def result(): T
+
+  def resultType: DataType
+
+  def prettyName: String
+}
+
+class CountStarEvaluator extends AggFuncEvaluator[Long] {
+  private var _result: Long = 0L
+
+  override def update(dataSplit: DataSplit): Unit = {
+    _result += dataSplit.mergedRowCount()
+  }
+
+  val a: Int = 1;
+  override def result(): Long = _result
+
+  override def resultType: DataType = LongType
+
+  override def prettyName: String = "count_star"
+}
+
+case class MinEvaluator(dataField: DataField) extends AggFuncEvaluator[Any] {
+  private var _result: Any = _
+
+  override def update(dataSplit: DataSplit): Unit = {

Review Comment:
   `val other = dataSplit.minValue(dataField)` could be written in line 59



##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/PaimonScanBuilder.scala:
##########
@@ -116,19 +115,26 @@ class PaimonScanBuilder(table: Table)
       val pushedPartitionPredicate = 
PredicateBuilder.and(pushedPaimonPredicates.toList.asJava)
       readBuilder.withFilter(pushedPartitionPredicate)
     }
-    val dataSplits =
+    val dataSplits = if 
(AggregatePushDownUtils.hasMinMaxAggregation(aggregation)) {
+      
readBuilder.newScan().plan().splits().asScala.map(_.asInstanceOf[DataSplit])
+    } else {
       
readBuilder.dropStats().newScan().plan().splits().asScala.map(_.asInstanceOf[DataSplit])
-    if (!dataSplits.forall(_.mergedRowCountAvailable())) {
-      return false
     }
-    dataSplits.foreach(aggregator.update)
-    localScan = Some(
-      PaimonLocalScan(
-        aggregator.result(),
-        aggregator.resultSchema(),
-        table,
-        pushedPaimonPredicates))
-    true
+    if (AggregatePushDownUtils.canPushdownAggregation(table, aggregation, 
dataSplits.toSeq)) {

Review Comment:
   remove `.toSeq`



##########
paimon-core/src/main/java/org/apache/paimon/table/source/DataSplit.java:
##########
@@ -141,6 +144,44 @@ public long mergedRowCount() {
         return partialMergedRowCount();
     }
 
+    public Object minValue(DataField dataField) {
+        Object minValue = null;
+        for (int i = 0; i < dataFiles().size(); i++) {
+            DataFileMeta dataFile = dataFiles.get(i);
+            Object other =
+                    InternalRowUtils.get(
+                            dataFile.valueStats().minValues(), dataField.id(), 
dataField.type());
+            if (minValue == null) {
+                minValue = other;
+            } else if (other != null) {
+                int cmp = CompareUtils.compareLiteral(dataField.type(), 
minValue, other);
+                if (cmp > 0) {
+                    minValue = other;
+                }
+            }
+        }
+        return minValue;
+    }
+
+    public Object maxValue(DataField dataField) {
+        Object maxValue = null;
+        for (int i = 0; i < dataFiles().size(); i++) {
+            DataFileMeta dataFile = dataFiles.get(i);
+            Object other =
+                    InternalRowUtils.get(
+                            dataFile.valueStats().maxValues(), dataField.id(), 
dataField.type());
+            if (maxValue == null) {
+                maxValue = other;
+            } else if (other != null) {
+                int cmp = CompareUtils.compareLiteral(dataField.type(), 
maxValue, other);
+                if (cmp < 0) {

Review Comment:
   if (CompareUtils.compareLiteral(dataField.type(), maxValue, other) < 0) {



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

Reply via email to