Skip to content

Commit e92bf37

Browse files
tinglongliao-dbHyukjinKwon
authored andcommitted
[SPARK-49978][R] Move sparkR deprecation warning to package attach time
### 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 <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent f5e6b05 commit e92bf37

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

R/pkg/DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Collate:
5757
'types.R'
5858
'utils.R'
5959
'window.R'
60+
'zzz.R'
6061
RoxygenNote: 7.1.2
6162
VignetteBuilder: knitr
6263
NeedsCompilation: no

R/pkg/R/sparkR.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,6 @@ sparkR.session <- function(
403403
sparkPackages = "",
404404
enableHiveSupport = TRUE,
405405
...) {
406-
407-
if (Sys.getenv("SPARKR_SUPPRESS_DEPRECATION_WARNING") == "") {
408-
warning(
409-
"SparkR is deprecated from Apache Spark 4.0.0 and will be removed in a future version.")
410-
}
411-
412406
sparkConfigMap <- convertNamedListToEnv(sparkConfig)
413407
namedParams <- list(...)
414408
if (length(namedParams) > 0) {

R/pkg/R/zzz.R

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# zzz.R - package startup message
18+
19+
.onAttach <- function(...) {
20+
if (Sys.getenv("SPARKR_SUPPRESS_DEPRECATION_WARNING") == "") {
21+
packageStartupMessage(
22+
paste0(
23+
"Warning: ",
24+
"SparkR is deprecated in Apache Spark 4.0.0 and will be removed in a future release. ",
25+
"To continue using Spark in R, we recommend using sparklyr instead: ",
26+
"https://spark.posit.co/get-started/"
27+
)
28+
)
29+
}
30+
}

0 commit comments

Comments
 (0)