Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix
  • Loading branch information
cloud-fan committed Oct 23, 2019
commit 836e8689474a99ee51b63ca78088b618b64ec95d
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import org.apache.spark.sql.execution.vectorized.OnHeapColumnVector
import org.apache.spark.sql.internal.StaticSQLConf.SPARK_SESSION_EXTENSIONS
import org.apache.spark.sql.types.{DataType, Decimal, IntegerType, LongType, Metadata, StructType}
import org.apache.spark.sql.vectorized.{ColumnarArray, ColumnarBatch, ColumnarMap, ColumnVector}
import org.apache.spark.unsafe.types.{CalendarInterval, UTF8String}
import org.apache.spark.unsafe.types.UTF8String

/**
* Test cases for the [[SparkSessionExtensions]].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ object IntervalBenchmark extends SqlBasedBenchmark {
}
}

private def addCase(
benchmark: Benchmark,
cardinality: Long,
name: String,
exprs: Column*): Unit = {
benchmark.addCase(name, numIters = 3) { _ =>
doBenchmark(cardinality, exprs: _*)
}
}

private def buildString(withPrefix: Boolean, units: Seq[String] = Seq.empty): Column = {
val init = lit(if (withPrefix) "interval" else "") ::
($"id" % 10000).cast("string") ::
Expand All @@ -78,6 +88,9 @@ object IntervalBenchmark extends SqlBasedBenchmark {
val intervalToTest = ListBuffer[String]()

val benchmark = new Benchmark("cast strings to intervals", N, output = output)
// The first 2 cases are used to show the overhead of preparing the interval string.
addCase(benchmark, N, "prepare string w/ interval", buildString(true, timeUnits))
addCase(benchmark, N, "prepare string w/o interval", buildString(false, timeUnits))
addCase(benchmark, N, intervalToTest) // Only years

for (unit <- timeUnits) {
Expand Down