cloud-fan commented on a change in pull request #30745:
URL: https://github.com/apache/spark/pull/30745#discussion_r583661646



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/ProductAggSuite.scala
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.spark.sql
+
+import org.apache.spark.sql.expressions.Window
+import org.apache.spark.sql.functions.{ col, lit, product }
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types.{ByteType, DoubleType, FloatType, 
IntegerType, ShortType}
+
+
+class ProductAggSuite extends QueryTest with SharedSparkSession {
+  // Sequence of integers small enough that factorial is representable exactly 
as DoubleType:
+  private lazy val data16 = spark.range(1, 17).toDF("x")
+
+  private lazy val factorials = (1 to 16).scanLeft(1L) { case (f, x) => f * x }
+
+  test("bare factorial") {
+    implicit val enc = Encoders.scalaDouble
+
+    val prod = data16.agg(product(col("x"))).as[Double].head
+    val expected = (1L to 16L).reduce { _ * _ }.toDouble
+
+    assert(prod === expected)
+    assert(prod === factorials(16))
+  }
+
+  test("type flexibility") {
+    val bytes16 = spark.createDataset((1 to 16).map { _.toByte 
})(Encoders.scalaByte).toDF("x")

Review comment:
       It's not only about risk, but also about having a consistent code style 
for writing tests in Spark. If another people is trying to add a new agg 
function as you did, and sees this test suite,he/she may follow it to write a 
new test suite, which is unexpected.
   
   If you don't have time to do this, please create a JIRA ticket for rewriting 
this test suite, add a TODO with the JIRA ID here, so that other people won't 
follow it to write tests.




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

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