-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29518][SQL][TEST] Benchmark date_part for INTERVAL
#26175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,8 +61,10 @@ object ExtractBenchmark extends SqlBasedBenchmark { | |
| } | ||
|
|
||
| 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 "timestamp" => "cast(id as timestamp)" | ||
| case "date" => "cast(cast(id as timestamp) as date)" | ||
| case "interval" => "(cast(cast(id as timestamp) as date) - date'0001-01-01') + " + | ||
| "(cast(id as timestamp) - timestamp'1000-01-01 01:02:03.123456')" | ||
| case other => throw new IllegalArgumentException( | ||
| s"Unsupported column type $other. Valid column types are 'timestamp' and 'date'") | ||
| } | ||
|
|
@@ -74,8 +76,8 @@ object ExtractBenchmark extends SqlBasedBenchmark { | |
| 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 "extract" => s"EXTRACT($field FROM ${castExpr(from)}) AS $field" | ||
| case "date_part" => s"DATE_PART('$field', ${castExpr(from)}) AS $field" | ||
| case other => throw new IllegalArgumentException( | ||
| s"Unsupported function '$other'. Valid functions are 'extract' and 'date_part'.") | ||
| } | ||
|
|
@@ -84,24 +86,36 @@ object ExtractBenchmark extends SqlBasedBenchmark { | |
| } | ||
| } | ||
|
|
||
| private case class Settings(fields: Seq[String], func: Seq[String], iterNum: Long) | ||
|
|
||
| override def runBenchmarkSuite(mainArgs: Array[String]): Unit = { | ||
| val N = 10000000L | ||
| val fields = Seq( | ||
| val datetimeFields = Seq( | ||
| "MILLENNIUM", "CENTURY", "DECADE", "YEAR", | ||
| "ISOYEAR", "QUARTER", "MONTH", "WEEK", | ||
| "DAY", "DAYOFWEEK", "DOW", "ISODOW", | ||
| "DOY", "HOUR", "MINUTE", "SECOND", | ||
| "MILLISECONDS", "MICROSECONDS", "EPOCH") | ||
| val intervalFields = Seq( | ||
| "MILLENNIUM", "CENTURY", "DECADE", "YEAR", | ||
| "QUARTER", "MONTH", "DAY", | ||
| "HOUR", "MINUTE", "SECOND", | ||
| "MILLISECONDS", "MICROSECONDS", "EPOCH") | ||
| val settings = Map( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a big deal but
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? Could you clarify, please. Do you want to replace
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one? for {
(dataType, (fields, funcs, iterNum)) <- Map(
"timestamp" -> (datetimeFields, Seq("extract", "date_part"), N),
"date" -> (datetimeFields, Seq("extract", "date_part"), N),
"interval" -> (intervalFields, Seq("date_part"), N))
func <- funcs} {
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, I was thinking like that. I don't mind if you prefer the current way. no biggie. |
||
| "timestamp" -> Settings(datetimeFields, Seq("extract", "date_part"), N), | ||
| "date" -> Settings(datetimeFields, Seq("extract", "date_part"), N), | ||
| "interval" -> Settings(intervalFields, Seq("date_part"), N)) | ||
|
|
||
| for { | ||
| (dataType, Settings(fields, funcs, iterNum)) <- settings | ||
| func <- funcs} { | ||
|
|
||
| Seq("extract", "date_part").foreach { func => | ||
| Seq("timestamp", "date").foreach { dateType => | ||
| val benchmark = new Benchmark(s"Invoke $func for $dateType", N, output = output) | ||
| val benchmark = new Benchmark(s"Invoke $func for $dataType", N, output = output) | ||
|
|
||
| run(benchmark, N, s"cast to $dateType", castExpr(dateType)) | ||
| fields.foreach(run(benchmark, func, N, _, dateType)) | ||
| run(benchmark, iterNum, s"cast to $dataType", castExpr(dataType)) | ||
| fields.foreach(run(benchmark, func, iterNum, _, dataType)) | ||
|
|
||
| benchmark.run() | ||
| } | ||
| benchmark.run() | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why do we need to add alias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I debugged this, I showed dataframes to terminal. And printed tables were so wide.