Tutorial: Build a visual data prep
In this tutorial, you build a visual data prep in Lakeflow Designer that answers a business question: which types of vacation rental property earn the most from confirmed bookings? You use the Wanderbricks sample dataset, a simulated travel booking platform that's preloaded in every Unity Catalog-enabled workspace.
You learn how to:
- Add data sources to the canvas.
- Filter, join, aggregate, and sort data with built-in operators.
- Check each step's results in the output pane.
- Write the results to a Unity Catalog table.
Prerequisites
- A Databricks workspace with Unity Catalog enabled.
CAN USEpermission on at least one general purpose compute resource (serverless or all-purpose).USE CATALOG,USE SCHEMA, andCREATE TABLEprivileges on a schema where you can write the output table, such asmain.default.
Step 1: Create a visual data prep
- Click
New in the sidebar and select Visual data prep. Designer opens with a welcome screen.
- Click the file name at the top of the editor and rename the file to
Wanderbricks revenue. - In the compute picker next to the Schedule button, select the compute to use.
Step 2: Add the bookings data
Every visual data prep starts with one or more data sources, which the Source operator represents on the canvas.
- On the welcome screen, click Select source operator.
- In the Source configuration pane, search for
samples.wanderbricks.bookingsand select the table. A Source operator for the table appears on the canvas. - Select the Source operator. The output pane at the bottom of the editor shows a preview of the bookings data, including the
property_id,total_amount, andstatuscolumns.
You can also drag a table from the Catalog pane onto the canvas to add it as a source. For other ways to bring in data, see Ingest data into Lakeflow Designer.
Step 3: Keep only confirmed bookings
- Hover over the bookings Source operator and click the
button next to it. Select Filter. The new Filter operator is already connected to the source.
- In the Filter configuration pane, add a condition: select the
statuscolumn, select Is equal to, and enterconfirmed. - Click Apply.
- Select the Filter operator and check the output pane. The Included output contains only confirmed bookings.
The Filter operator has two outputs. Included holds the rows that meet the condition, and Excluded holds the rest. See Filter.
Step 4: Join bookings to properties
Each booking has a property_id. To group bookings by property type, join them to the properties table.
- Add a second Source operator for
samples.wanderbricks.properties. In the Operators pane, click Source, then search for and select the table. - In the Operators pane, click Join to add a Join operator.
- Connect the Included output of the Filter operator to the Join operator's first input. Then connect the properties Source operator to the Join operator's second input. To connect two operators, drag from an output port to an input port.
- In the Join configuration pane, set the join condition to match
property_idin both tables. - For Join type, select Inner join to produce a single joined output.
- Click Apply, then select the Join operator to preview the joined rows.
For more about connecting operators, see Connect operators.
Step 5: Total the revenue by property type
- Click the
button next to the Join operator and select Aggregate.
- Under Aggregate by, add two aggregations:
- Select
total_amount, selectSUM, and name the output columntotal_revenue. - Click + Add aggregation. Select
booking_id, selectCOUNT, and name the output columnbooking_count.
- Select
- Under Group by, select
property_type. - Click Apply.
Step 6: Sort the results
- Click the
button next to the Aggregate operator and select Sort.
- Select
total_revenueand DESC, then click Apply.
Step 7: Check the results
Select the Sort operator. The output pane shows one row for each property type, with the highest-earning type first.
By default, previews process a sample of the input rows, so the totals reflect only that sample. To see totals for the full dataset, click Run all in the toolbar. On the full dataset, the results show four property types, with Urban Year-Round earning the most revenue. To inspect the distribution of a column, select it and open the data profile. See Preview and refine results in Lakeflow Designer.
Step 8: Write the results to a table
- Click the
button next to the Sort operator and select Output.
- In the Output configuration pane, select Table for Output type.
- Enter
wanderbricks_revenue_by_property_typefor Table name, and select the catalog and schema for Output location, such asmain.default. - Leave Write mode set to Overwrite.
- Click Run. Designer runs the visual data prep and creates the table.
Your finished visual data prep reads two tables, filters and joins them, totals revenue by property type, and writes the result to Unity Catalog.
Optional: Try it with Genie Code
You can also build visual data preps by describing what you want. In a new visual data prep, use the Genie Code prompt above the canvas.
Tell Genie Code to do this for you:
Using samples.wanderbricks.bookings and samples.wanderbricks.properties, show total revenue and booking count by property type for confirmed bookings, highest revenue first.
Genie Code adds and connects the operators for you. Select each operator to check its configuration and results. See Use Genie Code in Lakeflow Designer.
Next steps
- To run the visual data prep on a schedule, see Schedule as a job.
- To make the visual data prep reusable across environments, see Use parameters in Lakeflow Designer.
- To learn every part of the editor, see The Lakeflow Designer interface.
- To explore all of the operators you can use, see Built-in operators in Lakeflow Designer.