Skip to content

Commit 03fc722

Browse files
authored
Add engine parameter to hopsworks.login (4.1) (#384)
* Add engine parameter to hopsworks.login * Fix the docstring for the engine parameter * Fix typing * Remove engine param from get_feature_store * Remove redundant code from get_feature_store
1 parent 64c246d commit 03fc722

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

python/hopsworks/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import tempfile
2323
import warnings
2424
from pathlib import Path
25+
from typing import Literal, Union
2526

2627
from hopsworks import client, constants, project, version
2728
from hopsworks.client.exceptions import (
@@ -83,6 +84,7 @@ def login(
8384
api_key_file: str = None,
8485
hostname_verification: bool = False,
8586
trust_store_path: str = None,
87+
engine: Union[None, Literal["spark"], Literal["python"], Literal["training"]] = None,
8688
) -> project.Project:
8789
"""Connect to [Serverless Hopsworks](https://app.hopsworks.ai) by calling the `hopsworks.login()` function with no arguments.
8890
@@ -122,6 +124,13 @@ def login(
122124
api_key_file: Path to file wih Api Key
123125
hostname_verification: Whether to verify Hopsworks' certificate
124126
trust_store_path: Path on the file system containing the Hopsworks certificates
127+
engine: Which engine to use, `"spark"`, `"python"` or `"training"`. Defaults to `None`,
128+
which initializes the engine to Spark if the environment provides Spark, for
129+
example on Hopsworks and Databricks, or falls back to Python if Spark is not
130+
available, e.g. on local Python environments or AWS SageMaker. This option
131+
allows you to override this behaviour. `"training"` engine is useful when only
132+
feature store metadata is needed, for example training dataset location and label
133+
information when Hopsworks training experiment is conducted.
125134
# Returns
126135
`Project`: The Project object to perform operations on
127136
# Raises
@@ -138,7 +147,7 @@ def login(
138147

139148
# If inside hopsworks, just return the current project for now
140149
if "REST_ENDPOINT" in os.environ:
141-
_hw_connection = _hw_connection(hostname_verification=hostname_verification)
150+
_hw_connection = _hw_connection(hostname_verification=hostname_verification, engine=engine)
142151
_connected_project = _hw_connection.get_project()
143152
_initialize_module_apis()
144153
print("\nLogged in to project, explore it here " + _connected_project.get_url())
@@ -207,6 +216,7 @@ def login(
207216
_hw_connection = _hw_connection(
208217
host=host,
209218
port=port,
219+
engine=engine,
210220
api_key_file=api_key_path,
211221
hostname_verification=hostname_verification,
212222
trust_store_path=trust_store_path,
@@ -246,6 +256,7 @@ def login(
246256
_hw_connection = _hw_connection(
247257
host=host,
248258
port=port,
259+
engine=engine,
249260
api_key_value=api_key,
250261
hostname_verification=hostname_verification,
251262
trust_store_path=trust_store_path,

python/hopsworks_common/connection.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Connection:
100100
Defaults to `None`.
101101
engine: Which engine to use, `"spark"`, `"python"` or `"training"`. Defaults to `None`,
102102
which initializes the engine to Spark if the environment provides Spark, for
103-
example on Hopsworks and Databricks, or falls back on Hive in Python if Spark is not
103+
example on Hopsworks and Databricks, or falls back to Python if Spark is not
104104
available, e.g. on local Python environments or AWS SageMaker. This option
105105
allows you to override this behaviour. `"training"` engine is useful when only
106106
feature store metadata is needed, for example training dataset location and label
@@ -151,7 +151,6 @@ def __init__(
151151
def get_feature_store(
152152
self,
153153
name: Optional[str] = None,
154-
engine: Optional[str] = None,
155154
): # -> feature_store.FeatureStore
156155
# the typing is commented out due to circular dependency, it breaks auto_doc.py
157156
"""Get a reference to a feature store to perform operations on.
@@ -161,25 +160,10 @@ def get_feature_store(
161160
162161
# Arguments
163162
name: The name of the feature store, defaults to `None`.
164-
engine: Which engine to use, `"spark"`, `"python"` or `"training"`. Defaults to `None`,
165-
which initializes the engine to Spark if the environment provides Spark, for
166-
example on Hopsworks and Databricks, or falls back on Hive in Python if Spark is not
167-
available, e.g. on local Python environments or AWS SageMaker. This option
168-
allows you to override this behaviour. `"training"` engine is useful when only
169-
feature store metadata is needed, for example training dataset location and label
170-
information when Hopsworks training experiment is conducted.
171163
172164
# Returns
173165
`FeatureStore`. A feature store handle object to perform operations on.
174166
"""
175-
# Ensure the engine is initialized and of right type
176-
from hsfs import engine as hsfs_engine
177-
178-
if engine:
179-
global _hsfs_engine_type
180-
_hsfs_engine_type = engine
181-
hsfs_engine.get_instance()
182-
183167
if not name:
184168
name = client.get_instance()._project_name
185169
return self._feature_store_api.get(util.append_feature_store_suffix(name))
@@ -532,7 +516,7 @@ def connection(
532516
Defaults to `None`.
533517
engine: Which engine to use, `"spark"`, `"python"` or `"training"`. Defaults to `None`,
534518
which initializes the engine to Spark if the environment provides Spark, for
535-
example on Hopsworks and Databricks, or falls back on Hive in Python if Spark is not
519+
example on Hopsworks and Databricks, or falls back to Python if Spark is not
536520
available, e.g. on local Python environments or AWS SageMaker. This option
537521
allows you to override this behaviour. `"training"` engine is useful when only
538522
feature store metadata is needed, for example training dataset location and label

python/hopsworks_common/project.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def project_namespace(self):
109109
return self._project_namespace
110110

111111
def get_feature_store(
112-
self, name: Optional[str] = None, engine: Optional[str] = None
112+
self, name: Optional[str] = None
113113
): # -> hsfs.feature_store.FeatureStore
114114
"""Connect to Project's Feature Store.
115115
@@ -127,15 +127,12 @@ def get_feature_store(
127127
128128
# Arguments
129129
name: Project name of the feature store.
130-
engine: Which engine to use, `"spark"`, `"python"` or `"training"`.
131-
Defaults to `"python"` when connected to [Serverless Hopsworks](https://app.hopsworks.ai).
132-
See [`hopsworks.connection`](connection.md#connection) documentation for more information.
133130
# Returns
134131
`hsfs.feature_store.FeatureStore`: The Feature Store API
135132
# Raises
136133
`RestAPIError`: If unable to connect
137134
"""
138-
return client.get_connection().get_feature_store(name, engine)
135+
return client.get_connection().get_feature_store(name)
139136

140137
def get_model_registry(self):
141138
"""Connect to Project's Model Registry API.

0 commit comments

Comments
 (0)