Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting the app name via SparkConnection #156

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions hlink/spark/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
class SparkConnection:
"""Handles initialization of spark session and connection to local cluster."""

def __init__(self, derby_dir, warehouse_dir, tmp_dir, python, db_name):
def __init__(
self, derby_dir, warehouse_dir, tmp_dir, python, db_name, app_name="linking"
):
self.derby_dir = derby_dir
self.warehouse_dir = warehouse_dir
self.db_name = db_name
self.tmp_dir = tmp_dir
self.python = python
self.app_name = app_name

def spark_conf(self, executor_cores, executor_memory, driver_memory, cores):
spark_package_path = os.path.dirname(hlink.spark.__file__)
Expand All @@ -44,7 +47,7 @@ def spark_conf(self, executor_cores, executor_memory, driver_memory, cores):
)
.set("spark.executorEnv.SPARK_LOCAL_DIRS", self.tmp_dir)
.set("spark.sql.legacy.allowUntypedScalaUDF", True)
.setAppName("linking")
.setAppName(self.app_name)
# .set("spark.executor.cores", executor_cores) \
)
if executor_memory:
Expand Down
33 changes: 33 additions & 0 deletions hlink/tests/spark_connection_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pathlib import Path
import sys

from hlink.spark.session import SparkConnection


def test_app_name_defaults_to_linking(tmp_path: Path) -> None:
derby_dir = tmp_path / "derby"
warehouse_dir = tmp_path / "warehouse"
tmp_dir = tmp_path / "tmp"
connection = SparkConnection(
derby_dir, warehouse_dir, tmp_dir, sys.executable, "test"
)
spark = connection.local(cores=1, executor_memory="1G")
app_name = spark.conf.get("spark.app.name")
assert app_name == "linking"


def test_app_name_argument(tmp_path: Path) -> None:
derby_dir = tmp_path / "derby"
warehouse_dir = tmp_path / "warehouse"
tmp_dir = tmp_path / "tmp"
connection = SparkConnection(
derby_dir,
warehouse_dir,
tmp_dir,
sys.executable,
"test",
app_name="test_app_name",
)
spark = connection.local(cores=1, executor_memory="1G")
app_name = spark.conf.get("spark.app.name")
assert app_name == "test_app_name"