-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sync: Tier selector * Docs and mock client changes
- Loading branch information
1 parent
6032c95
commit 2a0eddd
Showing
23 changed files
with
768 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,13 @@ | |
|
||
|
||
# docsnip datasets | ||
@source(postgres.table("orders", cursor="timestamp"), every="1m", lateness="1d") | ||
@source( | ||
postgres.table("orders", cursor="timestamp"), | ||
every="1m", | ||
lateness="1d", | ||
tier="prod", | ||
) | ||
@source(Webhook(name="fennel_webhook").endpoint("Order"), tier="dev") | ||
@meta(owner="[email protected]") | ||
@dataset | ||
class Order: | ||
|
@@ -89,15 +95,14 @@ def myextractor(cls, ts: pd.Series, uids: pd.Series, sellers: pd.Series): | |
# We can write a unit test to verify that the feature is working as expected | ||
# docsnip test | ||
|
||
fake_webhook = Webhook(name="fennel_webhook") | ||
|
||
|
||
class TestUserLivestreamFeatures(unittest.TestCase): | ||
@mock | ||
def test_feature(self, client): | ||
fake_Order = Order.with_source(fake_webhook.endpoint("Order")) | ||
client.sync( | ||
datasets=[fake_Order, UserSellerOrders], featuresets=[UserSeller] | ||
datasets=[Order, UserSellerOrders], | ||
featuresets=[UserSeller], | ||
tier="dev", | ||
) | ||
columns = ["uid", "product_id", "seller_id", "timestamp"] | ||
now = datetime.utcnow() | ||
|
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from fennel.lib.metadata import meta | ||
from fennel.lib.schema import inputs, outputs | ||
from fennel.sources import source, Webhook | ||
from fennel.test_lib import mock | ||
from fennel.test_lib import mock, InternalTestClient | ||
|
||
webhook = Webhook(name="fennel_webhook") | ||
|
||
|
@@ -70,34 +70,41 @@ def e2(cls, ts: pd.Series, durations: pd.Series) -> pd.Series: | |
# /docsnip | ||
|
||
|
||
def test_multiple_extractors_of_same_feature(): | ||
with pytest.raises(Exception): | ||
# docsnip featureset_extractors_of_same_feature | ||
@featureset | ||
class Movies: | ||
duration: int = feature(id=1) | ||
over_2hrs: bool = feature(id=2) | ||
# invalid: both e1 & e2 output `over_3hrs` | ||
over_3hrs: bool = feature(id=3) | ||
|
||
@extractor | ||
@inputs(duration) | ||
@outputs(over_2hrs, over_3hrs) | ||
def e1(cls, ts: pd.Series, durations: pd.Series) -> pd.DataFrame: | ||
two_hrs = durations > 2 * 3600 | ||
three_hrs = durations > 3 * 3600 | ||
return pd.DataFrame( | ||
{"over_2hrs": two_hrs, "over_3hrs": three_hrs} | ||
) | ||
|
||
@extractor | ||
@inputs(duration) | ||
@outputs(over_3hrs) | ||
def e2(cls, ts: pd.Series, durations: pd.Series) -> pd.Series: | ||
return pd.Series(name="over_3hrs", data=durations > 3 * 3600) | ||
@mock | ||
def test_multiple_extractors_of_same_feature(client): | ||
# docsnip featureset_extractors_of_same_feature | ||
@meta(owner="[email protected]") | ||
@featureset | ||
class Movies: | ||
duration: int = feature(id=1) | ||
over_2hrs: bool = feature(id=2) | ||
# invalid: both e1 & e2 output `over_3hrs` | ||
over_3hrs: bool = feature(id=3) | ||
|
||
@extractor(tier=["default"]) | ||
@inputs(duration) | ||
@outputs(over_2hrs, over_3hrs) | ||
def e1(cls, ts: pd.Series, durations: pd.Series) -> pd.DataFrame: | ||
two_hrs = durations > 2 * 3600 | ||
three_hrs = durations > 3 * 3600 | ||
return pd.DataFrame({"over_2hrs": two_hrs, "over_3hrs": three_hrs}) | ||
|
||
@extractor(tier=["non-default"]) | ||
@inputs(duration) | ||
@outputs(over_3hrs) | ||
def e2(cls, ts: pd.Series, durations: pd.Series) -> pd.Series: | ||
return pd.Series(name="over_3hrs", data=durations > 3 * 3600) | ||
|
||
# /docsnip | ||
|
||
# /docsnip | ||
view = InternalTestClient() | ||
view.add(Movies) | ||
with pytest.raises(Exception) as e: | ||
view._get_sync_request_proto() | ||
assert ( | ||
str(e.value) | ||
== "Feature `over_3hrs` is extracted by multiple extractors including `e2`." | ||
) | ||
|
||
|
||
# docsnip remote_feature_as_input | ||
|
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 |
---|---|---|
|
@@ -23,14 +23,20 @@ | |
postgres = Postgres.get(name="my_rdbms") | ||
warehouse = Snowflake.get(name="my_warehouse") | ||
kafka = Kafka.get(name="my_kafka") | ||
webhook = Webhook(name="fennel_webhook") | ||
|
||
|
||
# /docsnip | ||
|
||
|
||
# docsnip datasets | ||
@dataset | ||
@source(postgres.table("product_info", cursor="last_modified"), every="1m") | ||
@source( | ||
postgres.table("product_info", cursor="last_modified"), | ||
every="1m", | ||
tier="prod", | ||
) | ||
@source(webhook.endpoint("Product"), tier="dev") | ||
@meta(owner="[email protected]", tags=["PII"]) | ||
class Product: | ||
product_id: int = field(key=True) | ||
|
@@ -51,7 +57,8 @@ def get_expectations(cls): | |
|
||
# ingesting realtime data from Kafka works exactly the same way | ||
@meta(owner="[email protected]") | ||
@source(kafka.topic("orders"), lateness="1h") | ||
@source(kafka.topic("orders"), lateness="1h", tier="prod") | ||
@source(webhook.endpoint("Order"), tier="dev") | ||
@dataset | ||
class Order: | ||
uid: int | ||
|
@@ -122,15 +129,13 @@ def myextractor(cls, ts: pd.Series, uids: pd.Series, sellers: pd.Series): | |
# docsnip sync | ||
from fennel.test_lib import MockClient | ||
|
||
webhook = Webhook(name="fennel_webhook") | ||
|
||
# client = Client('<FENNEL SERVER URL>') # uncomment this line to use a real Fennel server | ||
client = MockClient() # comment this line to use a real Fennel server | ||
fake_Product = Product.with_source(webhook.endpoint("Product")) | ||
fake_Order = Order.with_source(webhook.endpoint("Order")) | ||
client.sync( | ||
datasets=[fake_Order, fake_Product, UserSellerOrders], | ||
datasets=[Order, Product, UserSellerOrders], | ||
featuresets=[UserSellerFeatures], | ||
tier="dev", | ||
) | ||
|
||
now = datetime.utcnow() | ||
|
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 |
---|---|---|
|
@@ -26,11 +26,15 @@ class UserDataset: | |
|
||
postgres = Postgres.get(name="postgres") | ||
kafka = Kafka.get(name="kafka") | ||
webhook = Webhook(name="fennel_webhook") | ||
|
||
|
||
# docsnip external_data_sources | ||
@meta(owner="[email protected]") | ||
@source(postgres.table("user", cursor="update_timestamp"), every="1m") | ||
@source( | ||
postgres.table("user", cursor="update_timestamp"), every="1m", tier="prod" | ||
) | ||
@source(webhook.endpoint("User"), tier="dev") | ||
@dataset | ||
class User: | ||
uid: int = field(key=True) | ||
|
@@ -40,7 +44,8 @@ class User: | |
|
||
|
||
@meta(owner="[email protected]") | ||
@source(kafka.topic("transactions")) | ||
@source(kafka.topic("transactions"), tier="prod") | ||
@source(webhook.endpoint("Transaction"), tier="dev") | ||
@dataset | ||
class Transaction: | ||
uid: int | ||
|
@@ -118,15 +123,13 @@ def get_country(cls, ts: pd.Series, uids: pd.Series): | |
|
||
# /docsnip | ||
|
||
webhook = Webhook(name="fennel_webhook") | ||
|
||
|
||
# Tests to ensure that there are no run time errors in the snippets | ||
@mock | ||
def test_overview(client): | ||
fake_User = User.with_source(webhook.endpoint("User")) | ||
fake_Transaction = Transaction.with_source(webhook.endpoint("Transaction")) | ||
client.sync(datasets=[fake_User, fake_Transaction, UserTransactionsAbroad]) | ||
client.sync( | ||
datasets=[User, Transaction, UserTransactionsAbroad], tier="dev" | ||
) | ||
now = datetime.now() | ||
dob = now - timedelta(days=365 * 30) | ||
data = [ | ||
|
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
Oops, something went wrong.