-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdbt_masterclass.html
More file actions
1864 lines (1649 loc) · 92.9 KB
/
dbt_masterclass.html
File metadata and controls
1864 lines (1649 loc) · 92.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>dbt Masterclass — SQL Veteran's Field Guide</title>
<meta property="og:title" content="dbt Masterclass — SQL Veteran's Field Guide">
<meta property="og:description" content="Complete field guide to dbt — SQL transformations, testing, and documentation at scale.">
<meta property="og:image" content="../mathsGraph.jpg">
<meta property="og:type" content="article">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Syne:wght@400;700;800&family=JetBrains+Mono:wght@400;500;700&family=DM+Sans:wght@300;400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0c0c10;
--bg2: #13131a;
--bg3: #1a1a24;
--bg4: #22222f;
--border: #2a2a3a;
--amber: #f59e0b;
--amber-dim: #78500a;
--cyan: #06b6d4;
--cyan-dim: #0e4f5c;
--green: #22c55e;
--green-dim: #0f3d22;
--coral: #fb7185;
--coral-dim: #5c1025;
--purple: #a78bfa;
--purple-dim:#3b2878;
--text: #e2e8f0;
--text2: #94a3b8;
--text3: #475569;
--mono: 'JetBrains Mono', monospace;
--sans: 'DM Sans', sans-serif;
--display: 'Syne', sans-serif;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
background: var(--bg);
color: var(--text);
font-family: var(--sans);
font-size: 15px;
line-height: 1.7;
min-height: 100vh;
overflow-x: hidden;
}
/* ── GRID LINES BACKGROUND ── */
body::before {
content: '';
position: fixed;
inset: 0;
background-image:
linear-gradient(rgba(6,182,212,0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(6,182,212,0.03) 1px, transparent 1px);
background-size: 40px 40px;
pointer-events: none;
z-index: 0;
}
/* ── HEADER ── */
header {
position: sticky;
top: 0;
z-index: 100;
background: rgba(12,12,16,0.92);
backdrop-filter: blur(16px);
border-bottom: 1px solid var(--border);
padding: 0 2rem;
}
.header-inner {
max-width: 1400px;
margin: 0 auto;
display: flex;
align-items: center;
gap: 2rem;
height: 56px;
}
.logo {
font-family: var(--display);
font-size: 1.1rem;
font-weight: 800;
letter-spacing: -0.02em;
color: var(--amber);
white-space: nowrap;
}
.logo span { color: var(--cyan); }
nav {
display: flex;
gap: 0.25rem;
overflow-x: auto;
scrollbar-width: none;
flex: 1;
}
nav::-webkit-scrollbar { display: none; }
.nav-btn {
background: none;
border: none;
color: var(--text2);
font-family: var(--mono);
font-size: 0.72rem;
padding: 0.4rem 0.75rem;
cursor: pointer;
border-radius: 4px;
white-space: nowrap;
transition: all 0.15s;
letter-spacing: 0.03em;
}
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--amber-dim); color: var(--amber); }
.badge {
display: inline-flex;
align-items: center;
gap: 4px;
font-family: var(--mono);
font-size: 0.65rem;
padding: 2px 8px;
border-radius: 3px;
letter-spacing: 0.05em;
font-weight: 700;
}
.badge-amber { background: var(--amber-dim); color: var(--amber); }
.badge-cyan { background: var(--cyan-dim); color: var(--cyan); }
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-coral { background: var(--coral-dim); color: var(--coral); }
.badge-purple{ background: var(--purple-dim);color: var(--purple);}
/* ── LAYOUT ── */
.wrapper {
max-width: 1400px;
margin: 0 auto;
padding: 2rem;
position: relative;
z-index: 1;
}
section {
display: none;
animation: fadeUp 0.3s ease;
}
section.active { display: block; }
@keyframes fadeUp {
from { opacity: 0; transform: translateY(12px); }
to { opacity: 1; transform: translateY(0); }
}
/* ── SECTION HEADERS ── */
.section-header {
margin-bottom: 2rem;
padding-bottom: 1rem;
border-bottom: 1px solid var(--border);
}
.section-title {
font-family: var(--display);
font-size: 2rem;
font-weight: 800;
letter-spacing: -0.03em;
line-height: 1.1;
margin-bottom: 0.5rem;
}
.section-sub {
color: var(--text2);
font-size: 0.9rem;
max-width: 680px;
}
/* ── GRID LAYOUTS ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.25rem; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.5rem; }
@media (max-width: 900px) {
.grid-2, .grid-3 { grid-template-columns: 1fr; }
}
/* ── CARDS ── */
.card {
background: var(--bg2);
border: 1px solid var(--border);
border-radius: 8px;
padding: 1.5rem;
}
.card-title {
font-family: var(--display);
font-size: 1rem;
font-weight: 700;
margin-bottom: 0.75rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.card-sm { padding: 1rem 1.25rem; }
/* ── CODE BLOCKS ── */
.code-wrap {
background: #080810;
border: 1px solid var(--border);
border-radius: 6px;
overflow: hidden;
margin: 1rem 0;
position: relative;
}
.code-header {
display: flex;
align-items: center;
justify-content: space-between;
background: var(--bg3);
border-bottom: 1px solid var(--border);
padding: 0.5rem 1rem;
}
.code-filename {
font-family: var(--mono);
font-size: 0.72rem;
color: var(--text2);
letter-spacing: 0.04em;
}
.code-lang {
font-family: var(--mono);
font-size: 0.65rem;
color: var(--text3);
text-transform: uppercase;
letter-spacing: 0.1em;
}
pre {
padding: 1.25rem 1.5rem;
overflow-x: auto;
font-family: var(--mono);
font-size: 0.82rem;
line-height: 1.7;
tab-size: 2;
scrollbar-width: thin;
scrollbar-color: var(--bg4) transparent;
}
pre::-webkit-scrollbar { height: 4px; }
pre::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }
/* ── SYNTAX COLORS ── */
.kw { color: #f472b6; } /* keywords: WITH, SELECT, FROM */
.fn { color: #60a5fa; } /* functions: ref(), source() */
.st { color: #a3e635; } /* strings */
.cm { color: #4b5563; font-style: italic; } /* comments */
.jj { color: var(--amber); } /* jinja: {{ }} {% %} */
.nm { color: #c084fc; } /* names / identifiers */
.op { color: var(--cyan); } /* operators, punctuation */
.nu { color: #fb923c; } /* numbers */
.dc { color: var(--green); } /* dbt config: materialized etc */
.py { color: #fbbf24; } /* python */
/* ── CALLOUT ── */
.callout {
border-left: 3px solid;
padding: 0.75rem 1rem;
border-radius: 0 6px 6px 0;
margin: 1rem 0;
font-size: 0.88rem;
}
.callout-amber { border-color: var(--amber); background: rgba(245,158,11,0.07); color: var(--amber); }
.callout-cyan { border-color: var(--cyan); background: rgba(6,182,212,0.07); color: var(--cyan); }
.callout-green { border-color: var(--green); background: rgba(34,197,94,0.07); color: var(--green);}
.callout-coral { border-color: var(--coral); background: rgba(251,113,133,0.07);color: var(--coral);}
.callout strong { display: block; margin-bottom: 0.25rem; font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.05em; }
/* ── TABLES ── */
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th {
font-family: var(--mono);
font-size: 0.72rem;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--text3);
border-bottom: 1px solid var(--border);
padding: 0.5rem 0.75rem;
text-align: left;
}
td {
padding: 0.6rem 0.75rem;
border-bottom: 1px solid rgba(42,42,58,0.5);
vertical-align: top;
line-height: 1.5;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg3); }
td code, p code, li code {
font-family: var(--mono);
font-size: 0.8em;
background: var(--bg3);
padding: 1px 5px;
border-radius: 3px;
color: var(--cyan);
}
/* ── PILL TABS ── */
.pills {
display: flex;
gap: 0.5rem;
margin-bottom: 1.5rem;
flex-wrap: wrap;
}
.pill {
font-family: var(--mono);
font-size: 0.72rem;
padding: 0.35rem 0.9rem;
border-radius: 100px;
cursor: pointer;
border: 1px solid var(--border);
background: none;
color: var(--text2);
transition: all 0.15s;
letter-spacing: 0.03em;
}
.pill:hover { border-color: var(--cyan); color: var(--cyan); }
.pill.active { background: var(--cyan-dim); border-color: var(--cyan); color: var(--cyan); }
/* ── HERO STATS ── */
.hero-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 1rem;
margin-bottom: 2rem;
}
.hero-stat {
background: var(--bg2);
border: 1px solid var(--border);
border-radius: 6px;
padding: 1rem;
text-align: center;
}
.hero-num {
font-family: var(--display);
font-size: 1.8rem;
font-weight: 800;
line-height: 1;
margin-bottom: 0.25rem;
}
.hero-label {
font-family: var(--mono);
font-size: 0.67rem;
color: var(--text3);
letter-spacing: 0.08em;
text-transform: uppercase;
}
/* ── DAG VISUAL ── */
.dag-container {
background: #080810;
border: 1px solid var(--border);
border-radius: 8px;
padding: 2rem;
overflow-x: auto;
margin: 1rem 0;
}
.dag-node {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 14px;
border-radius: 5px;
font-family: var(--mono);
font-size: 0.75rem;
white-space: nowrap;
}
.dag-source { background: var(--cyan-dim); border: 1px solid var(--cyan); color: var(--cyan); }
.dag-model { background: var(--amber-dim); border: 1px solid var(--amber); color: var(--amber); }
.dag-mart { background: var(--purple-dim); border: 1px solid var(--purple); color: var(--purple); }
.dag-seed { background: var(--green-dim); border: 1px solid var(--green); color: var(--green); }
.dag-arrow { color: var(--text3); font-family: var(--mono); font-size: 1rem; }
.dag-row {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
flex-wrap: wrap;
}
/* ── STRATEGY CARDS ── */
.strat-card {
border: 1px solid var(--border);
border-radius: 8px;
overflow: hidden;
transition: border-color 0.15s;
}
.strat-card:hover { border-color: var(--amber); }
.strat-head {
background: var(--bg3);
padding: 0.75rem 1rem;
font-family: var(--mono);
font-size: 0.85rem;
font-weight: 700;
display: flex;
justify-content: space-between;
align-items: center;
}
.strat-body { padding: 1rem; background: var(--bg2); }
/* ── SKILL BRIDGE ── */
.bridge-row {
display: grid;
grid-template-columns: 1fr auto 1fr;
gap: 1rem;
align-items: center;
padding: 0.75rem 0;
border-bottom: 1px solid rgba(42,42,58,0.5);
}
.bridge-sql { color: var(--text2); font-family: var(--mono); font-size: 0.82rem; }
.bridge-dbt { color: var(--amber); font-family: var(--mono); font-size: 0.82rem; }
.bridge-arrow { color: var(--text3); text-align: center; }
/* ── PROFILE RING ── */
.profile-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 1rem;
margin: 1.5rem 0;
}
.skill-bar {
background: var(--bg2);
border: 1px solid var(--border);
border-radius: 6px;
padding: 1rem;
}
.skill-name {
font-family: var(--mono);
font-size: 0.75rem;
color: var(--text2);
margin-bottom: 0.5rem;
letter-spacing: 0.04em;
}
.skill-track {
height: 4px;
background: var(--bg3);
border-radius: 2px;
overflow: hidden;
}
.skill-fill {
height: 100%;
border-radius: 2px;
transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}
.skill-level {
font-family: var(--mono);
font-size: 0.65rem;
color: var(--text3);
margin-top: 0.4rem;
letter-spacing: 0.05em;
}
/* ── INTERACTIVE TABS ── */
.tab-pane { display: none; }
.tab-pane.active { display: block; }
/* ── SCROLLBAR GLOBAL ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
/* ── SEPARATOR ── */
.sep { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
/* ── PULSE DOT ── */
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
display: inline-block;
flex-shrink: 0;
}
.dot-amber { background: var(--amber); }
.dot-cyan { background: var(--cyan); }
.dot-green { background: var(--green); }
.dot-coral { background: var(--coral); }
/* ── SPECIAL HIGHLIGHT ── */
.hl { color: var(--amber); font-weight: 700; }
.hl-cyan { color: var(--cyan); }
.hl-green { color: var(--green); }
p { margin-bottom: 1rem; color: var(--text2); }
p:last-child { margin-bottom: 0; }
h3 { font-family: var(--display); font-size: 1.1rem; font-weight: 700; margin: 1.5rem 0 0.5rem; color: var(--text); }
h4 { font-family: var(--mono); font-size: 0.85rem; color: var(--text2); margin: 1rem 0 0.5rem; letter-spacing: 0.04em; }
ul { padding-left: 1.5rem; color: var(--text2); }
ul li { margin-bottom: 0.3rem; }
strong { color: var(--text); }
</style>
</head>
<body>
<nav style="font-family:'DM Mono',monospace;font-size:0.7rem;padding:8px 16px;background:#1c1a16;color:#b8b0a4;border-bottom:1px solid #333;letter-spacing:0.03em;position:sticky;top:0;z-index:9999;">
<a href="../index.html" style="color:#cc4400;text-decoration:none;">KeGG</a>
<span style="color:#555;margin:0 6px;">/</span>
<span style="color:#b8b0a4;">Masterclasses</span>
<span style="color:#555;margin:0 6px;">/</span>
<span style="color:#f2ece0;">dbt Masterclass — SQL Veteran's Field Guide</span>
</nav>
<header>
<div class="header-inner">
<div class="logo">dbt<span>.</span>masterclass</div>
<nav id="main-nav">
<button class="nav-btn active" onclick="showSection('profile', this)">⬡ Profile</button>
<button class="nav-btn" onclick="showSection('models', this)">◈ Models</button>
<button class="nav-btn" onclick="showSection('jinja', this)">⟨⟩ Jinja</button>
<button class="nav-btn" onclick="showSection('incremental', this)">⟳ Incremental</button>
<button class="nav-btn" onclick="showSection('testing', this)">✓ Testing</button>
<button class="nav-btn" onclick="showSection('snapshots', this)">⊛ Snapshots</button>
<button class="nav-btn" onclick="showSection('python', this)">⌥ Python</button>
<button class="nav-btn" onclick="showSection('patterns', this)">⬡ Patterns</button>
</nav>
</div>
</header>
<div class="wrapper">
<!-- ═══════════════════════════════════════════════
SECTION: PROFILE
════════════════════════════════════════════════ -->
<section id="profile" class="active">
<div class="section-header">
<div class="section-title">Your SQL DNA <span style="color:var(--amber)">→</span> dbt Fluency</div>
<div class="section-sub">You already know 80% of what dbt does. Let's map your existing mental models to dbt's paradigm — and surgically fill the gaps.</div>
</div>
<div class="hero-grid">
<div class="hero-stat"><div class="hero-num" style="color:var(--amber)">5</div><div class="hero-label">Materializations</div></div>
<div class="hero-stat"><div class="hero-num" style="color:var(--cyan)">∞</div><div class="hero-label">Jinja Power</div></div>
<div class="hero-stat"><div class="hero-num" style="color:var(--green)">DAG</div><div class="hero-label">Auto-lineage</div></div>
<div class="hero-stat"><div class="hero-num" style="color:var(--coral)">SCD2</div><div class="hero-label">Snapshots</div></div>
<div class="hero-stat"><div class="hero-num" style="color:var(--purple)">py</div><div class="hero-label">Python Models</div></div>
</div>
<div class="grid-2">
<div class="card">
<div class="card-title"><span class="dot dot-cyan"></span> Your Tech Profile → dbt Power Level</div>
<div class="profile-grid">
<div class="skill-bar">
<div class="skill-name">SQL / CTEs</div>
<div class="skill-track"><div class="skill-fill" style="width:95%;background:var(--amber)"></div></div>
<div class="skill-level">→ dbt models ARE CTEs</div>
</div>
<div class="skill-bar">
<div class="skill-name">NoSQL / JSON</div>
<div class="skill-track"><div class="skill-fill" style="width:80%;background:var(--cyan)"></div></div>
<div class="skill-level">→ semi-structured sources</div>
</div>
<div class="skill-bar">
<div class="skill-name">Docker</div>
<div class="skill-track"><div class="skill-fill" style="width:75%;background:var(--green)"></div></div>
<div class="skill-level">→ dbt Cloud / Airflow</div>
</div>
<div class="skill-bar">
<div class="skill-name">Cloud (AWS/GCP)</div>
<div class="skill-track"><div class="skill-fill" style="width:80%;background:var(--purple)"></div></div>
<div class="skill-level">→ BigQuery/Redshift targets</div>
</div>
<div class="skill-bar">
<div class="skill-name">Python</div>
<div class="skill-track"><div class="skill-fill" style="width:85%;background:var(--coral)"></div></div>
<div class="skill-level">→ Python models, macros</div>
</div>
<div class="skill-bar">
<div class="skill-name">dbt Core</div>
<div class="skill-track"><div class="skill-fill" style="width:45%;background:var(--amber)"></div></div>
<div class="skill-level">→ what we're fixing today</div>
</div>
</div>
</div>
<div class="card">
<div class="card-title"><span class="dot dot-amber"></span> SQL Veteran → dbt Translation</div>
<div class="bridge-row">
<div class="bridge-sql">CREATE OR REPLACE VIEW</div>
<div class="bridge-arrow">→</div>
<div class="bridge-dbt"><code>materialized='view'</code></div>
</div>
<div class="bridge-row">
<div class="bridge-sql">CREATE TABLE AS SELECT</div>
<div class="bridge-arrow">→</div>
<div class="bridge-dbt"><code>materialized='table'</code></div>
</div>
<div class="bridge-row">
<div class="bridge-sql">INSERT INTO ... WHERE date > ?</div>
<div class="bridge-arrow">→</div>
<div class="bridge-dbt"><code>materialized='incremental'</code></div>
</div>
<div class="bridge-row">
<div class="bridge-sql">MERGE INTO (SCD Type 2)</div>
<div class="bridge-arrow">→</div>
<div class="bridge-dbt"><code>snapshot</code> block</div>
</div>
<div class="bridge-row">
<div class="bridge-sql">SELECT * FROM schema.table</div>
<div class="bridge-arrow">→</div>
<div class="bridge-dbt"><code>{{ ref('model_name') }}</code></div>
</div>
<div class="bridge-row">
<div class="bridge-sql">External / raw table</div>
<div class="bridge-arrow">→</div>
<div class="bridge-dbt"><code>{{ source('schema','table') }}</code></div>
</div>
<div class="bridge-row">
<div class="bridge-sql">Stored procedure / UDF</div>
<div class="bridge-arrow">→</div>
<div class="bridge-dbt">macro in <code>macros/</code></div>
</div>
<div class="bridge-row">
<div class="bridge-sql">Static lookup CSV</div>
<div class="bridge-arrow">→</div>
<div class="bridge-dbt">seed in <code>seeds/</code></div>
</div>
<div class="bridge-row">
<div class="bridge-sql">WITH cte AS (SELECT ...)</div>
<div class="bridge-arrow">→</div>
<div class="bridge-dbt">ephemeral model</div>
</div>
<div class="bridge-row">
<div class="bridge-sql">Data contract / expectation</div>
<div class="bridge-arrow">→</div>
<div class="bridge-dbt"><code>dbt test</code> schema tests</div>
</div>
</div>
</div>
<hr class="sep">
<h3>The dbt Project Anatomy</h3>
<div class="grid-3">
<div class="card card-sm">
<div class="card-title"><span class="badge badge-cyan">sources</span></div>
<p>Raw ingested data. You declare these in <code>schema.yml</code> files, <em>not</em> create them. Think: Fivetran landing zone, Airbyte raw tables, Kafka-to-S3 dumps.</p>
</div>
<div class="card card-sm">
<div class="card-title"><span class="badge badge-amber">models</span></div>
<p>SQL (or Python) <code>SELECT</code> statements. Each file = one relation in your warehouse. dbt resolves dependencies automatically via <code>ref()</code>.</p>
</div>
<div class="card card-sm">
<div class="card-title"><span class="badge badge-green">seeds</span></div>
<p>CSV files checked into git. <code>dbt seed</code> loads them. Perfect for country codes, category maps, static cost tables.</p>
</div>
<div class="card card-sm">
<div class="card-title"><span class="badge badge-purple">macros</span></div>
<p>Jinja functions that generate SQL. Reusable logic. Cross-project via packages. Think SQL templating on steroids.</p>
</div>
<div class="card card-sm">
<div class="card-title"><span class="badge badge-coral">snapshots</span></div>
<p>Type-2 SCDs, automated. Point at a source, define uniqueness + change detection strategy, dbt handles the <code>valid_from</code> / <code>valid_to</code> bookkeeping.</p>
</div>
<div class="card card-sm">
<div class="card-title"><span class="badge badge-amber">tests</span></div>
<p>Assertions on your data. Four built-in generic tests. Unlimited custom SQL tests. Package extensions like <code>dbt_expectations</code> give you 50+ more.</p>
</div>
</div>
<!-- DAG VISUAL -->
<h3>Live DAG — The Ingress Pipeline You're Building</h3>
<div class="dag-container">
<div class="dag-row">
<span class="dag-node dag-source">⬡ src_postgres.orders</span>
<span class="dag-arrow">──▶</span>
<span class="dag-node dag-model">stg_orders</span>
<span class="dag-arrow">──▶</span>
<span class="dag-node dag-model">int_orders_enriched</span>
<span class="dag-arrow">──▶</span>
<span class="dag-node dag-mart">mart_revenue</span>
</div>
<div class="dag-row">
<span class="dag-node dag-source">⬡ src_kafka.events</span>
<span class="dag-arrow">──▶</span>
<span class="dag-node dag-model">stg_events</span>
<span class="dag-arrow">──▶</span>
<span class="dag-node dag-model">int_orders_enriched</span>
</div>
<div class="dag-row">
<span class="dag-node dag-source">⬡ src_s3.customers</span>
<span class="dag-arrow">──▶</span>
<span class="dag-node dag-model">stg_customers</span>
<span class="dag-arrow">──▶</span>
<span class="dag-node dag-model">int_orders_enriched</span>
</div>
<div class="dag-row">
<span class="dag-node dag-seed">✦ seed: country_codes</span>
<span class="dag-arrow">──▶</span>
<span class="dag-node dag-model">stg_customers</span>
</div>
<div class="dag-row">
<span class="dag-node dag-mart">mart_revenue</span>
<span class="dag-arrow">──▶</span>
<span class="dag-node dag-mart">mart_revenue_daily</span>
</div>
</div>
<p style="font-size:0.8rem;font-family:var(--mono);color:var(--text3)">Each arrow is a <code>ref()</code> or <code>source()</code> call. dbt resolves execution order and builds the DAG automatically.</p>
</section>
<!-- ═══════════════════════════════════════════════
SECTION: MODELS
════════════════════════════════════════════════ -->
<section id="models">
<div class="section-header">
<div class="section-title">Models <span style="color:var(--amber)">&</span> Materializations</div>
<div class="section-sub">The five materializations, when to reach for each, and the config patterns that unlock them.</div>
</div>
<div class="pills" id="mat-pills">
<button class="pill active" onclick="showTab('mat','view',this)">view</button>
<button class="pill" onclick="showTab('mat','table',this)">table</button>
<button class="pill" onclick="showTab('mat','incremental',this)">incremental</button>
<button class="pill" onclick="showTab('mat','ephemeral',this)">ephemeral</button>
<button class="pill" onclick="showTab('mat','materialized_view',this)">materialized_view</button>
</div>
<!-- VIEW -->
<div id="mat-view" class="tab-pane active">
<div class="grid-2">
<div>
<div class="callout callout-cyan">
<strong>WHEN TO USE</strong>
Staging models, rarely-queried transformations, alias layers. Zero storage cost. Freshest data always.
</div>
<div class="code-wrap">
<div class="code-header">
<span class="code-filename">models/staging/stg_orders.sql</span>
<span class="code-lang">sql + jinja</span>
</div>
<pre><span class="jj">{{</span>
<span class="fn">config</span>(
<span class="dc">materialized</span> <span class="op">=</span> <span class="st">'view'</span>,
<span class="dc">schema</span> <span class="op">=</span> <span class="st">'staging'</span>,
<span class="dc">tags</span> <span class="op">=</span> [<span class="st">'staging'</span>, <span class="st">'orders'</span>]
)
<span class="jj">}}</span>
<span class="kw">with</span> source <span class="kw">as</span> (
<span class="kw">select</span> <span class="op">*</span>
<span class="kw">from</span> <span class="jj">{{</span> <span class="fn">source</span>(<span class="st">'postgres'</span>, <span class="st">'orders'</span>) <span class="jj">}}</span>
),
renamed <span class="kw">as</span> (
<span class="kw">select</span>
<span class="cm">-- rename & cast at the boundary</span>
order_id <span class="kw">as</span> order_id,
customer_id <span class="kw">as</span> customer_id,
<span class="fn">cast</span>(created_at <span class="kw">as</span> timestamp) <span class="kw">as</span> created_at,
<span class="fn">upper</span>(status) <span class="kw">as</span> status,
amount <span class="op">/</span> <span class="nu">100.0</span> <span class="kw">as</span> amount_dollars,
_fivetran_synced <span class="kw">as</span> _loaded_at
<span class="kw">from</span> source
)
<span class="kw">select</span> <span class="op">*</span> <span class="kw">from</span> renamed</pre>
</div>
</div>
<div>
<div class="callout callout-amber">
<strong>PRO INSIGHT: THE STAGING CONTRACT</strong>
Staging models are your boundary. They rename, cast, and clean — nothing else. No joins. No business logic. This keeps your raw layer queryable independently and makes upstream schema changes a one-file fix.
</div>
<div class="code-wrap">
<div class="code-header">
<span class="code-filename">models/staging/schema.yml</span>
<span class="code-lang">yaml</span>
</div>
<pre><span class="dc">sources</span>:
<span class="op">-</span> <span class="dc">name</span>: <span class="st">postgres</span>
<span class="dc">database</span>: <span class="st">raw</span>
<span class="dc">schema</span>: <span class="st">public</span>
<span class="dc">loaded_at_field</span>: <span class="st">_fivetran_synced</span>
<span class="dc">freshness</span>:
<span class="dc">warn_after</span>: {<span class="dc">count</span>: <span class="nu">1</span>, <span class="dc">period</span>: <span class="st">hour</span>}
<span class="dc">error_after</span>: {<span class="dc">count</span>: <span class="nu">6</span>, <span class="dc">period</span>: <span class="st">hour</span>}
<span class="dc">tables</span>:
<span class="op">-</span> <span class="dc">name</span>: <span class="st">orders</span>
<span class="dc">description</span>: <span class="st">"Raw orders from Postgres via Fivetran"</span>
<span class="dc">columns</span>:
<span class="op">-</span> <span class="dc">name</span>: <span class="st">order_id</span>
<span class="dc">description</span>: <span class="st">"PK — UUID"</span>
<span class="dc">tests</span>:
<span class="op">-</span> <span class="st">not_null</span>
<span class="op">-</span> <span class="st">unique</span></pre>
</div>
<p>Run <code>dbt source freshness</code> to alert when sources go stale — critical for ingress monitoring.</p>
</div>
</div>
</div>
<!-- TABLE -->
<div id="mat-table" class="tab-pane">
<div class="grid-2">
<div>
<div class="callout callout-amber">
<strong>WHEN TO USE</strong>
Heavy aggregations, mart-layer models, anything downstream dashboards hammer. Pays compute once, serves reads infinitely.
</div>
<div class="code-wrap">
<div class="code-header">
<span class="code-filename">models/marts/mart_revenue.sql</span>
<span class="code-lang">sql + jinja</span>
</div>
<pre><span class="jj">{{</span>
<span class="fn">config</span>(
<span class="dc">materialized</span> <span class="op">=</span> <span class="st">'table'</span>,
<span class="dc">schema</span> <span class="op">=</span> <span class="st">'marts'</span>,
<span class="dc">dist</span> <span class="op">=</span> <span class="st">'customer_id'</span>, <span class="cm">-- Redshift</span>
<span class="dc">sort</span> <span class="op">=</span> [<span class="st">'order_date'</span>], <span class="cm">-- Redshift</span>
<span class="cm">-- BigQuery equivalent:</span>
<span class="dc">partition_by</span> <span class="op">=</span> {
<span class="st">'field'</span>: <span class="st">'order_date'</span>,
<span class="st">'data_type'</span>: <span class="st">'date'</span>,
<span class="st">'granularity'</span>: <span class="st">'day'</span>
},
<span class="dc">cluster_by</span> <span class="op">=</span> [<span class="st">'customer_id'</span>, <span class="st">'status'</span>]
)
<span class="jj">}}</span>
<span class="kw">with</span> orders <span class="kw">as</span> (
<span class="kw">select</span> <span class="op">*</span> <span class="kw">from</span> <span class="jj">{{</span> <span class="fn">ref</span>(<span class="st">'int_orders_enriched'</span>) <span class="jj">}}</span>
),
daily_revenue <span class="kw">as</span> (
<span class="kw">select</span>
<span class="fn">date_trunc</span>(<span class="st">'day'</span>, created_at) <span class="kw">as</span> order_date,
customer_id,
status,
<span class="fn">count</span>(<span class="op">*</span>) <span class="kw">as</span> order_count,
<span class="fn">sum</span>(amount_dollars) <span class="kw">as</span> gross_revenue,
<span class="fn">sum</span>(amount_dollars)
<span class="fn">filter</span> (<span class="kw">where</span> status <span class="op">=</span> <span class="st">'COMPLETED'</span>)
<span class="kw">as</span> net_revenue
<span class="kw">from</span> orders
<span class="kw">group by</span> <span class="nu">1</span>, <span class="nu">2</span>, <span class="nu">3</span>
)
<span class="kw">select</span> <span class="op">*</span> <span class="kw">from</span> daily_revenue</pre>
</div>
</div>
<div>
<div class="callout callout-green">
<strong>WAREHOUSE-NATIVE OPTIMISATION</strong>
dbt passes <code>partition_by</code> and <code>cluster_by</code> directly to BigQuery DDL. On Redshift, <code>dist</code> and <code>sort</code> control physical layout. Know your warehouse, inject it here.
</div>
<h4>Table vs View Decision Matrix</h4>
<table>
<thead><tr><th>Factor</th><th>→ View</th><th>→ Table</th></tr></thead>
<tbody>
<tr><td>Query frequency</td><td>Low / ad-hoc</td><td>High / BI tool</td></tr>
<tr><td>Transform cost</td><td>Cheap scans</td><td>Expensive aggregation</td></tr>
<tr><td>Data freshness</td><td>Always live</td><td>As-of last <code>dbt run</code></td></tr>
<tr><td>Storage cost</td><td>Zero</td><td>Full duplication</td></tr>
<tr><td>Downstream joins</td><td>Re-compute each time</td><td>Indexes / partitions help</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- INCREMENTAL -->
<div id="mat-incremental" class="tab-pane">
<div class="callout callout-amber">
<strong>CLICK → Incremental section for the full deep-dive</strong>
This tab covers the basics. The Incremental section in the nav covers merge strategies, late-arriving data, and the <code>--full-refresh</code> escape hatch.
</div>
<div class="code-wrap">
<div class="code-header">
<span class="code-filename">models/staging/stg_events.sql</span>
<span class="code-lang">incremental basics</span>
</div>
<pre><span class="jj">{{</span>
<span class="fn">config</span>(
<span class="dc">materialized</span> <span class="op">=</span> <span class="st">'incremental'</span>,
<span class="dc">unique_key</span> <span class="op">=</span> <span class="st">'event_id'</span>,
<span class="dc">on_schema_change</span> <span class="op">=</span> <span class="st">'sync_all_columns'</span>
)
<span class="jj">}}</span>
<span class="kw">select</span>
event_id,
user_id,
event_type,
event_ts,
properties
<span class="kw">from</span> <span class="jj">{{</span> <span class="fn">source</span>(<span class="st">'kafka'</span>, <span class="st">'events'</span>) <span class="jj">}}</span>
<span class="jj">{%</span> <span class="kw">if</span> <span class="fn">is_incremental</span>() <span class="jj">%}</span>
<span class="kw">where</span> event_ts <span class="op">></span> (<span class="kw">select</span> <span class="fn">max</span>(event_ts) <span class="kw">from</span> <span class="jj">{{</span> <span class="fn">this</span> <span class="jj">}}</span>)
<span class="jj">{%</span> <span class="kw">endif</span> <span class="jj">%}</span></pre>
</div>
<p><code>{{ this }}</code> is the relation reference to the model's own table in the warehouse — the magic that makes incremental work. <code>is_incremental()</code> returns <code>false</code> on first run (full load) and <code>true</code> on subsequent runs.</p>
</div>
<!-- EPHEMERAL -->
<div id="mat-ephemeral" class="tab-pane">
<div class="grid-2">
<div>
<div class="callout callout-purple">
<strong>EPHEMERAL = CTE-AS-A-FILE</strong>
Ephemeral models are inlined as CTEs into whatever model references them. They create zero warehouse objects — pure compile-time substitution. Think: shared logic extracted into its own file.
</div>
<div class="code-wrap">
<div class="code-header">
<span class="code-filename">models/intermediate/_int_exchange_rates.sql</span>
<span class="code-lang">ephemeral</span>
</div>
<pre><span class="jj">{{</span> <span class="fn">config</span>(<span class="dc">materialized</span><span class="op">=</span><span class="st">'ephemeral'</span>) <span class="jj">}}</span>
<span class="cm">-- This file creates NO table/view in the warehouse.
-- It's inlined as a CTE wherever ref() is called.</span>
<span class="kw">select</span>
currency_code,
rate_to_usd,
<span class="fn">date_trunc</span>(<span class="st">'day'</span>, valid_from) <span class="kw">as</span> rate_date
<span class="kw">from</span> <span class="jj">{{</span> <span class="fn">ref</span>(<span class="st">'stg_exchange_rates'</span>) <span class="jj">}}</span>
<span class="kw">where</span> is_current <span class="op">=</span> <span class="kw">true</span></pre>
</div>
</div>
<div>
<h4>What dbt compiles to:</h4>
<div class="code-wrap">
<div class="code-header"><span class="code-filename">compiled SQL (auto-generated)</span><span class="code-lang">compiled</span></div>
<pre><span class="cm">-- dbt inlines the ephemeral as a CTE:</span>
<span class="kw">with</span> __dbt__cte__int_exchange_rates <span class="kw">as</span> (
<span class="kw">select</span>
currency_code,
rate_to_usd,
<span class="fn">date_trunc</span>(<span class="st">'day'</span>, valid_from) <span class="kw">as</span> rate_date
<span class="kw">from</span> raw.public.exchange_rates
<span class="kw">where</span> is_current <span class="op">=</span> <span class="kw">true</span>
),
your_model_cte <span class="kw">as</span> (
<span class="kw">select</span>
o.amount_dollars <span class="op">*</span> fx.rate_to_usd <span class="kw">as</span> amount_usd
<span class="kw">from</span> orders o
<span class="kw">join</span> __dbt__cte__int_exchange_rates fx <span class="kw">using</span> (currency_code)
)
<span class="kw">select</span> <span class="op">*</span> <span class="kw">from</span> your_model_cte</pre>
</div>
<div class="callout callout-coral">
<strong>GOTCHA</strong>
Ephemeral models can't be <code>ref()</code>'d from <em>other</em> ephemeral models more than ~3 levels deep before the CTE stack explodes. Use a view instead when the chain gets long.
</div>
</div>
</div>
</div>
<!-- MATERIALIZED VIEW -->
<div id="mat-materialized_view" class="tab-pane">
<div class="callout callout-green">
<strong>dbt 1.6+ — Native Materialized View Support</strong>
Warehouse-native MVs (BigQuery, Snowflake, Redshift, Postgres 9.3+). Automatically refreshed by the warehouse engine. dbt manages the DDL; you write the SELECT.
</div>
<div class="code-wrap">
<div class="code-header">
<span class="code-filename">models/marts/mv_active_sessions.sql</span>
<span class="code-lang">materialized_view</span>
</div>
<pre><span class="jj">{{</span>
<span class="fn">config</span>(
<span class="dc">materialized</span> <span class="op">=</span> <span class="st">'materialized_view'</span>,
<span class="cm">-- Snowflake: target_lag controls refresh frequency</span>
<span class="dc">target_lag</span> <span class="op">=</span> <span class="st">'1 minute'</span>,
<span class="dc">snowflake_warehouse</span> <span class="op">=</span> <span class="st">'TRANSFORMING'</span>
)
<span class="jj">}}</span>
<span class="cm">-- The warehouse keeps this fresh automatically.
-- dbt run detects drift and issues ALTER/REPLACE DDL.</span>
<span class="kw">select</span>
session_id,
user_id,
<span class="fn">max</span>(event_ts) <span class="kw">as</span> last_activity,
<span class="fn">count</span>(<span class="op">*</span>) <span class="kw">as</span> event_count
<span class="kw">from</span> <span class="jj">{{</span> <span class="fn">ref</span>(<span class="st">'stg_events'</span>) <span class="jj">}}</span>
<span class="kw">where</span> event_ts <span class="op">></span> <span class="fn">current_timestamp</span>() <span class="op">-</span> <span class="fn">interval</span> <span class="st">'24 hours'</span>
<span class="kw">group by</span> <span class="nu">1</span>, <span class="nu">2</span></pre>
</div>
</div>
</section>
<!-- ═══════════════════════════════════════════════
SECTION: JINJA
════════════════════════════════════════════════ -->
<section id="jinja">
<div class="section-header">
<div class="section-title">Jinja Macros <span style="color:var(--amber)">—</span> SQL Metaprogramming</div>
<div class="section-sub">Where dbt goes from "SQL runner" to "SQL compiler". Macros are Jinja functions that generate SQL — write the generator once, never write boilerplate again.</div>
</div>
<div class="grid-2">