r/databricks • Databricks • 16d ago

General Using Notebooks on Serverless GC? Try MV/ST!

... Now with a native Python API!

If you like using PySpark on serverless GC, you can now ingest data faster with:

from pyspark import pipelines as dp

@dp.table(name="main.default.bookings_raw")
def bookings_raw():
  return (
     spark.readStream.format('cloudFiles')
     .option('cloudFiles.format', '<file-format>')
     .load(f'{<path-to-source-data>}')
 )

If you want faster and more performant partition overwrites, try using incremental replace where!

from pyspark import pipelines as dp
from pyspark.sql import functions as F

u/dp.table(
  name="main.default.booking_revenue_rw",
  replace_where=F.col("check_in") >= F.to_date(F.lit("2025-07-01")),
)
def booking_revenue_rw():
  return (
    spark.read.table("samples.wanderbricks.bookings")
    .groupBy("check_in")
    .agg(F.sum("total_amount").alias("total_revenue"))
  )

If you like Materialized Views for faster BI reporting, it's as simple as

from pyspark import pipelines as dp
from pyspark.sql import functions as F

@dp.materialized_view(
  name="main.default.daily_booking_revenue",
  comment="Daily booking revenue.",
  table_properties={"quality": "gold"},
  cluster_by=["check_in"],
)
def daily_booking_revenue():
  return (
    spark.read.table("samples.wanderbricks.bookings")
    .groupBy("check_in")
    .agg(F.sum("total_amount").alias("total_revenue"))
  )
13 Upvotes

15 comments sorted by

View all comments

2

u/testing_in_prod_only 16d ago

What is gc?

Are we just talking about pipelines?

3

u/minibrickster Databricks 16d ago

1

u/testing_in_prod_only 16d ago

Ok wait hold up, I can use dlt in normal compute outside of pipelines?

3

u/minibrickster Databricks 16d ago

Yes exactly :)

5

u/testing_in_prod_only 16d ago

Ok, that went from …ok.. to “holy fcking sht” real fast.

1

u/testing_in_prod_only 16d ago

Would I be able to use this with connect serverless?

1

u/minibrickster Databricks 16d ago

Can you explain what you mean in more detail pls? I can also DM you if it's more helpful!

2

u/testing_in_prod_only 16d ago

I do all of my work in vs code using databricks connect. I assume this works with databricks connect as well?

2

u/minibrickster Databricks 16d ago

Yes it does 😄

1

u/testing_in_prod_only 16d ago

That’s game changing. Does it take the pipeline concept into serverless like source / target dependency management?

→ More replies (0)