Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] feat(metadata): add table spec metadata #20477

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/content/api/modules.json.gz
Binary file not shown.
Binary file modified docs/content/api/searchindex.json.gz
Binary file not shown.
Binary file modified docs/content/api/sections.json.gz
Binary file not shown.
34 changes: 25 additions & 9 deletions docs/content/integrations/dbt/reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -571,18 +571,18 @@ def my_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource):

---

## Emit column schema as materialization metadata <Experimental />
## Emit column-level metadata as materialization metadata <Experimental />

<Note>
<strong>
Emitting column schema as materialization metadata is currently an
Emitting column-level metadata as materialization metadata is currently an
experimental feature.{" "}
</strong>{" "}
To use this feature, you'll need to be on at least `dagster==1.6.6` and
`dagster-dbt==0.22.6`.
To use this feature, you'll need to be on at least `dagster>=1.6.12` and
`dagster-dbt>=0.22.12`.
</Note>

Dagster allows you to emit column schema [materialization metadata](/concepts/assets/software-defined-assets#recording-materialization-metadata), which includes the column names and data types of your materialized dbt models, seeds, and snapshots.
Dagster allows you to emit column-level metadata, like column schema and column dependencies, as [materialization metadata](/concepts/assets/software-defined-assets#recording-materialization-metadata).

With this metadata, you can view documentation in Dagster for all columns, not just columns described in your dbt project.

Expand All @@ -595,20 +595,36 @@ packages:
revision: DAGSTER_VERSION # replace with the version of `dagster` you are using.
```

Then, enable the `dagster.log_columns_in_relation()` macro as a [post-hook](https://docs.getdbt.com/reference/resource-configs/pre-hook-post-hook) for the dbt resources that should emit column schema metadata. For example, adding the following snippet in `dbt_project.yml` enables this macro for all dbt models, seeds, and snapshots:
Then, enable the `dagster.log_column_level_metadata()` macro as a [post-hook](https://docs.getdbt.com/reference/resource-configs/pre-hook-post-hook) for the dbt resources that should emit column schema metadata. For example, adding the following snippet in `dbt_project.yml` enables this macro for all dbt models, seeds, and snapshots:

```yaml
models:
+post-hook:
- "{{ dagster.log_columns_in_relation() }}"
- "{{ dagster.log_column_level_metadata() }}"

seeds:
+post-hook:
- "{{ dagster.log_columns_in_relation() }}"
- "{{ dagster.log_column_level_metadata() }}"

snapshots:
+post-hook:
- "{{ dagster.log_columns_in_relation() }}"
- "{{ dagster.log_column_level_metadata() }}"
```

Column dependencies can be removed from materialization metadata by disabling the collection of parent relation metadata. This can be done by setting the `enable_parent_relation_metadata_collection` argument to `False` in the `dagster.log_column_level_metadata()` macro:

```yaml
models:
+post-hook:
- "{{ dagster.log_column_level_metadata(enable_parent_relation_metadata_collection=false) }}"

seeds:
+post-hook:
- "{{ dagster.log_column_level_metadata(enable_parent_relation_metadata_collection=false) }}"

snapshots:
+post-hook:
- "{{ dagster.log_column_level_metadata(enable_parent_relation_metadata_collection=false) }}"
```

---
Expand Down
Binary file modified docs/next/public/objects.inv
Binary file not shown.
2 changes: 2 additions & 0 deletions docs/sphinx/sections/api/apidocs/ops.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ All metadata types inherit from `MetadataValue`. The following types are defined

.. autoclass:: TableSchemaMetadataValue

.. autoclass:: TableSpecMetadataValue

.. autoclass:: TextMetadataValue

.. autoclass:: TimestampMetadataValue
Expand Down
14 changes: 14 additions & 0 deletions js_modules/dagster-ui/packages/ui-core/src/graphql/schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions js_modules/dagster-ui/packages/ui-core/src/graphql/types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyright/alt-1/requirements-pinned.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ asn1crypto==1.5.1
astroid==3.1.0
asttokens==2.4.1
async-lru==2.0.4
async-timeout==4.0.3
attrs==23.2.0
babel==2.14.0
backoff==2.2.1
Expand Down Expand Up @@ -256,6 +257,8 @@ snowflake-sqlalchemy==1.5.1
sortedcontainers==2.4.0
soupsieve==2.5
sqlalchemy==1.4.52
sqlglot==22.3.1
sqlglotrs==0.1.2
sqlparse==0.4.4
stack-data==0.6.3
starlette==0.37.2
Expand Down
4 changes: 4 additions & 0 deletions pyright/master/requirements-pinned.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ asn1crypto==1.5.1
-e examples/assets_pandas_pyspark
asttokens==2.4.1
async-lru==2.0.4
async-timeout==4.0.3
attrs==23.2.0
autodocsumm==0.2.12
autoflake==2.3.1
Expand Down Expand Up @@ -196,6 +197,7 @@ duckdb==0.10.1
ecdsa==0.18.0
email-validator==1.3.1
entrypoints==0.4
exceptiongroup==1.2.0
execnet==2.0.2
executing==2.0.1
expandvars==0.12.0
Expand Down Expand Up @@ -509,6 +511,8 @@ sphinxcontrib-serializinghtml==1.1.10
sqlalchemy==1.4.52
sqlalchemy-jsonfield==1.0.2
sqlalchemy-utils==0.41.1
sqlglot==22.3.1
sqlglotrs==0.1.2
sqlparse==0.4.4
sshpubkeys==3.3.1
sshtunnel==0.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from dagster._core.definitions.metadata import (
DagsterRunMetadataValue,
MetadataValue,
TableSpecMetadataValue,
)
from dagster._core.events import (
DagsterEventType,
Expand All @@ -36,6 +37,9 @@
from dagster._core.execution.plan.inputs import StepInputData
from dagster._core.execution.plan.outputs import StepOutputData

from dagster_graphql.schema.metadata import GrapheneTableSpecMetadataEntry
from dagster_graphql.schema.table import GrapheneTableSpec

MAX_INT = 2147483647
MIN_INT = -2147483648

Expand Down Expand Up @@ -165,6 +169,11 @@ def iterate_metadata_entries(metadata: Mapping[str, MetadataValue]) -> Iterator[
columns=value.schema.columns,
),
)
elif isinstance(value, TableSpecMetadataValue):
yield GrapheneTableSpecMetadataEntry(
label=key,
spec=GrapheneTableSpec(spec=value.table_spec),
)
elif isinstance(value, TimestampMetadataValue):
yield GrapheneTimestampMetadataEntry(label=key, timestamp=value.value)
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import graphene

from .asset_key import GrapheneAssetKey
from .table import GrapheneTable, GrapheneTableSchema
from .table import GrapheneTable, GrapheneTableSchema, GrapheneTableSpec


class GrapheneMetadataItemDefinition(graphene.ObjectType):
Expand Down Expand Up @@ -52,6 +52,14 @@ class Meta:
name = "TableSchemaMetadataEntry"


class GrapheneTableSpecMetadataEntry(graphene.ObjectType):
spec = graphene.NonNull(GrapheneTableSpec)

class Meta:
interfaces = (GrapheneMetadataEntry,)
name = "TableSpecMetadataEntry"


class GrapheneJsonMetadataEntry(graphene.ObjectType):
jsonString = graphene.NonNull(graphene.String)

Expand Down
27 changes: 27 additions & 0 deletions python_modules/dagster-graphql/dagster_graphql/schema/table.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import graphene

from .asset_key import GrapheneAssetKey
from .util import non_null_list


Expand Down Expand Up @@ -45,10 +46,36 @@ class Meta:
name = "Table"


class GrapheneTableColumnDep(graphene.ObjectType):
assetKey = graphene.NonNull(GrapheneAssetKey)
columnName = graphene.NonNull(graphene.String)

class Meta:
name = "TableColumnDep"


class GrapheneTableColumnSpec(graphene.ObjectType):
columnName = graphene.NonNull(graphene.String)
tableColumnDeps = non_null_list(GrapheneTableColumnDep)

class Meta:
name = "TableColumnSpec"


class GrapheneTableSpec(graphene.ObjectType):
columnSpecs = graphene.NonNull(GrapheneTableColumnSpec)

class Meta:
name = "TableSpec"


types = [
GrapheneTable,
GrapheneTableSchema,
GrapheneTableColumn,
GrapheneTableColumnConstraints,
GrapheneTableConstraints,
GrapheneTableColumnDep,
GrapheneTableColumnSpec,
GrapheneTableSpec,
]
1 change: 1 addition & 0 deletions python_modules/dagster/dagster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
PythonArtifactMetadataValue as PythonArtifactMetadataValue,
TableMetadataValue as TableMetadataValue,
TableSchemaMetadataValue as TableSchemaMetadataValue,
TableSpecMetadataValue as TableSpecMetadataValue,
TextMetadataValue as TextMetadataValue,
TimestampMetadataValue as TimestampMetadataValue,
UrlMetadataValue as UrlMetadataValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
TableRecord as TableRecord,
TableSchema as TableSchema,
TableSchemaMetadataValue as TableSchemaMetadataValue,
TableSpecMetadataValue as TableSpecMetadataValue,
TextMetadataValue as TextMetadataValue,
UrlMetadataValue as UrlMetadataValue,
)
Expand Down
Loading
Loading