Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-37138][SQL] Support ANSI Interval types in ApproxCountDistinct…
…ForIntervals/ApproximatePercentile/Percentile ### What changes were proposed in this pull request? Support Ansi Interval types in the agg expressions: - ApproxCountDistinctForIntervals - ApproximatePercentile - Percentile ### Why are the changes needed? To improve user experience with Spark SQL. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Added new UT. Closes #34412 from AngersZhuuuu/SPARK-37138. Authored-by: Angerszhuuuu <angers.zhu@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
- Loading branch information
1 parent
b0548c6
commit 08123a3
Showing
8 changed files
with
153 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
sql/core/src/test/scala/org/apache/spark/sql/PercentileQuerySuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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 java.time.{Duration, Period} | ||
|
||
import org.apache.spark.sql.test.SharedSparkSession | ||
|
||
/** | ||
* End-to-end tests for percentile aggregate function. | ||
*/ | ||
class PercentileQuerySuite extends QueryTest with SharedSparkSession { | ||
import testImplicits._ | ||
|
||
private val table = "percentile_test" | ||
|
||
test("SPARK-37138: Support Ansi Interval type in Percentile") { | ||
withTempView(table) { | ||
Seq((Period.ofMonths(100), Duration.ofSeconds(100L)), | ||
(Period.ofMonths(200), Duration.ofSeconds(200L)), | ||
(Period.ofMonths(300), Duration.ofSeconds(300L))) | ||
.toDF("col1", "col2").createOrReplaceTempView(table) | ||
checkAnswer( | ||
spark.sql( | ||
s"""SELECT | ||
| CAST(percentile(col1, 0.5) AS STRING), | ||
| SUM(null), | ||
| CAST(percentile(col2, 0.5) AS STRING) | ||
|FROM $table | ||
""".stripMargin), | ||
Row("200.0", null, "2.0E8")) | ||
} | ||
} | ||
} |