Skip to content

Commit 04f4ae8

Browse files
treyspsungchun12
andauthored
Docs: add UI guide (#2700)
Co-authored-by: Sung Won Chung <sungwonchung3@gmail.com>
1 parent 71fdbe4 commit 04f4ae8

31 files changed

+279
-0
lines changed

docs/guides/ui.md

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
# Browser UI guide
2+
3+
SQLMesh's free, open-source browser user interface (UI) makes it easy to understand, explore, and modify your SQLMesh project.
4+
5+
This page describes the UI's components and how they work.
6+
7+
## Purpose
8+
9+
Modifying SQLMesh projects involves changing code, creating environments, and applying plans. The browser UI facilitates this process with a graphical interface for executing SQLMesh commands.
10+
11+
However, not all SQLMesh commands can be executed - for example, `sqlmesh run` must be executed via the [CLI](../reference/cli.md) or [Python](../reference/python.md) interfaces.
12+
13+
### Editing code
14+
15+
Editing code is the primary activity when modifying SQLMesh projects.
16+
17+
Many developers edit code in an integrated development environment (IDE), such as [VSCode](https://code.visualstudio.com/) or [PyCharm](https://www.jetbrains.com/pycharm/). IDEs include extensive editing functionality like auto-completion, customized key mappings, code validation, and embedded terminals.
18+
19+
The SQLMesh UI editor is not an IDE; it is a code editor for quickly updating models and writing ad-hoc SQL queries.
20+
21+
For development work, we recommend using the SQLMesh UI alongside an IDE. The UI's modular design lets you mix and match UI components while you edit code in the IDE. Learn more [below](#working-with-an-ide).
22+
23+
## Setup
24+
25+
Before beginning, ensure that you meet all the [prerequisites](../prerequisites.md) for using SQLMesh. The SQLMesh browser UI requires additional Python libraries not included in the base SQLMesh installation.
26+
27+
To use the UI, install SQLMesh with the `web` add-on. First, if using a python virtual environment, ensure it's activated by running `source .env/bin/activate` command from the folder used during [installation](../installation.md).
28+
29+
Next, install the UI with `pip`:
30+
31+
```bash
32+
pip install "sqlmesh[web]"
33+
```
34+
35+
## Start the Browser UI
36+
37+
Open the UI by running the `sqlmesh ui` command from within the project directory:
38+
39+
```bash
40+
sqlmesh ui
41+
```
42+
43+
After starting up, the SQLMesh web UI is served at `http://127.0.0.1:8000` by default:
44+
45+
![SQLMesh web UI startup on CLI](./ui/ui-quickstart_cli.png)
46+
47+
Navigate to the URL by clicking the link in your terminal (if supported) or copy-pasting it into your web browser:
48+
49+
![SQLMesh web UI startup in browser](./ui/ui-quickstart_ui-startup.png)
50+
51+
## Modules
52+
53+
The UI consists of modules that contain different functionality, and sets of modules are grouped into "modes" (learn more about modes [below](#modes)).
54+
55+
The UI modules are:
56+
57+
- [Code editor](#editor-module)
58+
- [Plan builder](#plan-module)
59+
- [Project documentation](#docs-module)
60+
- [Table and column lineage](#lineage-module)
61+
62+
The screenshots in most examples below use the default `editor` mode.
63+
64+
### Editor module
65+
66+
The `editor` module will appear by default if the UI is started without specifying a mode. Its default view contains five panes:
67+
68+
1. Project directory allows navigation of project directories and files.
69+
2. Editor tabs displays open code editors.
70+
3. Code editor allows viewing and editing code files.
71+
4. Inspector provides settings and information based on recent actions and the currently active pane. (Note: inspector pane is collapsed by default. Expand it by clicking the hamburger button at the top of the collapsed pane - see previous image.)
72+
5. Details displays column-level lineage for models open in the editor and results of queries. (Note: details pane is collapsed by default. It will automatically expand upon opening a model in the editor or running a query.)
73+
74+
![SQLMesh browser UI panes](./ui/ui-quickstart_ui-startup-panes.png)
75+
76+
It also contains nine buttons:
77+
78+
1. Toggle Editor/Docs/Errors/Plan toggles among the editor module (default), docs module, errors view, and plan module. Errors view is only available if an error has occurred.
79+
2. History navigation returns to previous views, similar to the back button in a web browser.
80+
3. Add new tab opens a new code editor window.
81+
4. Plan opens the plan module.
82+
5. Documentation links to the SQLMesh documentation website.
83+
6. The crescent moon toggles between page light and dark modes.
84+
7. Run SQL query executes the [`sqlmesh fetchdf` command](../reference/cli.md#fetchdf).
85+
8. Format SQL query reformats a SQL query using SQLGlot's pretty layout.
86+
9. Change SQL dialect specifies the SQL dialect of the current tab for custom SQL queries. It does not affect the SQL dialect for the project.
87+
88+
![SQLMesh browser UI buttons](./ui/ui-guide_ui-startup-buttons.png)
89+
90+
And it contains four status indicators:
91+
92+
1. Editor tab language displays the programming language of the current code editor tab (SQL or Python).
93+
2. Current environment displays the currently selected environment
94+
3. Change indicator displays a summary of the changes in the project files relative to the most recently run SQLMesh plan in the selected environment.
95+
4. Error indicator displays the count of errors in the project.
96+
97+
![SQLMesh web UI status indicators](./ui/ui-quickstart_ui-startup-status.png)
98+
99+
#### Edit models
100+
101+
Open a model in a new tab by clicking its file name in the left-hand project directory pane.
102+
103+
The tab will show the model definition, and the details pane at the bottom will display the model in the project's table and column lineage.
104+
105+
![Incremental model open in editor](./ui/ui-quickstart_incremental-model.png)
106+
107+
The lineage display will update as model modifications are saved. For example, you might modify the incremental SQL model by adding a new column to the query. Press `Cmd + S` (`Ctrl + S` on Windows) to save the modified model file and display the updated lineage:
108+
109+
![Incremental model modified in editor](./ui/ui-quickstart_incremental-model-modified.png)
110+
111+
The `Changes` indicator in the top right now shows blue and orange circles that reflect our model update.
112+
113+
#### Run SQL queries
114+
115+
Run SQL queries by executing them from custom SQL editor tabs.
116+
117+
For example, we might add a SQL query `select * from sqlmesh_example.incremental_model` to the Custom SQL 1 tab. To run the query, first click the hamburger icon to open the explorer pane:
118+
119+
![Querying `dev` incremental model with SQL query in editor](./ui/ui-guide_fetchdf-prod-query.png)
120+
121+
Then click the `Run Query` button in the bottom right to execute the query:
122+
123+
![Results from querying dev incremental model with SQL query in editor](./ui/ui-guide_fetchdf-prod.png)
124+
125+
The results appear in an interactive table in the details pane below the editor.
126+
127+
### Plan module
128+
129+
The plan module provides a graphical interface for the `sqlmesh plan` command. Its actions change based on the current state of your SQLMesh project. For example, it will auto-update impact analysis based on the latest saved changes to a SQL model.
130+
131+
Open the plan module by clicking the green circle button on the left-hand pane or the green Plan button on the top bar next to the environment dropdown.
132+
133+
The sections below use the SQLMesh [quickstart project](../quick_start.md) to demonstrate the module.
134+
135+
#### New project
136+
137+
In a brand new project, the only environment is the empty `prod` environment. The first SQLMesh plan must execute every model to populate the production environment.
138+
139+
When you open the plan module, it contains multiple pieces of information about the project's first plan:
140+
141+
- The `Initializing Prod Environment` section shows that the plan is initializing the `prod` environment.
142+
- The Start and End date sections are grayed out because they are not allowed when running a plan in the `prod` environment.
143+
- The `Changes` section shows that SQLMesh detected three models added relative to the current empty environment.
144+
- The `Backfills` section shows that backfills will occur for all three of the added models.
145+
146+
![Plan module - new project](./ui/ui-quickstart_run-plan.png)
147+
148+
SQLMesh will apply the plan and initiate backfill when you click the blue button labeled `Apply Changes And Backfill`.
149+
150+
The page will update and new output sections will appear. Each section reflects a stage in the plan application and will be green if the step succeeded.
151+
152+
The `Tests Completed` section indicates that the project's [unit tests](../concepts/tests.md) ran successfully.
153+
154+
The `Snapshot Tables Created` indicates that [snapshots](../concepts/architecture/snapshots.md) of the added and modified models were created successfully.
155+
156+
The `Backfilled` section shows progress indicators for the backfill operations. The first progress indicator shows the total number of tasks and completion percentage for the entire backfill operation. The remaining progress bars show completion percentage and run time for each model (very fast in this simple example).
157+
158+
![Plan module - plan applied](./ui/ui-quickstart_apply-plan.png)
159+
160+
#### New environment
161+
162+
To create a new environment, open the environment menu by clicking the drop-down labeled `Environment: prod \/` next to the green `Plan` button on the top right.
163+
164+
To create an environment named "dev," type `dev` into the Environment field and click the blue `Add` button.
165+
166+
![Open environment menu](./ui/ui-quickstart_create-dev.png)
167+
168+
The drop-down now shows that the SQLMesh UI is working in the `dev` environment:
169+
170+
![Working in dev environment](./ui/ui-quickstart_plan-dev.png)
171+
172+
To populate the environment with views of the production environment, click the green `Plan` button to open the plan module:
173+
174+
![Run plan on dev pane](./ui/ui-quickstart_run-plan-dev.png)
175+
176+
The output section does not list any added/modified models or backfills because `dev` is being created from the existing `prod` environment without modification.
177+
178+
Clicking the blue `Apply Virtual Update` button applies the new plan:
179+
180+
![Run plan on dev pane output](./ui/ui-quickstart_run-plan-dev-output.png)
181+
182+
183+
#### Existing environment
184+
185+
If you modify the project files, you will want to apply the changes to an existing environment. In this example, we have changed the project's `incremental_model` and are applying the changes to the `dev` environment.
186+
187+
The plan module will summarize the changes when you open it:
188+
189+
![Plan pane after opening plan module with modified model](./ui/ui-quickstart_run-plan-dev-modified.png)
190+
191+
The `Changes` section detects that `incremental_model` was directly modified and that `full_model` was indirectly modified because it selects from the incremental model.
192+
193+
Click the blue `Apply Changes And Backfill` button to apply the plan and execute the backfill:
194+
195+
![Plan after applying updated plan with modified model](./ui/ui-quickstart_apply-plan-dev-modified.png)
196+
197+
### Docs module
198+
199+
The docs module displays information about all your project's models in one interface.
200+
201+
A list of all models is displayed in the left-hand pane. You can filter models by name by typing in the field at the top of the pane.
202+
203+
When you choose a model, its query, lineage, and attributes are displayed. This example shows information from the [quickstart project](../quick_start.md) incremental model:
204+
205+
![Docs with incremental model selected](./ui/ui-guide_docs.png)
206+
207+
By default, the model definition source code is displayed. If you toggle to `Compiled Query`, it will display an example of the model query rendered with macro values substituted:
208+
209+
![Docs with compiled incremental model query](./ui/ui-guide_docs-compiled-query.png)
210+
211+
### Lineage module
212+
213+
The lineage module displays a graphical representation of the project's table and column lineage.
214+
215+
Click a model in the left-hand pane to view its lineage. By default, only the model's upstream parents and downstream children are displayed:
216+
217+
![Lineage module](./ui/ui-guide_lineage.png)
218+
219+
You may include all a project's models by clicking `All` in the Show drop-down on the upper right. In this example, two additional models appear:
220+
221+
![Lineage module - all models](./ui/ui-guide_lineage-all.png)
222+
223+
Click `Connected` in the Show drop-down menu to highlight edges between upstream parents and downstream children in blue. This may be helpful when when a project contains many models:
224+
225+
![Lineage module - all models, connected edges](./ui/ui-guide_lineage-all-connected.png)
226+
227+
## Modes
228+
229+
The SQLMesh UI consists of the four modules described above, grouped into three different "modes." Modes allow you to maintain a clean interface by suppressing UI features you don't plan to use during a session.
230+
231+
You may specify the UI mode as an option when you [start the UI on the command line](#start-the-browser-ui). For example, to run the UI in plan mode issue the CLI command `sqlmesh ui --mode plan` from within the project directory.
232+
233+
The UI modes contain these modules:
234+
235+
- `editor`: code editor, plan builder, project documentation, table and column lineage
236+
- `plan`: plan builder, project documentation, table and column lineage
237+
- `docs`: project documentation, table and column lineage
238+
239+
### Working with an IDE
240+
241+
The SQLMesh browser UI complements an IDE by rapidly surfacing the implications of changes to project code.
242+
243+
This section demonstrates one way to use the UI while editing in VSCode; the UI's `plan` mode suppresses the code editor module so it's not in the way.
244+
245+
VSCode natively supports [opening a web browser in a VSCode window](https://dev.to/equiman/vscode-browser-inside-2b06). We can open the browser UI in that window and see the effects of our code updates in real time.
246+
247+
To use this workflow, first open a terminal in VSCode and navigate to your project directory. Then follow these steps:
248+
249+
<b>1.</b> Start the browser UI in `plan` mode with the command `sqlmesh ui --mode plan`:
250+
251+
![VSCode - start the UI](./ui/ui-guide_vscode-start-ui.png)
252+
253+
<br></br>
254+
<b>2.</b> In VSCode, type the shortcut `cmd+shift+p` to open the search menu:
255+
256+
![VSCode - open search menu](./ui/ui-guide_vscode-open-search.png)
257+
258+
<br></br>
259+
<b>3.</b> Type `simple browser` into the search menu and click the entry `Simple browser: Show`:
260+
261+
![VSCode - open simple browser](./ui/ui-guide_vscode-start-browser.png)
262+
263+
<br></br>
264+
<b>4.</b> Copy the web address printed by the command output (`http://127.0.0.1:8000` by default), paste it into the menu, and click enter:
265+
266+
![VSCode - navigate to UI](./ui/ui-guide_vscode-browser-url.png)
267+
268+
<br></br>
269+
<b>5.</b> The UI will now appear in a VSCode tab:
270+
271+
![VSCode - UI in browser tab](./ui/ui-guide_vscode-browser-ui.png)
272+
273+
<br></br>
274+
<b>6.</b> Split the VSCode window to open a code editor alongside the UI. As you update models, the UI plan and lineage interfaces will update to reflect the changes in real time:
275+
276+
![VSCode - update model plan](./ui/ui-guide_vscode-update-plan.png)
277+
278+
![VSCode - update model lineage](./ui/ui-guide_vscode-update-lineage.png)
60.5 KB
Loading

docs/guides/ui/ui-guide_docs.png

614 KB
Loading
388 KB
Loading
488 KB
Loading
298 KB
Loading
303 KB
Loading
280 KB
Loading
197 KB
Loading
171 KB
Loading

0 commit comments

Comments
 (0)