cloud-fan commented on a change in pull request #25772:
[SPARK-29065][SQL][TEST] Extend `EXTRACT` benchmark
URL: https://github.com/apache/spark/pull/25772#discussion_r323645259
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/ExtractBenchmark.scala
##########
@@ -48,35 +48,41 @@ object ExtractBenchmark extends SqlBasedBenchmark {
}
}
- private def run(cardinality: Long, field: String): Unit = {
- codegenBenchmark(s"$field of timestamp", cardinality) {
- doBenchmark(cardinality, s"EXTRACT($field FROM (cast(id as timestamp)))")
+ private def castExpr(from: String): String = from match {
+ case "timestamp" => s"cast(id as timestamp)"
+ case "date" => s"cast(cast(id as timestamp) as date)"
+ case other => throw new IllegalArgumentException(
+ s"Unsupported column type $other. Valid column types are 'timestamp' and
'date'")
+ }
+
+ private def run(func: String, cardinality: Long, field: String, from:
String): Unit = {
+ val expr = func match {
+ case "extract" => s"EXTRACT($field FROM ${castExpr(from)})"
+ case "date_part" => s"DATE_PART('$field', ${castExpr(from)})"
+ case other => throw new IllegalArgumentException(
+ s"Unsupported function '$other'. Valid functions are 'extract' and
'date_part'.")
+ }
+ codegenBenchmark(s"$field of $from", cardinality) {
Review comment:
Yea I know the code is same, but since we are refining this benchmark, we
can fix this issue as well.
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]