Unit 7 Cloud Pipelines Notes
Writing Outputs: Tables and Delta
Learn how to save cleaned data as a reusable table — and understand why stored outputs are what dashboards, reports, and business decisions actually depend on.
Learning Objectives
- Explain why businesses save cleaned data and what happens if they do not
- Describe what an output table is and what makes a Delta table different from a regular table
- Create a cleaned dataset, register it as a SQL view, and save it as a permanent output table
- Read back from a saved table and run a business aggregation query using GROUP BY and SUM
- Explain how the output table created in this unit connects downstream to dashboards and reporting tools
Every unit so far has produced data that only existed inside an active notebook session. The moment the session ends, that data is gone. A temporary SQL view — like the ones you created in Unit 6 — lives only as long as the notebook is running. If someone opens the Databricks workspace tomorrow and tries to query sales_table, they will find nothing. Output tables change this permanently.
Imagine writing a detailed report in a word processor and never saving it. It looks perfect on your screen — until the power cuts out and everything disappears. Saving to a shared drive is the difference between work that only you can see, temporarily, and work that the whole team can access, reliably, any time they need it. Saving cleaned data to an output table is exactly this: making the result of the pipeline’s work permanently available to every tool and person downstream.
A Delta table is Databricks’ recommended format for storing output data. It is built on top of standard file storage but adds three capabilities that make it far more suitable for business pipelines than a plain CSV or temporary view.
| Feature | What It Means in Plain Language |
|---|---|
| Reliable storage | Delta tables are fault-tolerant — if a write fails halfway through, the table stays in its previous clean state rather than ending up half-written and corrupted. |
| Update support | You can update or delete specific rows in a Delta table without rewriting the entire file — the same way you edit a cell in a spreadsheet without recreating the whole document. |
| Version history | Every change to a Delta table is logged. You can query the table as it was at any previous point in time — essential for auditing and debugging. |
| Analytics performance | Delta tables are optimised for the kind of large-scale queries that dashboards and reports run — they return results much faster than reading raw files. |
In this course, you use Delta tables because they are the standard in Databricks and because they are reliable. You do not need to understand how they work internally. Think of them the way you think of a USB drive — you do not need to understand flash memory to save a file to one. The important thing is knowing when and why to use it.
Create a notebook named Unit7_Write_Output in Databricks, language Python, cluster attached. This notebook starts with already-cleaned data — the result of what Unit 6 produced. The goal now is to save that result permanently.
[“Alice”, 500, “WEST”],
[“Charlie”, 450, “NORTH”]
]
spark.createDataFrame(data, [“employee”, “sales”, “region”]) \
.createOrReplaceTempView(“clean_sales”)
This is the cleaned dataset — Bob’s row has already been removed and all region values are uppercase, exactly as Unit 6 produced. The two lines create a Spark DataFrame from the clean data and register it as a temporary SQL view named clean_sales. This view is the input to the storage step. Notice that no output appears for this cell — it is a setup step that prepares the data without displaying it.
| employee | sales | region |
|---|---|---|
| Alice | 500 | WEST |
| Charlie | 450 | NORTH |
Always preview before saving. This query confirms that the view contains exactly what you expect — two clean rows, correct column names, consistent formatting. It is a final check before writing to a permanent table. In a real pipeline, discovering an error here costs only seconds to fix. Discovering the same error after the table has been written, and dashboards have already read from it, costs far more.
SELECT * FROM clean_sales;
This is the most important cell in the unit. CREATE OR REPLACE TABLE creates a new, permanent Delta table named final_sales_output. The AS SELECT * FROM clean_sales part tells Databricks to populate it with everything from the clean view. The word REPLACE means that if a table with this name already exists — from a previous pipeline run, for example — it is overwritten with the fresh data. After this cell runs, final_sales_output exists in the Databricks Catalog as a real, persistent table. It survives after the notebook closes. Other notebooks, dashboards, and SQL tools can now query it by name at any time.
| employee | sales | region |
|---|---|---|
| Alice | 500 | WEST |
| Charlie | 450 | NORTH |
This query reads from final_sales_output — the permanent table, not the temporary view. The result looks identical to Cell 2, but the source is fundamentally different. If you closed the notebook and reopened it tomorrow, this query would still return the same rows. The temporary view from Cell 1 would be gone, but the permanent table would remain. This distinction — temporary view vs. permanent table — is what separates a notebook session from a production pipeline output.
FROM final_sales_output
GROUP BY region;
| region | total_sales |
|---|---|
| WEST | 500 |
| NORTH | 450 |
This query demonstrates exactly how a business uses a stored output table. SUM(sales) adds up all sales values. GROUP BY region tells SQL to calculate that sum separately for each region, so you get one total per region rather than one grand total. The label AS total_sales names the result column clearly for reporting. This is the kind of query a dashboard runs automatically every morning against final_sales_output to update a regional performance chart. The pipeline’s entire job — from S3 upload through cleaning to this table — exists to make this one query reliable and fast.
Every step of the pipeline — the S3 bucket, the Lambda trigger, the cleaning logic — exists to produce one thing: a clean, reliable, reusable output table. That table is what the business actually uses. It is not an intermediate result; it is the finished product. When a manager opens a dashboard at 9 AM and sees accurate regional sales figures, they are reading from a table exactly like the one you just created.
Cell 5 introduced two SQL tools that have not appeared before in this course. They are worth understanding clearly because they appear in almost every business report query.
A teacher has a register with 30 students, each belonging to one of four houses. To find out how many students are in each house, the teacher counts by group — all the Reds together, all the Blues together. That is GROUP BY: it collapses many rows into one row per group. SUM then adds up a number within each group. Together: “For each region, add up the sales figures of everyone in that region.” That is exactly what Cell 5 does.
| Keyword | What It Does | Business Use |
|---|---|---|
| SUM(column) | Adds up all the values in a column. SUM(sales) totals every sales figure in the dataset into one number. | Total revenue for the month. Total hours worked. Total units shipped. |
| GROUP BY column | Divides the rows into groups based on a column’s values, then applies the aggregation (SUM, COUNT, AVG) separately to each group. | Sales by region. Orders by customer. Costs by department. |
| AS alias | Gives the calculated result column a readable name in the output. SUM(sales) AS total_sales labels the column clearly. | Makes reports and dashboards self-explanatory without extra documentation. |
GROUP BY without an aggregation like SUM does nothing useful — you would just get one row per group with no calculation. SUM without GROUP BY gives you one grand total across the entire table. Together, they give you one calculated total per category — which is what nearly every business report in existence is trying to show.
Knowledge Check
Five questions covering Unit 7. Select the best answer for each question.
1. What is the key difference between a temporary SQL view and a permanent output table?
2. What does CREATE OR REPLACE TABLE final_sales_output AS SELECT * FROM clean_sales do?
3. In the aggregation query from Cell 5, what does GROUP BY region do?
4. Why should dashboards read from a stored output table rather than directly from the raw file?
5. A Delta table differs from a plain CSV in which important way?
Unit 7 Summary
What you covered in this unit
Permanent, queryable tables that store the cleaned results of a pipeline run — accessible to dashboards, analysts, and other pipelines at any time.
Databricks’ recommended storage format. Supports updates, version history, and fault tolerance — making it far more reliable than plain CSV files for production use.
The SQL command that writes a permanent table. Each pipeline run can replace the previous version with fresh cleaned data using this single statement.
Two SQL tools that work together to produce aggregated business reports — totalling or counting values per category, which is the foundation of most dashboards.