-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtop_3_user_xp_duplicate.Rmd
49 lines (38 loc) · 2.29 KB
/
top_3_user_xp_duplicate.Rmd
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
---
owner: [email protected]
description: Provide the top 3 users with the most XP.
fields:
user_id: The user id
xp: The user amount of XP
schema: viewflow_demo
connection_id: postgres_demo
automate_read_write: True
---
## Automatisation of reading/writing tables
By default, an Rmd script is simply executed. However, it's possible to automate a part of the script by adding `automate_read_write: True` to the metadata.
If this option is enabled, Viewflow will take care of connecting to the database and reading the required tables.
Finally, the newly created view is automatically written to the database (this data frame should have the same name as the name of this file).
From now on, we will assume the automatisation of reading/writing tables is turned on.
## Dependencies
The new view is based on the user_xp table. We can simply use this table in the default format: `<schema_name>.<table_name>`
A custom format for referencing tables can be configured by creating a new function in
`viewflow/parsers/dependencies_r_patterns.py` and adding a new line to the metadata in this file.
(This line would look like `dependency_function: your_custom_function`)
Customizing the format to reference tables can be useful if you want to avoid conflicts with other object names.
By default, if you use `public.<some_name>` for some object, Viewflow will automatically try to assign a table from the `public` schema to this name!
By mentioning a table in the specified format, Viewflow will automatically make sure that:
1. The script is only executed after all tasks on which this task depends are finished
2. This table is correctly read from the database.
```{r rename_view}
user_xp <- viewflow_demo.user_xp
```
That's all there is to it! You simply refer to the tables you want to use and Viewflow handles the rest!
Note that the previous line of R code is optional, you can directly utilize the table without renaming.
## View creation
A view is materialized with the 3 users having most XP.
```{r create_view}
top_3_user_xp_duplicate <- head(user_xp[order(user_xp$xp, decreasing=TRUE),], n = 3)
```
## View materialization
Viewflow will automatically materialize the view `top_3_user_xp_duplicate` in the database.
The new view must be assigned to an object with exactly the same name as the filename (excluding the file extension).