Skip to content

Commit

Permalink
Update MockTaskContext to support new functions added in Spark-4.0 [d…
Browse files Browse the repository at this point in the history
…atabricks] (#11972)

This fixes #11971 . This
unblocks the scala_2.13 nightly build jobs.

MockTaskContext extends TaskContext in spark-rapids code. Recently
additional definitions were added in Spark-4.0's TaskContext.
In this PR, we added the missing methods to MockTaskContext.scala file.
We are not overriding these methods so that it can compile on all Spark
versions.

In Spark-4.0, these were added in TaskContext.scala:
PR : apache/spark#49413

```
private[spark] def interruptible(): Boolean
private[spark] def pendingInterrupt(threadToInterrupt: Option[Thread], reason: String): Unit
private[spark] def createResourceUninterruptibly[T <: Closeable](resourceBuilder: => T): T
```

Signed-off-by: Niranjan Artal <[email protected]>
Co-authored-by: Gera Shegalov <[email protected]>
  • Loading branch information
nartal1 and gerashegalov authored Jan 17, 2025
1 parent 6705345 commit 1ba64a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/dev/shims.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ for conflicting Shim implementations.

### Compile-time issues

#### Methods added in new versions

If the base class or trait in the new version just adds new methods on top of previous versions and can be implemented
with default behavior, they can be added directly to the unshimmed class. For methods introduced
in newer versions that do not exist in older versions, removing the override keyword ensures that
these methods are treated as new additions rather than overrides. This allows the same class to work
across different Spark versions.

#### Different parent class signatures

Upstream base classes we derive from might be incompatible in the sense that one version
requires us to implement/override the method `M` whereas the other prohibits it by marking
the base implementation `final`, E.g. `org.apache.spark.sql.catalyst.trees.TreeNode` changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2023, NVIDIA CORPORATION.
* Copyright (c) 2020-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/
package org.apache.spark.sql.rapids.metrics.source

import java.io.Closeable
import java.util
import java.util.Properties

Expand Down Expand Up @@ -102,4 +103,16 @@ class MockTaskContext(taskAttemptId: Long, partitionId: Int) extends TaskContext
* removing the override keyword.
*/
def isFailed(): Boolean = false

/**
* These below methods were introduced in Spark-4. It's not shimmed and added to the common class
* removing the override keyword.
*/

private[spark] def interruptible(): Boolean = false

private[spark] def pendingInterrupt(threadToInterrupt: Option[Thread], reason: String): Unit = {}

private[spark] def createResourceUninterruptibly[T <: Closeable](
resourceBuilder: => T): T = resourceBuilder
}

0 comments on commit 1ba64a8

Please sign in to comment.