Skip to content

Commit e96b0bb

Browse files
authored
Merge pull request #6 from fhdsl/fall-2025
Fall 2025, weeks 1-2
2 parents 274774d + 38c3d58 commit e96b0bb

11 files changed

Lines changed: 399 additions & 798 deletions

concepts.qmd

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@ con <- DBI::dbConnect(duckdb::duckdb(),
2121

2222
> A database is an organized collection of structured information, or data, typically stored electronically in a computer system. A database is usually controlled by a database management system (DBMS). Together, the data and the DBMS, along with the applications that are associated with them, are referred to as a database system, often shortened to just database. - [Oracle Documentation](https://www.oracle.com/database/what-is-database/)
2323
24-
When we talk about databases, we mean the *database system* rather than database itself. Specifically, we talk about the different layers of a database system.
24+
When we talk about databases, we often mean the *database system* rather than database itself. Specifically, we talk about the different layers of a database system.
2525

2626
## Parts of a Database System
2727

2828
The [Composable Codex](https://voltrondata.com/codex/a-new-frontier#structure-of-a-composable-data-system) talks about three layers of a database system:
2929

30+
![](img/composable-data-system-modules.png) [From the Composable Codex](https://voltrondata.com/codex/a-new-frontier#building-a-new-composable-frontier)
3031

31-
![](img/composable-data-system-modules.png)
32-
[From the Composable Codex](https://voltrondata.com/codex/a-new-frontier#building-a-new-composable-frontier)
33-
34-
1. **A user interface** - how users interact with the database. In this class, our main way of interacting with databases is SQL (Structured Query Language).
35-
2. **An execution engine** - a software system that queries the data in storage. There are many examples of this: SQL Server, MariaDB, DuckDB, Snowflake. These can live on our machine, on a server within our network, or a server on the cloud.
36-
3. **Data Storage** - the physical location where the data is stored. This could be on your computer, on the network, or in the cloud (such as an Amazon S3 bucket)
32+
1. **A user interface** - how users interact with the database. In this class, our main way of interacting with databases is SQL (Structured Query Language).
33+
2. **An execution engine** - a software system that queries the data in storage. There are many examples of this: SQL Server, MariaDB, DuckDB, Snowflake. These can live on our machine, on a server within our network, or a server on the cloud.
34+
3. **Data Storage** - the physical location where the data is stored. This could be on your computer, on the network, or in the cloud (such as an Amazon S3 bucket)
3735

3836
## For this class
3937

@@ -46,7 +44,7 @@ B["2.DuckDB"] --> C
4644
C["3.File on our Machine"]
4745
```
4846

49-
::: {.callout}
47+
::: callout
5048
## Why We're Using DuckDB in this Course
5149

5250
DuckDB is a very fast, open-source database engine. Because of restrictions on clinical data, sometimes the only way to analyze it is on an approved laptop. DuckDB does wondrous things on laptops, so we hope it will be a helpful tool in your arsenal.
@@ -74,18 +72,30 @@ B["2.Databricks/Snowflake"] --> C
7472
C["3.Amazon S3"]
7573
```
7674

77-
In this case, we need to sign into the Databricks system, which is a set of systems that lives in the cloud. We actually will use SQL within their notebooks to write our queries. Databricks will then use the Snowflake engine to query the data that is stored in cloud storage (an S3 bucket).
75+
In this case, we need to sign into the Databricks system, which is a set of systems that lives in the cloud. We actually will use SQL within their notebooks to write our queries. Databricks will then use the Snowflake engine to query the data that is stored in cloud storage (an S3 bucket).
7876

7977
If this is making you dizzy, don't worry too much about it. Just know that we can switch out the different layers based on our needs.
8078

79+
## Our underlying data model
80+
81+
The three components of our Database System is dependent on our choice of the data model. Most data models are centered around **Relational Databases**. A relational database organizes data into multiple tables. Each table's row is a record with a unique ID called the key, as well as attributes described in the columns. The tables may relate to each other based on columns with the same values.
82+
83+
Below is an example **entity-relationship diagram** that summarizes relationships between tables:
84+
85+
![](img/omop1.png)
86+
87+
Each rectangle represent a table, and within each table are the columns (fields). The connecting lines shows that there are shared values between tables in those columns, which helps one navigate between tables. Don't worry if this feels foreign to you right now - we will unpack these diagrams throughout the course.
88+
89+
Other data models include **NoSQL ("Not Only SQL")**, which allows the organization of unstructured data via key-value pairs, graphs, and encoding entire documents. Another emerging data model are **Array/Matrix/Vector-based models**, which are largely focused on organizing numerical data for machine learning purposes.
90+
8191
## What is SQL?
8292

83-
SQL is short for **S**tructured **Q**uery **L**anguage. It is a standardized language for querying databases (originally relational databases)
93+
SQL is short for **S**tructured **Q**uery **L**anguage. It is a standardized language for querying relational databases.
8494

8595
SQL lets us do various operations on data. It contains various *clauses* which let us manipulate data:
8696

8797
| Priority | Clause | Purpose |
88-
| -------- | ---------- | -------------------------------------------------------------- |
98+
|------------|------------|------------------------------------------------|
8999
| 1 | `FROM` | Choose tables to query and specify how to `JOIN` them together |
90100
| 2 | `WHERE` | Filter tables based on criteria |
91101
| 3 | `GROUP BY` | Aggregates the Data |
@@ -99,15 +109,15 @@ We do not use all of these clauses when we write a SQL Query. We only use the on
99109
Oftentimes, we really only want a summary out of the database. We would probably use the following clauses:
100110

101111
| Priority | Clause | Purpose |
102-
| -------- | ---------- | -------------------------------------------------------------- |
112+
|------------|------------|------------------------------------------------|
103113
| 1 | `FROM` | Choose tables to query and specify how to `JOIN` them together |
104114
| 2 | `WHERE` | Filter tables based on criteria |
105115
| 3 | `GROUP BY` | Aggregates the Data |
106116
| 5 | `SELECT` | Selects columns in table and calculate new columns |
107117

108118
Notice that there is a **Priority** column in these tables. This is important, because parts of queries are evaluated in this order.
109119

110-
::: {.callout-note}
120+
::: callout-note
111121
## Dialects of SQL
112122

113123
You may have heard that the SQL used in SQL Server is different than other databases. In truth, there are multiple dialects of SQL, based on the engine.
@@ -119,33 +129,33 @@ However, we're focusing on the 95% of SQL that is common to all systems. Most of
119129

120130
Let's look at a typical SQL statement:
121131

122-
```sql
132+
``` sql
123133
SELECT person_id, gender_source_value # Choose Columns
124134
FROM person # Choose the person table
125135
WHERE year_of_birth < 2000; # Filter the data using a criterion
126136
```
127137

128138
We can read this as:
129139

130-
```
140+
```
131141
SELECT the person_id and gender_source_value columns
132142
FROM the person table
133143
ONLY Those with year of birth less than 2000
134144
```
135145

136146
As you can see, SQL can be read. We will gradually introduce clauses and different database operations.
137147

138-
::: {.callout-note}
148+
::: callout-note
139149
As a convention, we will capitalize SQL clauses (such as `SELECT`), and use lowercase for everything else.
140150
:::
141151

142152
## Database Connections
143153

144-
We haven't really talked about how we *connect* to the database engine.
154+
We haven't really talked about how we *connect* to the database engine.
145155

146156
In order to connect to the database engine and create a database connection, we may have to authenticate with an ID/password combo or use other methods of authentication to prove who we are.
147157

148-
Once we are authenticated, we now have a connection. This is basically our conduit to the database engine. We can *send* queries through it, and the database engine will run these queries, and **return** a result.
158+
Once we are authenticated, we now have a connection. This is basically our conduit to the database engine. We can *send* queries through it, and the database engine will run these queries, and **return** a result.
149159

150160
```{mermaid}
151161
graph LR
@@ -155,7 +165,7 @@ graph LR
155165

156166
As long as the connection is open, we can continue to send queries and receive results.
157167

158-
It is best practice to explicitly **disconnect** from the database. Once we have disconnected, we no longer have access to the database.
168+
It is best practice to explicitly **disconnect** from the database. Once we have disconnected, we no longer have access to the database.
159169

160170
```{mermaid}
161171
graph LR
@@ -175,20 +185,20 @@ SELECT * FROM person LIMIT 10;
175185

176186
Some quick terminology:
177187

178-
- **Database Record** - a row in this table. In this case, each row in the table above corresponds to a single *person*.
179-
- **Database Field** - the columns in this table. In our case, each column corresponds to a single measurement, such as `birth_datetime`. Each column has a specific datatype, which may be integers, decimals, dates, a short text field, or longer text fields. Think of them like the different pieces of information requested in a form.
188+
- **Database Record** - a row in this table. In this case, each row in the table above corresponds to a single *person*.
189+
- **Database Field** - the columns in this table. In our case, each column corresponds to a single measurement, such as `birth_datetime`. Each column has a specific datatype, which may be integers, decimals, dates, a short text field, or longer text fields. Think of them like the different pieces of information requested in a form.
180190

181-
It is faster and requires less memory if we do not use a single large table, but decompose the data up into *multiple tables*. These tables are stored in a number of different formats:
191+
It is faster and requires less memory if we do not use a single large table, but decompose the data up into *multiple tables*. These tables are stored in a number of different formats:
182192

183-
- Comma Separated Value (CSV)
184-
- A Single File (SQL Server)
185-
- a *virtual file*
193+
- Comma Separated Value (CSV)
194+
- A Single File (SQL Server)
195+
- a *virtual file*
186196

187-
In a virtual file, the data acts like it is stored in a single file, but is actually many different files underneath that can be on your machine, on the network, or on the cloud. The *virtual file* lets us interact with this large mass of data as if it is a single file.
197+
In a virtual file, the data acts like it is stored in a single file, but is actually many different files underneath that can be on your machine, on the network, or on the cloud. The *virtual file* lets us interact with this large mass of data as if it is a single file.
188198

189199
The database engine is responsible for scanning the data, either row by row, or column by column. The engines are made to be very fast in this scanning to return relevant records.
190200

191-
:::{.callout}
201+
::: callout
192202
## Rows versus Columns
193203

194204
Just a quick note about row-based storage vs column-based storage. SQL was originally written for relational databases, which are stored by row.

first-section-new-chapter.qmd

Lines changed: 0 additions & 224 deletions
This file was deleted.

img/omop1.png

136 KB
Loading

img/omop2.png

164 KB
Loading

0 commit comments

Comments
 (0)