-
Notifications
You must be signed in to change notification settings - Fork 237
/
Plugin.scala
506 lines (448 loc) · 21.3 KB
/
Plugin.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
/*
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
*
* Licensed 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 com.nvidia.spark.rapids
import java.time.ZoneId
import java.util.Properties
import java.util.concurrent.atomic.{AtomicBoolean, AtomicReference}
import scala.collection.JavaConverters._
import scala.collection.mutable.{Map => MutableMap}
import scala.util.Try
import scala.util.matching.Regex
import ai.rapids.cudf.{CudaException, CudaFatalException, CudfException, MemoryCleaner}
import com.nvidia.spark.rapids.python.PythonWorkerSemaphore
import org.apache.spark.{ExceptionFailure, SparkConf, SparkContext, TaskFailedReason}
import org.apache.spark.api.plugin.{DriverPlugin, ExecutorPlugin, PluginContext}
import org.apache.spark.internal.Logging
import org.apache.spark.serializer.{JavaSerializer, KryoSerializer}
import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.catalyst.expressions.Expression
import org.apache.spark.sql.catalyst.rules.Rule
import org.apache.spark.sql.execution._
import org.apache.spark.sql.execution.adaptive.{AdaptiveSparkPlanExec, QueryStageExec}
import org.apache.spark.sql.execution.exchange.ReusedExchangeExec
import org.apache.spark.sql.internal.StaticSQLConf
import org.apache.spark.sql.rapids.GpuShuffleEnv
import org.apache.spark.sql.rapids.execution.TrampolineUtil
import org.apache.spark.sql.util.QueryExecutionListener
class PluginException(msg: String) extends RuntimeException(msg)
case class CudfVersionMismatchException(errorMsg: String) extends PluginException(errorMsg)
case class ColumnarOverrideRules() extends ColumnarRule with Logging {
lazy val overrides: Rule[SparkPlan] = GpuOverrides()
lazy val overrideTransitions: Rule[SparkPlan] = new GpuTransitionOverrides()
override def preColumnarTransitions : Rule[SparkPlan] = overrides
override def postColumnarTransitions: Rule[SparkPlan] = overrideTransitions
}
object RapidsPluginUtils extends Logging {
val CUDF_PROPS_FILENAME = "cudf-java-version-info.properties"
val JNI_PROPS_FILENAME = "spark-rapids-jni-version-info.properties"
val PLUGIN_PROPS_FILENAME = "rapids4spark-version-info.properties"
private val SQL_PLUGIN_NAME = classOf[SQLExecPlugin].getName
private val UDF_PLUGIN_NAME = "com.nvidia.spark.udf.Plugin"
private val SQL_PLUGIN_CONF_KEY = StaticSQLConf.SPARK_SESSION_EXTENSIONS.key
private val SERIALIZER_CONF_KEY = "spark.serializer"
private val JAVA_SERIALIZER_NAME = classOf[JavaSerializer].getName
private val KRYO_SERIALIZER_NAME = classOf[KryoSerializer].getName
private val KRYO_REGISTRATOR_KEY = "spark.kryo.registrator"
private val KRYO_REGISTRATOR_NAME = classOf[GpuKryoRegistrator].getName
{
val pluginProps = loadProps(RapidsPluginUtils.PLUGIN_PROPS_FILENAME)
logInfo(s"RAPIDS Accelerator build: $pluginProps")
val jniProps = loadProps(RapidsPluginUtils.JNI_PROPS_FILENAME)
logInfo(s"RAPIDS Accelerator JNI build: $jniProps")
val cudfProps = loadProps(RapidsPluginUtils.CUDF_PROPS_FILENAME)
logInfo(s"cudf build: $cudfProps")
val pluginVersion = pluginProps.getProperty("version", "UNKNOWN")
val cudfVersion = cudfProps.getProperty("version", "UNKNOWN")
logWarning(s"RAPIDS Accelerator $pluginVersion using cudf $cudfVersion.")
}
def logPluginMode(conf: RapidsConf): Unit = {
if (conf.isSqlEnabled && conf.isSqlExecuteOnGPU) {
logWarning("RAPIDS Accelerator is enabled, to disable GPU " +
s"support set `${RapidsConf.SQL_ENABLED}` to false.")
if (conf.explain != "NONE") {
logWarning(s"spark.rapids.sql.explain is set to `${conf.explain}`. Set it to 'NONE' to " +
"suppress the diagnostics logging about the query placement on the GPU.")
}
} else if (conf.isSqlEnabled && conf.isSqlExplainOnlyEnabled) {
logWarning("RAPIDS Accelerator is in explain only mode, to disable " +
s"set `${RapidsConf.SQL_ENABLED}` to false. To change the mode, " +
s"restart the application and change `${RapidsConf.SQL_MODE}`.")
} else {
logWarning("RAPIDS Accelerator is disabled, to enable GPU " +
s"support set `${RapidsConf.SQL_ENABLED}` to true.")
}
if (conf.isUdfCompilerEnabled) {
logWarning("Experimental RAPIDS UDF compiler is enabled, in case of related failures " +
s"disable it by setting `${RapidsConf.UDF_COMPILER_ENABLED}` to false. " +
"More information is available at https://nvidia.github.io/spark-rapids/docs/FAQ.html#" +
"automatic-translation-of-scala-udfs-to-apache-spark-operations" )
}
}
def fixupConfigs(conf: SparkConf): Unit = {
// First add in the SQL executor plugin because that is what we need at a minimum
if (conf.contains(SQL_PLUGIN_CONF_KEY)) {
for (pluginName <- Array(SQL_PLUGIN_NAME, UDF_PLUGIN_NAME)){
val previousValue = conf.get(SQL_PLUGIN_CONF_KEY).split(",").map(_.trim)
if (!previousValue.contains(pluginName)) {
conf.set(SQL_PLUGIN_CONF_KEY, (previousValue :+ pluginName).mkString(","))
} else {
conf.set(SQL_PLUGIN_CONF_KEY, previousValue.mkString(","))
}
}
} else {
conf.set(SQL_PLUGIN_CONF_KEY, Array(SQL_PLUGIN_NAME,UDF_PLUGIN_NAME).mkString(","))
}
val serializer = conf.get(SERIALIZER_CONF_KEY, JAVA_SERIALIZER_NAME)
if (KRYO_SERIALIZER_NAME.equals(serializer)) {
if (conf.contains(KRYO_REGISTRATOR_KEY)) {
if (!KRYO_REGISTRATOR_NAME.equals(conf.get(KRYO_REGISTRATOR_KEY)) ) {
logWarning("The RAPIDS Accelerator when used with Kryo needs to register some " +
s"serializers using $KRYO_REGISTRATOR_NAME. Please call it from your registrator " +
" to let the plugin work properly.")
} // else it is set and we are good to go
} else {
// We cannot set the kryo key here, it is not early enough to be picked up everywhere
throw new UnsupportedOperationException("The RAPIDS Accelerator when used with Kryo " +
"needs to register some serializers. Please set the spark config " +
s"$KRYO_REGISTRATOR_KEY to $KRYO_REGISTRATOR_NAME or some operations may not work " +
"properly.")
}
} else if (!JAVA_SERIALIZER_NAME.equals(serializer)) {
throw new UnsupportedOperationException(s"$serializer is not a supported serializer for " +
s"the RAPIDS Accelerator. Please disable the RAPIDS Accelerator or use a supported " +
s"serializer ($JAVA_SERIALIZER_NAME, $KRYO_SERIALIZER_NAME).")
}
// set driver timezone
conf.set(RapidsConf.DRIVER_TIMEZONE.key, ZoneId.systemDefault().normalized().toString)
}
def loadProps(resourceName: String): Properties = {
val classLoader = RapidsPluginUtils.getClass.getClassLoader
val resource = classLoader.getResourceAsStream(resourceName)
if (resource == null) {
throw new PluginException(s"Could not find properties file $resourceName in the classpath")
}
val props = new Properties
props.load(resource)
props
}
}
/**
* The Spark driver plugin provided by the RAPIDS Spark plugin.
*/
class RapidsDriverPlugin extends DriverPlugin with Logging {
var rapidsShuffleHeartbeatManager: RapidsShuffleHeartbeatManager = null
override def receive(msg: Any): AnyRef = {
if (rapidsShuffleHeartbeatManager == null) {
throw new IllegalStateException(
s"Rpc message $msg received, but shuffle heartbeat manager not configured.")
}
msg match {
case RapidsExecutorStartupMsg(id) =>
rapidsShuffleHeartbeatManager.registerExecutor(id)
case RapidsExecutorHeartbeatMsg(id) =>
rapidsShuffleHeartbeatManager.executorHeartbeat(id)
case m => throw new IllegalStateException(s"Unknown message $m")
}
}
override def init(
sc: SparkContext, pluginContext: PluginContext): java.util.Map[String, String] = {
val sparkConf = pluginContext.conf
RapidsPluginUtils.fixupConfigs(sparkConf)
val conf = new RapidsConf(sparkConf)
RapidsPluginUtils.logPluginMode(conf)
if (GpuShuffleEnv.isRapidsShuffleAvailable(conf)) {
GpuShuffleEnv.initShuffleManager()
if (conf.shuffleTransportEarlyStart) {
rapidsShuffleHeartbeatManager =
new RapidsShuffleHeartbeatManager(
conf.shuffleTransportEarlyStartHeartbeatInterval,
conf.shuffleTransportEarlyStartHeartbeatTimeout)
}
}
conf.rapidsConfMap
}
}
/**
* The Spark executor plugin provided by the RAPIDS Spark plugin.
*/
class RapidsExecutorPlugin extends ExecutorPlugin with Logging {
var rapidsShuffleHeartbeatEndpoint: RapidsShuffleHeartbeatEndpoint = null
override def init(
pluginContext: PluginContext,
extraConf: java.util.Map[String, String]): Unit = {
try {
// if configured, re-register checking leaks hook.
reRegisterCheckLeakHook()
val conf = new RapidsConf(extraConf.asScala.toMap)
// Compare if the cudf version mentioned in the classpath is equal to the version which
// plugin expects. If there is a version mismatch, throw error. This check can be disabled
// by setting this config spark.rapids.cudfVersionOverride=true
checkCudfVersion(conf)
// Validate driver and executor time zone are same if the driver time zone is supported by
// the plugin.
val driverTimezone = conf.driverTimeZone match {
case Some(value) => ZoneId.of(value)
case None => throw new RuntimeException(s"Driver time zone cannot be determined.")
}
if (TypeChecks.areTimestampsSupported(driverTimezone)) {
val executorTimezone = ZoneId.systemDefault()
if (executorTimezone.normalized() != driverTimezone.normalized()) {
throw new RuntimeException(s" Driver and executor timezone mismatch. " +
s"Driver timezone is $driverTimezone and executor timezone is " +
s"$executorTimezone. Set executor timezone to $driverTimezone.")
}
}
// we rely on the Rapids Plugin being run with 1 GPU per executor so we can initialize
// on executor startup.
if (!GpuDeviceManager.rmmTaskInitEnabled) {
logInfo("Initializing memory from Executor Plugin")
GpuDeviceManager.initializeGpuAndMemory(pluginContext.resources().asScala.toMap, conf)
if (GpuShuffleEnv.isRapidsShuffleAvailable(conf)) {
GpuShuffleEnv.initShuffleManager()
if (conf.shuffleTransportEarlyStart) {
logInfo("Initializing shuffle manager heartbeats")
rapidsShuffleHeartbeatEndpoint = new RapidsShuffleHeartbeatEndpoint(pluginContext, conf)
rapidsShuffleHeartbeatEndpoint.registerShuffleHeartbeat()
}
}
}
val concurrentGpuTasks = conf.concurrentGpuTasks
logInfo(s"The number of concurrent GPU tasks allowed is $concurrentGpuTasks")
GpuSemaphore.initialize(concurrentGpuTasks)
} catch {
case e: Throwable =>
// Exceptions in executor plugin can cause a single thread to die but the executor process
// sticks around without any useful info until it hearbeat times out. Print what happened
// and exit immediately.
logError("Exception in the executor plugin, shutting down!", e)
System.exit(1)
}
}
/**
* Re-register leaks checking hook if configured.
*/
private def reRegisterCheckLeakHook(): Unit = {
// DEFAULT_SHUTDOWN_THREAD in MemoryCleaner is responsible to check the leaks at shutdown time,
// it expects all other hooks are done before the checking
// as other hooks will close some resources.
if (MemoryCleaner.configuredDefaultShutdownHook) {
// Shutdown hooks are executed concurrently in JVM, and there is no execution order guarantee.
// See the doc of `Runtime.addShutdownHook`.
// Here we should wait Spark hooks to be done, or a false leak will be detected.
// See issue: https://github.com/NVIDIA/spark-rapids/issues/5854
//
// Here use `Spark ShutdownHookManager` to manage hooks with priority.
// 20 priority is small enough, will run after Spark hooks.
TrampolineUtil.addShutdownHook(20, MemoryCleaner.removeDefaultShutdownHook())
}
}
private def checkCudfVersion(conf: RapidsConf): Unit = {
try {
val pluginProps = RapidsPluginUtils.loadProps(RapidsPluginUtils.PLUGIN_PROPS_FILENAME)
logInfo(s"RAPIDS Accelerator build: $pluginProps")
val expectedCudfVersion = Option(pluginProps.getProperty("cudf_version")).getOrElse {
throw CudfVersionMismatchException("Could not find cudf version in " +
RapidsPluginUtils.PLUGIN_PROPS_FILENAME)
}
val cudfProps = RapidsPluginUtils.loadProps(RapidsPluginUtils.CUDF_PROPS_FILENAME)
logInfo(s"cudf build: $cudfProps")
val cudfVersion = Option(cudfProps.getProperty("version")).getOrElse {
throw CudfVersionMismatchException("Could not find cudf version in " +
RapidsPluginUtils.CUDF_PROPS_FILENAME)
}
// compare cudf version in the classpath with the cudf version expected by plugin
if (!RapidsExecutorPlugin.cudfVersionSatisfied(expectedCudfVersion, cudfVersion)) {
throw CudfVersionMismatchException(s"Found cudf version $cudfVersion, RAPIDS Accelerator " +
s"expects $expectedCudfVersion")
}
} catch {
case x: PluginException if conf.cudfVersionOverride =>
logWarning(s"Ignoring error due to ${RapidsConf.CUDF_VERSION_OVERRIDE.key}=true: " +
s"${x.getMessage}")
}
}
override def shutdown(): Unit = {
GpuSemaphore.shutdown()
PythonWorkerSemaphore.shutdown()
GpuDeviceManager.shutdown()
Option(rapidsShuffleHeartbeatEndpoint).foreach(_.close())
}
override def onTaskFailed(failureReason: TaskFailedReason): Unit = {
failureReason match {
case ef: ExceptionFailure =>
ef.exception match {
case Some(_: CudaFatalException) =>
logError("Stopping the Executor based on exception being a fatal CUDA error: " +
s"${ef.toErrorString}")
System.exit(20)
case Some(_: CudaException) =>
logDebug(s"Executor onTaskFailed because of a non-fatal CUDA error: " +
s"${ef.toErrorString}")
case Some(_: CudfException) =>
logDebug(s"Executor onTaskFailed because of a CUDF error: ${ef.toErrorString}")
case _ =>
logDebug(s"Executor onTaskFailed: ${ef.toErrorString}")
}
case other =>
logDebug(s"Executor onTaskFailed: ${other.toString}")
}
}
}
object RapidsExecutorPlugin {
/**
* Return true if the expected cudf version is satisfied by the actual version found.
* The version is satisfied if the major and minor versions match exactly. If there is a requested
* patch version then the actual patch version must be greater than or equal.
* For example, version 7.1 is not satisfied by version 7.2, but version 7.1 is satisfied by
* version 7.1.1.
* If the expected cudf version is a specified 'timestamp-seq' one, then it is satisfied by
* the SNAPSHOT version.
* For example, version 7.1-yyyymmdd.hhmmss-seq is satisfied by version 7.1-SNAPSHOT.
*/
def cudfVersionSatisfied(expected: String, actual: String): Boolean = {
val expHyphen = if (expected.indexOf('-') >= 0) expected.indexOf('-') else expected.length
val actHyphen = if (actual.indexOf('-') >= 0) actual.indexOf('-') else actual.length
if (actual.substring(actHyphen) != expected.substring(expHyphen) &&
!(actual.substring(actHyphen) == "-SNAPSHOT" &&
expected.substring(expHyphen).matches("-([0-9]{8}).([0-9]{6})-([1-9][0-9]*)"))) {
return false
}
val (expMajorMinor, expPatch) = expected.substring(0, expHyphen).split('.').splitAt(2)
val (actMajorMinor, actPatch) = actual.substring(0, actHyphen).split('.').splitAt(2)
actMajorMinor.startsWith(expMajorMinor) && {
val expPatchInts = expPatch.map(_.toInt)
val actPatchInts = actPatch.map(v => Try(v.toInt).getOrElse(Int.MinValue))
val zipped = expPatchInts.zipAll(actPatchInts, 0, 0)
zipped.forall { case (e, a) => e <= a }
}
}
}
object ExecutionPlanCaptureCallback {
private[this] val shouldCapture: AtomicBoolean = new AtomicBoolean(false)
private[this] val execPlan: AtomicReference[SparkPlan] = new AtomicReference[SparkPlan]()
private def captureIfNeeded(qe: QueryExecution): Unit = {
if (shouldCapture.get()) {
execPlan.set(qe.executedPlan)
}
}
def startCapture(): Unit = {
execPlan.set(null)
shouldCapture.set(true)
}
def getResultWithTimeout(timeoutMs: Long = 2000): Option[SparkPlan] = {
try {
val endTime = System.currentTimeMillis() + timeoutMs
var plan = execPlan.getAndSet(null)
while (plan == null) {
if (System.currentTimeMillis() > endTime) {
return None
}
Thread.sleep(10)
plan = execPlan.getAndSet(null)
}
Some(plan)
} finally {
shouldCapture.set(false)
execPlan.set(null)
}
}
def extractExecutedPlan(plan: Option[SparkPlan]): SparkPlan = {
plan match {
case Some(p: AdaptiveSparkPlanExec) => p.executedPlan
case Some(p) => p
case _ => throw new IllegalStateException("No execution plan available")
}
}
def assertCapturedAndGpuFellBack(fallbackCpuClass: String, timeoutMs: Long = 2000): Unit = {
val gpuPlan = getResultWithTimeout(timeoutMs=timeoutMs)
assert(gpuPlan.isDefined, "Did not capture a GPU plan")
assertDidFallBack(gpuPlan.get, fallbackCpuClass)
}
def assertDidFallBack(gpuPlan: SparkPlan, fallbackCpuClass: String): Unit = {
val executedPlan = ExecutionPlanCaptureCallback.extractExecutedPlan(Some(gpuPlan))
assert(executedPlan.find(didFallBack(_, fallbackCpuClass)).isDefined,
s"Could not find $fallbackCpuClass in the GPU plan\n$executedPlan")
}
def assertDidFallBack(df: DataFrame, fallbackCpuClass: String): Unit = {
val executedPlan = df.queryExecution.executedPlan
assertDidFallBack(executedPlan, fallbackCpuClass)
}
def assertContains(gpuPlan: SparkPlan, className: String): Unit = {
assert(containsPlan(gpuPlan, className),
s"Could not find $className in the Spark plan\n$gpuPlan")
}
def assertContains(df: DataFrame, gpuClass: String): Unit = {
val executedPlan = df.queryExecution.executedPlan
assertContains(executedPlan, gpuClass)
}
def assertNotContain(gpuPlan: SparkPlan, className: String): Unit = {
assert(!containsPlan(gpuPlan, className),
s"We found $className in the Spark plan\n$gpuPlan")
}
def assertNotContain(df: DataFrame, gpuClass: String): Unit = {
val executedPlan = df.queryExecution.executedPlan
assertNotContain(executedPlan, gpuClass)
}
private def didFallBack(exp: Expression, fallbackCpuClass: String): Boolean = {
!exp.getClass.getCanonicalName.equals("com.nvidia.spark.rapids.GpuExpression") &&
PlanUtils.getBaseNameFromClass(exp.getClass.getName) == fallbackCpuClass ||
exp.children.exists(didFallBack(_, fallbackCpuClass))
}
private def didFallBack(plan: SparkPlan, fallbackCpuClass: String): Boolean = {
val executedPlan = ExecutionPlanCaptureCallback.extractExecutedPlan(Some(plan))
!executedPlan.getClass.getCanonicalName.equals("com.nvidia.spark.rapids.GpuExec") &&
PlanUtils.sameClass(executedPlan, fallbackCpuClass) ||
executedPlan.expressions.exists(didFallBack(_, fallbackCpuClass))
}
private def containsExpression(exp: Expression, className: String,
regexMap: MutableMap[String, Regex] // regex memoization
): Boolean = exp.find {
case e if PlanUtils.getBaseNameFromClass(e.getClass.getName) == className => true
case e: ExecSubqueryExpression => containsPlan(e.plan, className, regexMap)
case _ => false
}.nonEmpty
private def containsPlan(plan: SparkPlan, className: String,
regexMap: MutableMap[String, Regex] = MutableMap.empty // regex memoization
): Boolean = plan.find {
case p if PlanUtils.sameClass(p, className) =>
true
case p: AdaptiveSparkPlanExec =>
containsPlan(p.executedPlan, className, regexMap)
case p: QueryStageExec =>
containsPlan(p.plan, className, regexMap)
case p: ReusedSubqueryExec =>
containsPlan(p.child, className, regexMap)
case p: ReusedExchangeExec =>
containsPlan(p.child, className, regexMap)
case p if p.expressions.exists(containsExpression(_, className, regexMap)) =>
true
case p: SparkPlan =>
val sparkPlanStringForRegex = p.verboseStringWithSuffix(1000)
regexMap.getOrElseUpdate(className, className.r)
.findFirstIn(sparkPlanStringForRegex)
.nonEmpty
}.nonEmpty
}
/**
* Used as a part of testing to capture the executed query plan.
*/
class ExecutionPlanCaptureCallback extends QueryExecutionListener {
import ExecutionPlanCaptureCallback._
override def onSuccess(funcName: String, qe: QueryExecution, durationNs: Long): Unit =
captureIfNeeded(qe)
override def onFailure(funcName: String, qe: QueryExecution, exception: Exception): Unit =
captureIfNeeded(qe)
}