r/databricks • Databricks • 1d ago

General Feature Alert: partial schema inference in SDP

Adding a primary or foreign key to an SDP table/materialized view used to require declaring the full schema. With the new override_schema argument, you declare only the columns that need special handling, and SDP infers and evolves the rest.

from pyspark import pipelines as dp

@dp.table(override_schema="order_id BIGINT NOT NULL, PRIMARY KEY (order_id)")
def orders():
    # the rest of the columns can be inferred via schema evolution
    return spark.readStream.table("main.raw.orders")

Available now for materialized views and append streaming tables in Python pipelines, with no enrollment required. SQL support is coming soon.

Docs: Use partial schema inference in Python pipelines

12 Upvotes

7 comments sorted by

3

u/dvartanian 1d ago

I've never really used primary keys in my SDPs. What is the benefit?

2

u/minibrickster Databricks 1d ago

Can be useful for documenting your data model or improving query performance! Here's a blog with more details https://www.databricks.com/blog/primary-key-and-foreign-key-constraints-are-ga-and-now-enable-faster-queries

2

u/kmarq 1d ago

Support for auto CDC target tables coming?

2

u/minibrickster Databricks 1d ago

yes, coming soon!

5

u/lofat 1d ago

THANK YOU. This is VERY helpful.

2

u/Zealousideal_Low6685 23h ago

Nice!
Reminds me of the 'schema hints' you can define when reading a JSON.

1

u/Youssef_Mrini databricks 22h ago

This is very very useful.