Preparing and querying data
DEA-C01 · Lesson 15 of 23 · 2:06:39
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the DEA-C01 exam (AWS Certified Data Engineer – Associate). In this lesson: AWS Glue DataBrew projects, recipes, recipe jobs, and profile jobs, Amazon Athena workgroups, data usage controls, query result reuse, and CTAS, views and Data Catalog views, Apache Spark in Athena notebooks, SQL aggregation with GROUP BY and grouping sets, window functions for rolling averages, and pivoting rows into columns. Includes three original practice questions.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Cleaned by hand
Every week, analysts at AnyCompany Games clean the same messy file of tournament results by hand, and each one does it differently. Their Athena queries repeat the same long joins, and nobody knows how to compute a seven-day rolling average of daily players. This lesson covers preparing data, querying with Athena, views and Spark notebooks, and aggregations.
Preparing data
AWS Glue DataBrew is a visual data preparation tool: you clean and normalize data without writing code, with more than two hundred fifty ready-made transformations. In a DataBrew project, you work on a sample of the dataset, the first five hundred rows by default, and each transformation becomes a step of a recipe. You publish the recipe as a version, then a recipe job applies it to the whole dataset and writes the output to S3, on a schedule if needed. A profile job analyzes a dataset instead, to create a profile of the data, with statistics on its columns. And SageMaker Unified Studio brings data, analytics, and machine learning tools into one interface, where a project prepares data with Visual ETL flows or notebooks.
Querying with Athena
Amazon Athena runs SQL directly on data in S3, with table definitions from the Glue Data Catalog, and you pay for the data that each query scans. So partitions, columnar formats, and selecting only the columns you need make queries both faster and cheaper. Workgroups keep teams and workloads apart, each with its own query result location, and data usage controls cancel a query that scans more than a set limit. When the data does not change often, query result reuse returns the stored result of the same query, up to a maximum age that you choose. And create table as select, or CTAS, writes the result of a query as a new table in S3, for example in Parquet and partitioned, in one step.
Views and Spark notebooks
A view is a stored query: in Athena or Redshift, create view saves a select statement, and that query runs each time someone queries the view. Views hide complexity, like long joins, expose a subset of columns, and combine tables with union all, so analysts write simpler queries. A Glue Data Catalog view gives Athena and Redshift one common view, with definer semantics: access uses the permissions of the user who created the view. A materialized view, by contrast, stores its result, as you saw with Redshift in lesson nine. And to explore data with code, Athena runs Apache Spark with no clusters to manage, in notebooks compatible with Jupyter, or from SageMaker Unified Studio notebooks.
Aggregations and windows
Aggregation summarizes many rows into one value, like a count, a sum, or an average, and group by computes it for each group, like matches per game mode. Having then filters the groups, and grouping sets, rollup, or cube compute subtotals in one query. A window function keeps every row, and adds a value computed over a window of rows, defined by partition by, order by, and a frame. For a seven-day rolling average, average the daily players over a frame of the six previous rows and the current row, ordered by day. And pivoting turns rows into columns, like one column per game mode, with pivot and unpivot in Redshift, or with one conditional aggregate per column.
Preparation at AnyCompany Games
Here is the plan at AnyCompany Games: tournament results go through a DataBrew recipe, published once, and run by a weekly recipe job. Athena queries the cleaned data in one workgroup per team, with a limit on the data that each query scans. Shared joins sit in views, and a CTAS query writes a Parquet copy of the daily summary. And the dashboard shows daily players with a seven-day rolling average, and a pivot with one column per game mode.
Recap
Let's recap. DataBrew prepares data visually, with recipes built on a sample, published as versions, and run by recipe jobs, while profile jobs describe the data. Athena queries S3 with SQL, and workgroups, data usage controls, result reuse, and CTAS keep it fast and under control. Views store queries, Data Catalog views share them across services, and Athena runs Spark in notebooks. Group by and grouping sets aggregate rows, and window functions compute rolling averages while keeping every row. And pivoting turns rows into columns.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
Analysts in one team sometimes run Athena queries that scan terabytes by mistake. The team wants queries that scan more than 100 GB to be canceled automatically. What should the data engineer configure?
- Query result reuse, with a maximum age of one hour
- A per-query data usage control in the workgroup
- A CTAS query that converts the tables to Parquet
- Partition projection on every table of the team
Show the answer
A per-query data usage control in the workgroup
A per-query data usage control in the workgroup cancels any query that scans more than the limit. “Query result reuse, with a maximum age of one hour” would return stored results for repeated queries, without limiting new ones. “A CTAS query that converts the tables to Parquet” would make queries scan less data, but nothing would stop a careless one. And “Partition projection on every table of the team” would speed up partition lookups, without canceling anything.
Analysts in three teams copy the same long join of matches, players, and payments into every Athena query, and each copy drifts a little over time. What should the data engineer create?
- A CTAS table, refreshed by hand once a month
- A separate workgroup for each of the teams
- A DataBrew recipe that cleans each table
- An Athena view that holds the shared join
Show the answer
An Athena view that holds the shared join
The view stores the join once, and every query that selects from it runs the same, current definition. “A CTAS table, refreshed by hand once a month” would copy the data, which goes stale between refreshes. “A separate workgroup for each of the teams” would separate the workloads, without sharing any query. And “A DataBrew recipe that cleans each table” would clean the data, not share a join.
A table holds one row per day with the number of active players. For each day, the product team wants the average of that day and the six days before it, while keeping every row. What should the data engineer write?
- A window AVG over the 6 preceding rows and current row
- A GROUP BY on the week number, with an AVG of players
- A PIVOT that makes one column for each day of the week
- A view that selects only the last seven rows of the table
Show the answer
A window AVG over the 6 preceding rows and current row
The window function keeps every row, and its frame averages the current day with the six days before it. “A GROUP BY on the week number, with an AVG of players” would return one row per week, not one per day. “A PIVOT that makes one column for each day of the week” would turn days into columns, without averaging anything. And “A view that selects only the last seven rows of the table” would keep only seven rows, and compute nothing.