-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathrun_snowflake_destination.py
92 lines (79 loc) · 2.4 KB
/
run_snowflake_destination.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
"""
Usage:
poetry install
poetry run python examples/run_snowflake_destination.py
"""
from __future__ import annotations
import airbyte as ab
from airbyte.caches import SnowflakeCache
from airbyte.secrets.google_gsm import GoogleGSMSecretManager
SCALE = 100
AIRBYTE_INTERNAL_GCP_PROJECT = "dataline-integration-testing"
secret_mgr = GoogleGSMSecretManager(
project=AIRBYTE_INTERNAL_GCP_PROJECT,
credentials_json=ab.get_secret("GCP_GSM_CREDENTIALS"),
)
secret = secret_mgr.get_secret(
secret_name="AIRBYTE_LIB_SNOWFLAKE_CREDS",
)
assert secret is not None, "Secret not found."
secret_config = secret.parse_json()
snowflake_destination_secret = secret_mgr.fetch_connector_secret(
connector_name="destination-snowflake",
).parse_json()
cortex_destination_secret = secret_mgr.fetch_connector_secret(
connector_name="destination-snowflake-cortex",
).parse_json()
source = ab.get_source(
"source-faker",
config={
"count": SCALE,
},
install_if_missing=True,
streams=["products", "users"],
)
cache = SnowflakeCache(
account=secret_config["account"],
username=secret_config["username"],
password=secret_config["password"],
database=secret_config["database"],
warehouse=secret_config["warehouse"],
role=secret_config["role"],
)
snowflake_destination = ab.get_destination(
"destination-snowflake",
config={
**snowflake_destination_secret,
"default_schema": "pyairbyte_tests",
},
)
cortex_destination_secret["processing"]["text_fields"] = [
"make",
"model",
"name",
"gender",
]
cortex_destination_secret["indexing"]["default_schema"] = "pyairbyte_tests"
cortex_destination = ab.get_destination(
"destination-snowflake-cortex",
config=cortex_destination_secret,
)
# cortex_destination.print_config_spec()
# snowflake_destination.print_config_spec()
# cortex_destination.print_config_spec()
snowflake_destination.check()
cortex_destination.check()
source.check()
# # This works:
# snowflake_write_result = snowflake_destination.write(
# source,
# cache=False, # Toggle comment to test with/without caching
# )
cortex_write_result = cortex_destination.write(
source,
cache=False, # Toggle comment to test with/without caching
)
# result = source.read(cache)
# for name in ["products"]:
# print(f"Stream {name}: {len(list(result[name]))} records")