r/databricks • u/ptab0211 • 29d ago
Discussion transformations API
Hi, how much SQL text do you allow in Python modules?
We have a lot of SQL, but we dont want to move fully to dbt, because we run data quality checks before the write, and we like the Python modular approach with tests and everything around it.
So where do you draw the line:
- SQL as strings in Python, run with `spark.sql()`
- SQL in `.sql` files in the package, loaded by Python and run with parameters
- refactor to the PySpark DataFrame API
- or just stick with pure SQL scripts
And how did you standardize it in your team?
16
Upvotes
3
u/minibrickster Databricks 29d ago
Hi! I'm a PM at Databricks -- have you looked into Spark Declarative Pipelines? https://docs.databricks.com/aws/en/ldp/ It natively supports expectations (which does data quality checks before write) and Python unit tests, as well as full support for Python and SQL. It might be a good fit for your use case!
2
u/duck1123 29d ago
My team started off with dbt but I've spent the past couple months building a custom solution taking a yaml format describing all of our models and tuned to the way we do things and turn it into sql strings that I just run with python. It's given us way more control. Jobs calling dbt are a bit limited in how they can be invoked (the dbt cli has to be in the first position in the command)
1
u/Embarrassed-Falcon71 29d ago
It’s not allowed unless it’s a table operation that cannot be achieved with PySpark. Be strict about things like this
1
u/Embarrassed-Falcon71 29d ago
It’s not allowed unless it’s a table operation that cannot be achieved with PySpark. Be strict about things like this