-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature group api and hive and spark engine (#10)
- Loading branch information
1 parent
77a1935
commit 4d8647c
Showing
14 changed files
with
381 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from hopsworks import feature_group | ||
|
||
|
||
class FeatureGroupApi: | ||
def __init__(self, client, feature_store_id): | ||
# or should the client be passed with every call to the API | ||
self._client = client | ||
self._feature_store_id = feature_store_id | ||
|
||
def get(self, name, version): | ||
"""Get feature store with specific id or name. | ||
:param identifier: id or name of the feature store | ||
:type identifier: int, str | ||
:return: the featurestore metadata | ||
:rtype: FeatureStore | ||
""" | ||
path_params = [ | ||
"project", | ||
self._client._project_id, | ||
"featurestores", | ||
self._feature_store_id, | ||
"featuregroups", | ||
name, | ||
] | ||
query_params = {"version": version} | ||
return feature_group.FeatureGroup.from_response_json( | ||
self._client, | ||
self._client._send_request("GET", path_params, query_params)[0], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import json | ||
|
||
from hopsworks import util, engine | ||
|
||
|
||
class Query: | ||
def __init__( | ||
self, query_constructor_api, left_feature_group, left_features, joins=None, | ||
): | ||
self._left_feature_group = left_feature_group | ||
self._left_features = left_features | ||
self._joins = joins | ||
self._query_constructor_api = query_constructor_api | ||
|
||
def read(self, dataframe_type="default"): | ||
sql_query = self._query_constructor_api.construct_query(self)["query"] | ||
return engine.get_instance().sql(sql_query, dataframe_type) | ||
|
||
def show(self, n): | ||
sql_query = self._query_constructor_api.construct_query(self)["query"] | ||
return engine.get_instance().show(sql_query, n) | ||
|
||
def json(self): | ||
return json.dumps(self, cls=util.QueryEncoder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class QueryConstructorApi: | ||
def __init__(self, client): | ||
self._client = client | ||
|
||
def construct_query(self, query): | ||
path_params = ["project", self._client._project_id, "featurestores", "query"] | ||
headers = {"content-type": "application/json"} | ||
return self._client._send_request( | ||
"PUT", path_params, headers=headers, data=query.json() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from hopsworks.engine import spark, hive | ||
|
||
_engine = None | ||
|
||
|
||
def init(engine_type, host=None, cert_folder=None, cert_key=None): | ||
global _engine | ||
if not _engine: | ||
if engine_type == "spark": | ||
_engine = spark.Engine() | ||
elif engine_type == "hive": | ||
_engine = hive.Engine(host, cert_folder, cert_key) | ||
|
||
|
||
def get_instance(): | ||
global _engine | ||
if _engine: | ||
return _engine | ||
raise Exception("Couldn't find execution engine. Try reconnecting to Hopsworks.") | ||
|
||
|
||
def stop(): | ||
global _engine | ||
_engine = None |
Oops, something went wrong.