zhengruifeng opened a new pull request, #38917:
URL: https://github.com/apache/spark/pull/38917

   ### What changes were proposed in this pull request?
   correct the output column name of `groupBy.agg(count_distinct)`
   
   
   ### Why are the changes needed?
   
   before this PR: `[id: bigint, count(value): bigint]`
   
   ```
   scala> val df = spark.range(1, 10).withColumn("value", lit(1))
   df: org.apache.spark.sql.DataFrame = [id: bigint, value: int]
   
   scala> df.select(count_distinct($"value"))
   res0: org.apache.spark.sql.DataFrame = [count(DISTINCT value): bigint]
   
   scala> df.groupBy("id").agg(count_distinct($"value"))
   res1: org.apache.spark.sql.DataFrame = [id: bigint, count(value): bigint]
   
   scala> df.select(sum_distinct($"value"))
   res2: org.apache.spark.sql.DataFrame = [sum(DISTINCT value): bigint]
   
   scala> df.groupBy("id").agg(sum_distinct($"value"))
   res3: org.apache.spark.sql.DataFrame = [id: bigint, sum(DISTINCT value): 
bigint]
   
   scala> df.createOrReplaceTempView("table")
   
   scala> spark.sql(" SELECT id, COUNT(DISTINCT value) FROM table GROUP BY id ")
   res5: org.apache.spark.sql.DataFrame = [id: bigint, count(DISTINCT value): 
bigint]
   ```
   
   after this PR: `[id: bigint, count(DISTINCT value): bigint]`
   ```
   scala> val df = spark.range(1, 10).withColumn("value", lit(1))
   df: org.apache.spark.sql.DataFrame = [id: bigint, value: int]
   
   scala> df.select(count_distinct($"value"))
   res0: org.apache.spark.sql.DataFrame = [count(DISTINCT value): bigint]
   
   scala> df.groupBy("id").agg(count_distinct($"value"))
   res1: org.apache.spark.sql.DataFrame = [id: bigint, count(DISTINCT value): 
bigint]
   ```
   
   
   ### Does this PR introduce _any_ user-facing change?
   the default column name changed
   
   
   ### How was this patch tested?
   added UT


-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to