Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,33 @@ import org.apache.spark.sql.internal.SQLConf
*/
object CometDatetimeExpressionBenchmark extends CometBenchmarkBase {

def dateTruncExprBenchmark(values: Int, useDictionary: Boolean): Unit = {
def dateTruncExprBenchmark(values: Int): Unit = {
withTempPath { dir =>
withTempTable("parquetV1Table") {
prepareTable(
dir,
spark.sql(
s"select cast(timestamp_micros(cast(value/100000 as integer)) as date) as dt FROM $tbl"))
Seq("YEAR", "YYYY", "YY", "MON", "MONTH", "MM").foreach { level =>
val isDictionary = if (useDictionary) "(Dictionary)" else ""
val name = s"Date Truncate $isDictionary - $level"
Seq("YEAR", "MONTH").foreach { level =>
val name = s"Date Truncate - $level"
val query = s"select trunc(dt, '$level') from parquetV1Table"
runExpressionBenchmark(name, values, query)
}
}
}
}

def timestampTruncExprBenchmark(values: Int, useDictionary: Boolean): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are a lot of tests we could start removing this logic from too.

def timestampTruncExprBenchmark(values: Int): Unit = {
withTempPath { dir =>
withTempTable("parquetV1Table") {
prepareTable(
dir,
spark.sql(s"select timestamp_micros(cast(value/100000 as integer)) as ts FROM $tbl"))
Seq(
"YEAR",
"YYYY",
"YY",
"MON",
"MONTH",
"MM",
"DAY",
"DD",
"HOUR",
"MINUTE",
"SECOND",
"WEEK",
"QUARTER").foreach { level =>
val isDictionary = if (useDictionary) "(Dictionary)" else ""
val name = s"Timestamp Truncate $isDictionary - $level"
val query = s"select date_trunc('$level', ts) from parquetV1Table"
runExpressionBenchmark(name, values, query)
Seq("YEAR", "MONTH", "DAY", "HOUR", "MINUTE", "SECOND", "WEEK", "QUARTER").foreach {
level =>
val name = s"Timestamp Truncate - $level"
val query = s"select date_trunc('$level', ts) from parquetV1Table"
runExpressionBenchmark(name, values, query)
}
}
}
Expand All @@ -85,16 +71,10 @@ object CometDatetimeExpressionBenchmark extends CometBenchmarkBase {
"spark.sql.parquet.datetimeRebaseModeInWrite" -> "CORRECTED") {

runBenchmarkWithTable("DateTrunc", values) { v =>
dateTruncExprBenchmark(v, useDictionary = false)
}
runBenchmarkWithTable("DateTrunc (Dictionary)", values, useDictionary = true) { v =>
dateTruncExprBenchmark(v, useDictionary = true)
dateTruncExprBenchmark(v)
}
runBenchmarkWithTable("TimestampTrunc", values) { v =>
timestampTruncExprBenchmark(v, useDictionary = false)
}
runBenchmarkWithTable("TimestampTrunc (Dictionary)", values, useDictionary = true) { v =>
timestampTruncExprBenchmark(v, useDictionary = true)
timestampTruncExprBenchmark(v)
}
}
}
Expand Down