Skip to content

Commit 0ea514a

Browse files
TheOphigeIcaroG
andauthored
feat(tutorials/semantic-layer): add semantic layer tab scaffolding to tutorials (#4566)
* feat(tutorials/semantic-layer): add semantic layer tab scaffolding to tutorials * feat(tutorials/semantic-layer): remove v0 and joins * Update apps/docs/docs/tutorials/quickstart.md Co-authored-by: Ícaro Guerra <[email protected]> * Update apps/docs/docs/tutorials/quickstart.md Co-authored-by: Ícaro Guerra <[email protected]> * Update apps/docs/docs/tutorials/quickstart.md Co-authored-by: Ícaro Guerra <[email protected]> * Update apps/docs/docs/tutorials/quickstart.md Co-authored-by: Ícaro Guerra <[email protected]> * Update apps/docs/docs/tutorials/quickstart.md Co-authored-by: Ícaro Guerra <[email protected]> * Update: apps/docs/docs/tutorials/quickstart.md Co-authored-by: Ícaro Guerra <[email protected]> * feat(tutorials/semantic-layer): add vo and v1 * feat(tutorials/semantic-layer): add vo and v1 * feat(tutorials/semantic-layer): add vo and v1 --------- Co-authored-by: Ícaro Guerra <[email protected]>
1 parent a808d0e commit 0ea514a

File tree

1 file changed

+176
-0
lines changed

1 file changed

+176
-0
lines changed

apps/docs/docs/tutorials/quickstart.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ description: Get started with pyoso and common query patterns for our most popul
44
sidebar_position: 2
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
This tutorial walks through the basics of using [pyoso](../get-started/python.md) to explore the OSO data lake. This tutorial is designed to be run locally in a Jupyter notebook. We also have guides for using pyoso in different notebook environments [here](../guides/notebooks/).
811

912
:::tip
@@ -41,44 +44,145 @@ def stringify(arr):
4144

4245
Get a preview of all available models:
4346

47+
<Tabs>
48+
<TabItem value="python-sql" label="Python">
49+
4450
```python
4551
client.to_pandas("SELECT * FROM models_v0 LIMIT 5")
4652
```
4753

54+
</TabItem>
55+
<TabItem value="python-semantic" label="Semantic Layer">
56+
57+
```python
58+
query = semantic.select(
59+
"models"
60+
).limit(5)
61+
```
62+
63+
</TabItem>
64+
</Tabs>
65+
4866
Get the list of stable production models:
4967

68+
<Tabs>
69+
<TabItem value="python-sql" label="Python">
70+
5071
```python
5172
client.to_pandas("SELECT * FROM models_v0 WHERE model_name LIKE '%_v1'")
5273
```
5374

75+
</TabItem>
76+
<TabItem value="python-semantic" label="Semantic Layer">
77+
78+
```python
79+
query = oso.semantic.select(
80+
"models",
81+
).where(
82+
"models.model_name LIKE '%_v1'"
83+
)
84+
```
85+
86+
</TabItem>
87+
</Tabs>
88+
5489
Get the list of less stable models:
5590

91+
<Tabs>
92+
<TabItem value="python-sql" label="Python">
93+
5694
```python
5795
client.to_pandas("SELECT * FROM models_v0 WHERE model_name LIKE '%_v0'")
5896
```
5997

98+
</TabItem>
99+
<TabItem value="python-semantic" label="Semantic Layer">
100+
101+
```python
102+
query = oso.semantic.select(
103+
"models",
104+
).where(
105+
"models.model_name LIKE '%_v0'"
106+
)
107+
```
108+
109+
</TabItem>
110+
</Tabs>
111+
60112
## Query Popular Models
61113

62114
Get a list of projects:
63115

116+
<Tabs>
117+
<TabItem value="python-sql" label="Python">
118+
64119
```python
65120
client.to_pandas("SELECT * FROM projects_v1 LIMIT 5")
66121
```
67122

123+
</TabItem>
124+
<TabItem value="python-semantic" label="Semantic Layer">
125+
126+
```python
127+
query = oso.semantic.select(
128+
"projects",
129+
).limit(5)
130+
```
131+
132+
</TabItem>
133+
</Tabs>
134+
68135
Look up a specific project:
69136

137+
<Tabs>
138+
<TabItem value="python-sql" label="Python">
139+
70140
```python
71141
client.to_pandas("SELECT * FROM projects_v1 WHERE project_name = 'opensource-observer'")
72142
```
73143

144+
</TabItem>
145+
<TabItem value="python-semantic" label="Semantic Layer">
146+
147+
```python
148+
query = oso.semantic.select(
149+
"projects",
150+
).where(
151+
"projects.project_name = 'opensource-observer'"
152+
)
153+
```
154+
155+
</TabItem>
156+
</Tabs>
157+
74158
Get all artifacts owned by a project:
75159

160+
<Tabs>
161+
<TabItem value="python-sql" label="Python">
162+
76163
```python
77164
client.to_pandas("SELECT * FROM artifacts_by_project_v1 WHERE project_name = 'opensource-observer'")
78165
```
79166

167+
</TabItem>
168+
<TabItem value="python-semantic" label="Semantic Layer">
169+
170+
```python
171+
query = oso.semantic.select(
172+
"artifacts_by_project",
173+
).where(
174+
"artifacts_by_project.project_name = 'opensource-observer'"
175+
)
176+
```
177+
178+
</TabItem>
179+
</Tabs>
180+
80181
Get available key metrics for OSO:
81182

183+
<Tabs>
184+
<TabItem value="python-sql" label="Python">
185+
82186
```python
83187
client.to_pandas("""
84188
SELECT
@@ -94,8 +198,30 @@ client.to_pandas("""
94198
""")
95199
```
96200

201+
</TabItem>
202+
<TabItem value="python-semantic" label="Semantic Layer">
203+
204+
```python
205+
query = oso.semantic.select(
206+
"metrics.id",
207+
"metrics.name",
208+
"metrics.display_name",
209+
"key_metrics_by_project.sample_date",
210+
"key_metrics_by_project.amount",
211+
"key_metrics_by_project.unit",
212+
).where(
213+
"key_metrics_by_project.unit.project_id = 'UuWbpo5bpL5QsYvlukUWNm2uE8HFjxQxzCM0e+HMZfk='"
214+
)
215+
```
216+
217+
</TabItem>
218+
</Tabs>
219+
97220
Get a set of key metrics for a few projects:
98221

222+
<Tabs>
223+
<TabItem value="python-sql" label="Python">
224+
99225
```python
100226
MY_PROJECTS = ['opensource-observer', 'huggingface', 'wevm']
101227
MY_METRICS = ['GITHUB_stars_over_all_time', 'GITHUB_forks_over_all_time']
@@ -116,8 +242,35 @@ client.to_pandas(f"""
116242
""")
117243
```
118244

245+
</TabItem>
246+
<TabItem value="python-semantic" label="Semantic Layer">
247+
248+
```python
249+
MY_PROJECTS = ['opensource-observer', 'huggingface', 'wevm']
250+
MY_METRICS = ['GITHUB_stars_over_all_time', 'GITHUB_forks_over_all_time']
251+
252+
oso = Client() # ensure OSO_API_KEY is set
253+
254+
query = oso.semantic.select(
255+
"metrics.id",
256+
"metrics.name",
257+
"metrics.display_name",
258+
"key_metrics_by_project.sample_date",
259+
"key_metrics_by_project.amount",
260+
"key_metrics_by_project.unit",
261+
).where(
262+
"key_metrics_by_project.unit.project_id = MY_PROJECTS"
263+
)
264+
```
265+
266+
</TabItem>
267+
</Tabs>
268+
119269
Get timeseries metrics for OSO:
120270

271+
<Tabs>
272+
<TabItem value="python-sql" label="Python">
273+
121274
```python
122275
df_stars = client.to_pandas("""
123276
SELECT
@@ -137,6 +290,29 @@ df_stars = client.to_pandas("""
137290
""")
138291
```
139292

293+
</TabItem>
294+
<TabItem value="python-semantic" label="Semantic Layer">
295+
296+
```python
297+
query = (
298+
oso.semantic.select(
299+
"timeseries_metrics_by_project.metric_id",
300+
"metrics.metric_name",
301+
"metrics.display_name",
302+
"timeseries_metrics_by_project.sample_date",
303+
"timeseries_metrics_by_project.amount",
304+
"timeseries_metrics_by_project.unit",
305+
)
306+
.where(
307+
"projects.project_name = 'opensource-observer'",
308+
"metrics.metric_name = 'GITHUB_stars_daily'"
309+
)
310+
)
311+
```
312+
313+
</TabItem>
314+
</Tabs>
315+
140316
Add a cumulative column:
141317

142318
```python

0 commit comments

Comments
 (0)