-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist_metrics_lazy_sync.py
53 lines (37 loc) · 1.38 KB
/
list_metrics_lazy_sync.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
"""Fetch all available metrics from the metadata API and display only the dimensions of certain metrics."""
from argparse import ArgumentParser
from dbtsl import SemanticLayerClient
def get_arg_parser() -> ArgumentParser:
p = ArgumentParser()
p.add_argument("--env-id", required=True, help="The dbt environment ID", type=int)
p.add_argument("--token", required=True, help="The API auth token")
p.add_argument("--host", required=True, help="The API host")
return p
def main() -> None:
arg_parser = get_arg_parser()
args = arg_parser.parse_args()
client = SemanticLayerClient(
environment_id=args.env_id,
auth_token=args.token,
host=args.host,
lazy=True,
)
with client.session():
metrics = client.metrics()
for i, m in enumerate(metrics):
print(f"📈 {m.name}")
print(f" type={m.type}")
print(f" description={m.description}")
assert len(m.dimensions) == 0
# skip if index is odd
if i & 1:
print(" dimensions=skipped")
continue
# load dimensions only if index is even
m.load_dimensions()
print(" dimensions=[")
for dim in m.dimensions:
print(f" {dim.name},")
print(" ]")
if __name__ == "__main__":
main()