Skip to content

Commit

Permalink
Metadata docs
Browse files Browse the repository at this point in the history
  • Loading branch information
petehunt committed Aug 22, 2024
1 parent 407ea5c commit c0d7fa0
Show file tree
Hide file tree
Showing 17 changed files with 435 additions and 933 deletions.
2 changes: 1 addition & 1 deletion docs/docs-beta/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ yarn-error.log*
*.sqlite

.pnp.*
.yarn/*
.yarn
!.yarn/patches
!.yarn/plugins
!.yarn/releases
Expand Down
Binary file removed docs/docs-beta/.yarn/install-state.gz
Binary file not shown.
925 changes: 0 additions & 925 deletions docs/docs-beta/.yarn/releases/yarn-4.4.0.cjs

This file was deleted.

6 changes: 6 additions & 0 deletions docs/docs-beta/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ Install Vale with:
brew install vale
```

or

```bash
pip install vale
```

---

## Overview of the docs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from dagster import (
CodeReferencesMetadataValue,
Definitions,
LocalFileCodeReference,
asset,
with_source_code_references,
)


@asset(
metadata={
"dagster/code_references": CodeReferencesMetadataValue(
code_references=[
LocalFileCodeReference(
file_path="/path/to/source.yaml",
# Label and line number are optional
line_number=1,
label="Model YAML",
)
]
)
}
)
def my_asset_modeled_in_yaml(): ...


defs = Definitions(
assets=with_source_code_references([my_asset_modeled_in_yaml])
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from dagster import asset, AssetSpec, MetadataValue

# You can attach metadata via the `metadata` argument on the `@asset` decorator.
@asset(metadata={
"link_to_docs": MetadataValue.url("https://..."),
"snippet": MetadataValue.md("# Embedded markdown\n...")
})
def my_asset():
...

# You can also use `metadata` with `AssetSpec`
my_external_asset = AssetSpec(
"my_external_asset",
metadata={
"link_to_docs": MetadataValue.url("https://..."),
"snippet": MetadataValue.md("# Embedded markdown\n...")
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dagster import asset, AssetSpec

# You can attach kinds via the `kinds` argument on the `@asset` decorator.
@asset(kinds=["snowflake", "dbt"])
def my_asset():
...

# You can also use `kinds` with `AssetSpec`
my_external_asset = AssetSpec(
"my_external_asset",
kinds=["snowflake", "dbt"]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
from pathlib import Path

from dagster import (
AnchorBasedFilePathMapping,
Definitions,
asset,
link_code_references_to_git,
with_source_code_references,
)


@asset
def my_asset(): ...


@asset
def another_asset(): ...


assets = with_source_code_references([my_asset, another_asset])

defs = Definitions(
assets=link_code_references_to_git(
assets_defs=assets,
git_url="https://github.com/dagster-io/dagster",
git_branch="main",
file_path_mapping=AnchorBasedFilePathMapping(
local_file_anchor=Path(__file__),
file_anchor_path_in_repository="src/repo.py",
),
)
# only link to github in production. link locally otherwise
if bool(os.getenv("IS_PRODUCTION"))
else assets
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dagster import asset, AssetSpec

# You can attach owners via the `owners` argument on the `@asset` decorator.
@asset(owners=["[email protected]", "team:data-eng"])
def my_asset():
...

# You can also use `owners` with `AssetSpec`
my_external_asset = AssetSpec(
"my_external_asset",
owners=["[email protected]", "team:roof", "team:corpdev"]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from dagster_cloud.metadata.source_code import link_code_references_to_git_if_cloud

from dagster import (
Definitions,
asset,
with_source_code_references,
)


@asset
def my_asset(): ...


@asset
def another_asset(): ...


defs = Definitions(
assets=link_code_references_to_git_if_cloud(
assets_defs=with_source_code_references([my_asset, another_asset]),
# This function also supports customizable path mapping, but usually
# the defaults are fine.
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from dagster import Definitions, asset, with_source_code_references


@asset
def my_asset(): ...


@asset
def another_asset(): ...


defs = Definitions(
# with_source_code_references() automatically attaches the proper metadata
assets=with_source_code_references([my_asset, another_asset])
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from dagster import asset, MetadataValue, MaterializeResult

@asset
def my_asset():
# Asset logic goes here
return MaterializeResult(
metadata={
# file_size_kb will be rendered as a time series
"file_size_kb": MetadataValue.int(...)
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from dagster import (
AssetKey,
MaterializeResult,
TableColumnDep,
TableColumnLineage,
asset,
)


@asset(deps=["source_bar", "source_baz"])
def my_asset():
# The following TableColumnLineage models 3 tables:
# source_bar, source_baz, and my_asset
# With the following column dependencies:
# - my_asset.new_column_foo depends on:
# - source_bar.column_bar
# - source_baz.column_baz
# - my_asset.new_column_qux depends on:
# - source_bar.column_quuz
return MaterializeResult(
metadata={
"dagster/column_lineage": TableColumnLineage(
deps_by_column={
"new_column_foo": [
TableColumnDep(
asset_key=AssetKey("source_bar"),
column_name="column_bar",
),
TableColumnDep(
asset_key=AssetKey("source_baz"),
column_name="column_baz",
),
],
"new_column_qux": [
TableColumnDep(
asset_key=AssetKey("source_bar"),
column_name="column_quuz",
),
],
}
)
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from dagster import (
MaterializeResult,
TableColumn,
TableSchema,
asset,
)


# Definition-time metadata
# Here, we know the schema of the asset, so we can attach it to the asset decorator
@asset(
deps=["source_bar", "source_baz"],
metadata={
"dagster/column_schema": TableSchema(
columns=[
TableColumn(
"name",
"string",
description="The name of the person",
),
TableColumn(
"age",
"int",
description="The age of the person",
),
]
)
},
)
def my_asset(): ...


# Runtime metadata
# Here, the schema isn't known until the asset is materialized
@asset(deps=["source_bar", "source_baz"])
def my_other_asset():
column_names = ...
column_types = ...

columns = [
TableColumn(name, column_type)
for name, column_type in zip(column_names, column_types)
]

return MaterializeResult(
metadata={
"dagster/column_schema": TableSchema(columns=columns)
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dagster import asset, AssetSpec

# You can attach tags via the `tags` argument on the `@asset` decorator.
@asset(tags={"domain": "marketing", "pii": "true"})
def my_asset():
...

# You can also use `tags` with `AssetSpec`
my_external_asset = AssetSpec(
"my_external_asset",
tags={"domain": "legal", "sensitive": ""}
)

This file was deleted.

Loading

0 comments on commit c0d7fa0

Please sign in to comment.