Skip to content

Commit f3e3efa

Browse files
committed
fix(remote-function): Detect Spark version dynamically for JAR copy
Read SPARK_HOME/RELEASE file at runtime to determine the cluster's Spark version instead of hardcoding 3.5. Falls back to 3.5 if the file is missing or unparseable.
1 parent 589ae0a commit f3e3efa

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • sagemaker-core/src/sagemaker/core/remote_function

sagemaker-core/src/sagemaker/core/remote_function/job.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,16 @@ def __init__(
678678
" 'sagemaker-feature-store-pyspark>=2,<3'"
679679
)
680680
copy_jar_cmd = (
681-
"python3 -c \"import feature_store_pyspark, shutil, os, glob; "
681+
"python3 -c \""
682+
"import feature_store_pyspark, shutil, os, glob, re; "
683+
"release_file = os.path.join(os.environ.get('SPARK_HOME', '/usr/lib/spark'), 'RELEASE'); "
684+
"spark_ver = '3.5'; "
685+
"rf = open(release_file).read() if os.path.exists(release_file) else ''; "
686+
"m = re.search(r'Spark (\\d+\\.\\d+)', rf); "
687+
"spark_ver = m.group(1) if m else spark_ver; "
682688
"jars_dir = os.path.join(os.path.dirname(feature_store_pyspark.__file__), 'jars'); "
683689
"[shutil.copy(j, '/usr/lib/spark/jars/') "
684-
"for j in glob.glob(os.path.join(jars_dir, '*3.5*.jar'))]\""
690+
"for j in glob.glob(os.path.join(jars_dir, '*' + spark_ver + '*.jar'))]\""
685691
)
686692
if self.pre_execution_commands is None:
687693
self.pre_execution_commands = [install_cmd, copy_jar_cmd]

0 commit comments

Comments
 (0)