Skip to main content

Creating a Workspace

To create a new SDF Workspace, run the following command:
After running the command, you will see the following output:
Β Β Β Β CreatedΒ hello/.gitignore
Β Β Β Β CreatedΒ hello/models/main.sql
Β Β Β Β CreatedΒ hello/workspace.sdf.yml
Β 
Β Β Β Β Β Β Β Β WelcomeΒ toΒ yourΒ newΒ SDFΒ Workspace!Β ToΒ helpΒ youΒ onΒ yourΒ journey:
Β Β Β Β Β Β Β Β 
Β Β Β Β Β Β Β Β πŸ’‘Β JoinΒ theΒ SDFΒ CommunityΒ SlackΒ ->Β https://sdf.com/joinΒ 
Β Β Β Β Β Β Β Β 
Β Β Β Β Β Β Β Β πŸ“šΒ ReadΒ theΒ DocsΒ toΒ GetΒ StartedΒ ->Β https://docs.sdf.com/
Β Β Β Β Β Β Β Β 
Β Β Β FinishedΒ newΒ inΒ 0.289Β secs
You can view and modify the source code for all our examples directly in our GitHub repository.
This will create a new directory with the name of your workspace. In this case, that’s hello. The workspace will contain the following files and folder structure:
.
β”œβ”€β”€Β models
│   └── main.sql
└── workspace.sdf.yml2Β directories,Β 2Β files
The directory will contain a workspace.sdf.yml file, which is the primary configuration file for your project. It contains the following YML:
workspace:
Β Β name:Β hello
Β Β edition:Β β€œ1.3”
Β Β description:Β β€œAΒ minimalΒ workspace”  includes:
Β Β Β Β -Β path:Β models
For more on this, see our workspaces guide and for a full reference to our YML schema and more see the reference section. Lastly, our workspace contains a single model file, main.sql, which contains the following SQL:
selectΒ β€˜HelloΒ World!’ asΒ message
Next, let’s take a deeper look at your project.
SDF uses a cache to fingerprint outputs and accelerate recomputation. This cache is by default located in the sdftarget/ directory. The cache is machine specific and should not be checked in to git. An appropriate .gitignore file is created as part of the sdf new command.
We refer to SQL statements in SDF as models. Models are SQL statements that will materialized in your data warehouse, or locally with the SDF DB. They differ from tables as they can be materialized as tables, views, and more based on the configuration. Furthermore, they can be templatized with jinja and SDF SQL variables. SDF recommends specifying one model per file, as each model receives a fully qualified name (database.schema.table) that can correspond nicely to a directory structure. See our indexing documentation for more.

Exploring Your Project

Let’s see just how easy it is to set up SDF and run your first query.
1

Static Analysis with `sdf compile`

First, we’ll run the core command of SDF: sdf compile.The --show flag allows you to modulate SDF’s output and the all option indicates that we would like to see all schemas from all models referenced in the workspace.
Your output should look like:
WorkingΒ setΒ 1Β modelΒ file,Β 1Β .sdfΒ file
Β Β CompilingΒ hello.pub.mainΒ (./models/main.sql)
Β Β Β FinishedΒ 1Β modelΒ [1Β succeeded]Β inΒ 0.871Β secsSchemaΒ hello.pub.main
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Β column_name ┆ data_type        ┆ classifier ┆ descriptionΒ β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•ͺ══════════════════β•ͺ════════════β•ͺ═════════════║
β”‚Β message     ┆ varcharΒ notΒ null ┆            ┆             │
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
As you can see from the output, SDF has statically analyzed the query and determined there’s a single non-nullable column named column and it’s of type varchar. You’ll also see an empty classifier block in the output. This is for metadata we’ll attach to columns, but we’ll get to that later.
2

Create a New Model

Now, create a new file in the source directory called main2.sql with the query:
main2.sql
3

Lineage with `sdf lineage`

SDF guarantees rich column level lineage. The command below specifies a particular column, in a particular table that we would like to inspect.
WorkingΒ setΒ 2Β modelΒ files,Β 1Β .sdfΒ file
Β Β CompilingΒ hello.pub.mainΒ (./models/main.sql)
Β Β CompilingΒ hello.pub.main2Β (./models/main2.sql)
Β Β Β FinishedΒ 2Β modelsΒ [2Β succeeded]Β inΒ 0.853Β secs
hello.pub.main2.message
β”‚
β”‚Β copy
└──────┐
Β Β Β Β Β Β Β hello.pub.main.message
4

Execution with `sdf run`

Next, let’s execute the query, using SDF as the database. We’ll execute the query with SDF’s integrated execution runtime, right on your machine.
Your output should look like:
WorkingΒ setΒ 2Β modelΒ files,Β 1Β .sdfΒ file
Β Β Β Β RunningΒ hello.pub.mainΒ (./models/main.sql)
Β Β Β Β RunningΒ hello.pub.main2Β (./models/main2.sql)
Β Β Β FinishedΒ 2Β modelsΒ [2Β succeeded]Β inΒ 0.854Β secsTableΒ hello.pub.main
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Β messageΒ Β Β Β Β Β β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•‘
β”‚Β HelloΒ World!Β β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1Β rows.TableΒ hello.pub.main2
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Β messageΒ Β Β Β Β Β β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•‘
β”‚Β HelloΒ World!Β β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1Β rows.
In this guide we showed you just how easy it is to install SDF and run your first query.
If using VSCode, SDF’s YML schema is available for type and syntax checking via the Red HAT YAML. This will add auto-fill, type checking, and YML validation directly inline while editing sdf.yml files.

Tutorials

Try it yourself! Get to know the real value of SDF through our short series of tutorials

Setup SDF

Learn more about setting up SDF in your data stack