-
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.
Add support for stacked sinks (#611)
- Loading branch information
1 parent
417a95d
commit 725eb40
Showing
11 changed files
with
400 additions
and
15 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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import os | ||
import sys | ||
from datetime import datetime | ||
from fennel.expr import col | ||
from fennel.testing import mock | ||
|
||
__owner__ = "[email protected]" | ||
|
||
os.environ["KAFKA_HOST"] = "some-host" | ||
os.environ["KAFKA_USERNAME"] = "some-username" | ||
os.environ["KAFKA_PASSWORD"] = "some-password" | ||
os.environ["DB_NAME"] = "some-db" | ||
os.environ["SNOWFLAKE_USERNAME"] = "snowflake-username" | ||
os.environ["SNOWFLAKE_PASSWORD"] = "snowflake-password" | ||
|
||
|
||
@mock | ||
def test_stacked_sinks(client): | ||
from fennel.connectors import Kafka, S3, eval, source | ||
from fennel.datasets import dataset | ||
|
||
kafka = Kafka( | ||
name="my_kafka", | ||
bootstrap_servers="localhost:9092", | ||
security_protocol="SASL_PLAINTEXT", | ||
sasl_mechanism="PLAIN", | ||
sasl_plain_username="user", | ||
sasl_plain_password="password", | ||
) | ||
s3 = S3(name="mys3") | ||
cutoff = datetime(2024, 1, 1, 0, 0, 0) | ||
bucket = s3.bucket("data", path="orders") | ||
|
||
# docsnip-highlight start | ||
@source(bucket, disorder="1w", cdc="append", until=cutoff) | ||
@source(kafka.topic("order"), disorder="1d", cdc="append", since=cutoff) | ||
# docsnip-highlight end | ||
@dataset | ||
class UserLocation: | ||
uid: int | ||
city: str | ||
country: str | ||
update_time: datetime | ||
|
||
# docsnip stacked | ||
from fennel.connectors import Kafka, Snowflake, sink | ||
from fennel.datasets import dataset, pipeline, Dataset | ||
from fennel.lib.params import inputs | ||
|
||
kafka = Kafka( | ||
name="kafka_src", | ||
bootstrap_servers=os.environ["KAFKA_HOST"], | ||
security_protocol="PLAINTEXT", | ||
sasl_mechanism="PLAIN", | ||
sasl_plain_username=os.environ["KAFKA_USERNAME"], | ||
sasl_plain_password=os.environ["KAFKA_PASSWORD"], | ||
) | ||
snowflake = Snowflake( | ||
name="my_snowflake", | ||
account="VPECCVJ-MUB03765", | ||
warehouse="TEST", | ||
db_name=os.environ["DB_NAME"], | ||
schema="PUBLIC", | ||
role="ACCOUNTADMIN", | ||
username=os.environ["SNOWFLAKE_USERNAME"], | ||
password=os.environ["SNOWFLAKE_PASSWORD"], | ||
) | ||
|
||
# docsnip-highlight start | ||
@sink( | ||
snowflake.table("test_table"), | ||
every="1d", | ||
how="incremental", | ||
renames={"uid": "new_uid"}, | ||
stacked=True, | ||
) | ||
@sink(kafka.topic("user_location"), cdc="debezium") | ||
# docsnip-highlight end | ||
@dataset | ||
class UserLocationFiltered: | ||
uid: int | ||
city: str | ||
country: str | ||
update_time: datetime | ||
|
||
@pipeline | ||
@inputs(UserLocation) | ||
def user_location_count(cls, dataset: Dataset): | ||
return dataset.filter(lambda row: row["country"] != "United States") | ||
|
||
# /docsnip | ||
client.commit( | ||
message="some commit msg", datasets=[UserLocationFiltered, UserLocation] | ||
) |
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
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 |
---|---|---|
|
@@ -680,6 +680,14 @@ class UserInfoDataset: | |
cdc="debezium", | ||
env=["prod_new4"], | ||
) | ||
@sink( | ||
http_with_secret.path( | ||
endpoint="/sink3", limit=100, headers={"Foo": "Bar"} | ||
), | ||
cdc="debezium", | ||
env=["prod_new4"], | ||
stacked=True, | ||
) | ||
@dataset | ||
class UserInfoDatasetDerived: | ||
user_id: int = field(key=True) | ||
|
@@ -934,10 +942,10 @@ def create_user_transactions(cls, dataset: Dataset): | |
sync_request = view._get_sync_request_proto(env="prod_new4") | ||
assert len(sync_request.datasets) == 2 | ||
assert len(sync_request.sources) == 1 | ||
assert len(sync_request.sinks) == 1 | ||
assert len(sync_request.sinks) == 2 | ||
assert len(sync_request.extdbs) == 2 | ||
|
||
sink_request = sync_request.sinks[0] | ||
sink_request = sync_request.sinks[1] | ||
s = { | ||
"table": { | ||
"http_path": { | ||
|
@@ -975,6 +983,45 @@ def create_user_transactions(cls, dataset: Dataset): | |
sink_request, expected_sink_request | ||
) | ||
|
||
sink_request = sync_request.sinks[0] | ||
s = { | ||
"table": { | ||
"http_path": { | ||
"db": { | ||
"name": "http_sink_with_secret", | ||
"http": { | ||
"host_secret": { | ||
"secret_arn": "arn:aws:secretsmanager:us-west-2:123456789012:secret:fennel-test-secret-1", | ||
"role_arn": "arn:aws:iam::123456789012:role/fennel-test-role", | ||
"path": ["http_host"], | ||
}, | ||
"healthz": "/health", | ||
"ca_cert": { | ||
"secret_ref": { | ||
"secret_arn": "arn:aws:secretsmanager:us-west-2:123456789012:secret:fennel-test-secret-1", | ||
"role_arn": "arn:aws:iam::123456789012:role/fennel-test-role", | ||
"path": ["ca_cert"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
"endpoint": "/sink3", | ||
"limit": 100, | ||
"headers": { | ||
"Foo": "Bar", | ||
}, | ||
}, | ||
}, | ||
"dataset": "UserInfoDatasetDerived", | ||
"dsVersion": 1, | ||
"cdc": "Debezium", | ||
"stacked": True, | ||
} | ||
expected_sink_request = ParseDict(s, connector_proto.Sink()) | ||
assert sink_request == expected_sink_request, error_message( | ||
sink_request, expected_sink_request | ||
) | ||
|
||
|
||
def test_kafka_sink_and_source_doesnt_create_extra_extdbs(): | ||
@meta(owner="[email protected]") | ||
|
Oops, something went wrong.