Skip to content

Commit

Permalink
[SPARK-49978][R] Move sparkR deprecation warning to package attach time
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

Previously, the output deprecation warning happens in the `spark.session` function, in this PR, we move it to the `.onAttach` function so it will be triggered whenever library is attached

### Why are the changes needed?

I believe having the warning message on attach time have the following benefits:

- **Have a more prompt warning.** If the deprecation is for the whole package instead of just the `sparkR.session` function, it is more intuitive for the warning to show up on attach time instead of waiting til later time
- **Do not rely on the assumption of "every sparkR user will run sparkR.session method".** This asumption may not hold true all the time. For example, some hosted spark platform like Databricks already configure the spark session in the background and therefore will not show the error message. So making this change should make sure a broader reach for this warning notification
- **Less intrusive warning**. Previous warning show up every time `sparkR.session` is called, but the new warning message will only show up once even if user run multiple `library`/`require` commands

### Does this PR introduce _any_ user-facing change?

**Yes**
1. No more waring message in sparkR.session method
2. Warning message on library attach (when calling `library`/`require` function)
<img width="859" alt="image" src="https://github.com/user-attachments/assets/d88d9108-ec63-4f69-8de6-3f34eeafdd0c">
3. Able to surpress warning by setting `SPARKR_SUPPRESS_DEPRECATION_WARNING`
<img width="733" alt="image" src="https://github.com/user-attachments/assets/0266e6dd-3dc7-4c20-b999-b83906f381cd">

### How was this patch tested?

Just a simple migration change, will rely on existing pre/post-merge check, and this existing test
Also did manual testing(see previous section for screenshot)

### Was this patch authored or co-authored using generative AI tooling?

No

Closes #48482 from tinglongliao-db/sparkR-deprecation-migration.

Authored-by: Tinglong Liao <tinglong.liao@databricks.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
  • Loading branch information
tinglongliao-db authored and HyukjinKwon committed Oct 16, 2024
1 parent f5e6b05 commit e92bf37
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions R/pkg/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Collate:
'types.R'
'utils.R'
'window.R'
'zzz.R'
RoxygenNote: 7.1.2
VignetteBuilder: knitr
NeedsCompilation: no
Expand Down
6 changes: 0 additions & 6 deletions R/pkg/R/sparkR.R
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,6 @@ sparkR.session <- function(
sparkPackages = "",
enableHiveSupport = TRUE,
...) {

if (Sys.getenv("SPARKR_SUPPRESS_DEPRECATION_WARNING") == "") {
warning(
"SparkR is deprecated from Apache Spark 4.0.0 and will be removed in a future version.")
}

sparkConfigMap <- convertNamedListToEnv(sparkConfig)
namedParams <- list(...)
if (length(namedParams) > 0) {
Expand Down
30 changes: 30 additions & 0 deletions R/pkg/R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
# zzz.R - package startup message

.onAttach <- function(...) {
if (Sys.getenv("SPARKR_SUPPRESS_DEPRECATION_WARNING") == "") {
packageStartupMessage(
paste0(
"Warning: ",
"SparkR is deprecated in Apache Spark 4.0.0 and will be removed in a future release. ",
"To continue using Spark in R, we recommend using sparklyr instead: ",
"https://spark.posit.co/get-started/"
)
)
}
}

0 comments on commit e92bf37

Please sign in to comment.