From 833d49559a4d353ac682f27268725fcc14f93f6e Mon Sep 17 00:00:00 2001 From: Willem Pienaar <6728866+woop@users.noreply.github.com> Date: Thu, 16 Jan 2020 03:02:42 +0200 Subject: [PATCH] Remove "resource" concept and the need to specify a kind in feature sets (#432) --- infra/docker-compose/docker-compose.yml | 5 ++- sdk/__init__.py | 0 sdk/python/feast/cli.py | 43 ++++++++----------------- sdk/python/feast/feature_set.py | 2 -- sdk/python/feast/loaders/yaml.py | 7 ++-- sdk/python/feast/resource.py | 10 ------ 6 files changed, 19 insertions(+), 48 deletions(-) delete mode 100644 sdk/__init__.py delete mode 100644 sdk/python/feast/resource.py diff --git a/infra/docker-compose/docker-compose.yml b/infra/docker-compose/docker-compose.yml index a224500ca0..44750650ce 100644 --- a/infra/docker-compose/docker-compose.yml +++ b/infra/docker-compose/docker-compose.yml @@ -59,6 +59,8 @@ services: redis: image: redis:5-alpine + ports: + - "6379:6379" kafka: image: confluentinc/cp-kafka:5.2.1 @@ -70,7 +72,8 @@ services: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE ports: - - 9094:9092 + - "9092:9092" + - "9094:9094" depends_on: - zookeeper diff --git a/sdk/__init__.py b/sdk/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/sdk/python/feast/cli.py b/sdk/python/feast/cli.py index 601f41d4b1..8e8f185d03 100644 --- a/sdk/python/feast/cli.py +++ b/sdk/python/feast/cli.py @@ -17,7 +17,6 @@ import click from feast import config as feast_config from feast.client import Client -from feast.resource import ResourceFactory from feast.feature_set import FeatureSet import toml import pkg_resources @@ -147,17 +146,25 @@ def feature_set_list(): print(tabulate(table, headers=["NAME", "VERSION"], tablefmt="plain")) -@feature_set.command("create") -@click.argument("name") -def feature_set_create(name): +@feature_set.command("apply") +@click.option( + "--filename", + "-f", + help="Path to a feature set configuration file that will be applied", + type=click.Path(exists=True), +) +def feature_set_create(filename): """ - Create a feature set + Create or update a feature set """ + + feature_sets = [FeatureSet.from_dict(fs_dict) for fs_dict in yaml_loader(filename)] + feast_client = Client( core_url=feast_config.get_config_property_or_fail("core_url") ) # type: Client - feast_client.apply(FeatureSet(name=name)) + feast_client.apply(feature_sets) @feature_set.command("describe") @@ -264,29 +271,5 @@ def ingest(name, version, filename, file_type): feature_set.ingest_file(file_path=filename) -@cli.command() -@click.option( - "--filename", - "-f", - help="Path to the configuration file that will be applied", - type=click.Path(exists=True), -) -def apply(filename): - """ - Apply a configuration to a resource by filename or stdin - """ - - resources = [ - ResourceFactory.get_resource(res_dict["kind"]).from_dict(res_dict) - for res_dict in yaml_loader(filename) - ] - - feast_client = Client( - core_url=feast_config.get_config_property_or_fail("core_url") - ) # type: Client - - feast_client.apply(resources) - - if __name__ == "__main__": cli() diff --git a/sdk/python/feast/feature_set.py b/sdk/python/feast/feature_set.py index d557660751..c47c51e5a2 100644 --- a/sdk/python/feast/feature_set.py +++ b/sdk/python/feast/feature_set.py @@ -689,8 +689,6 @@ def from_dict(cls, fs_dict): Returns a FeatureSet object based on the feature set dict """ - if ("kind" not in fs_dict) and (fs_dict["kind"].strip() != "feature_set"): - raise Exception(f"Resource kind is not a feature set {str(fs_dict)}") feature_set_proto = json_format.ParseDict( fs_dict, FeatureSetProto(), ignore_unknown_fields=True ) diff --git a/sdk/python/feast/loaders/yaml.py b/sdk/python/feast/loaders/yaml.py index 4cbe15dfaa..130a71a3d0 100644 --- a/sdk/python/feast/loaders/yaml.py +++ b/sdk/python/feast/loaders/yaml.py @@ -53,7 +53,7 @@ def _get_yaml_contents(yml: str) -> str: with open(yml, "r") as f: yml_content = f.read() - elif isinstance(yml, str) and "kind" in yml.lower(): + elif isinstance(yml, str): yml_content = yml else: raise Exception( @@ -73,7 +73,4 @@ def _yaml_to_dict(yaml_string): Dictionary containing the same object """ - yaml_dict = yaml.safe_load(yaml_string) - if not isinstance(yaml_dict, dict) or not "kind" in yaml_dict: - raise Exception(f"Could not detect YAML kind from resource: ${yaml_string}") - return yaml_dict + return yaml.safe_load(yaml_string) diff --git a/sdk/python/feast/resource.py b/sdk/python/feast/resource.py deleted file mode 100644 index 17a6529166..0000000000 --- a/sdk/python/feast/resource.py +++ /dev/null @@ -1,10 +0,0 @@ -from feast.feature_set import FeatureSet - -# TODO: This factory adds no value. It should be removed asap. -class ResourceFactory: - @staticmethod - def get_resource(kind): - if kind == "feature_set": - return FeatureSet - else: - raise ValueError(kind)