I am working on something where I have a SQL code in place already. Now we are migrating to Azure. So I created an Azure databricks for the piece of transformation and used the same SQL code with some minor changes.
I want to know – Is there any recommended way or best practice to work with Azure databricks ?
Should we re-write the code in PySpark for the better performance?
Note : End results from the previous SQL code has no bugs. Its just that we are migrating to Azure. Instead of spending time over re-writing the code, I made use of same SQL code. Now I am looking for suggestions to understand the best practices and how it will make a difference.
Looking for your help.
Thanks !
Expecting –
Along with the migration from on prem to Azure. I am looking for some best practices for better performance.
3
Answers
After getting help on the posted question and doing some research I came up with below response --
Use Python - For heavy transformation (more complex data processing) or for analytical / machine learning purpose Use SQL - When we are dealing with relational data source (focused on querying and manipulating structured data stored in a relational database)
Note: There may be some optimization techniques in both the languages which we can use to make the performance better.
Summary : Choose language based on the use cases. Both has the distributed processing because its running on Spark cluster.
Thank you !
Under the hood, all of the code (SQL/Python/Scala, if written correctly) is executed by the same execution engine. You can always compare execution plans of SQL & Python (
EXPLAIN <query
for SQL, anddataframe.explain()
for Python) and see that they are the same for same operations.So if your SQL code is working already you may continue to use it:
But often you can get more flexibility or functionality when using Python. For example (this is not a full list):
But really, on Databricks you can usually mix & match SQL & Python code together, for example, you can expose Python code as user-defined function and call it from SQL (small example of DLT pipeline that is doing that), etc.
You asked a lot of questions there but I’ll address the one you asked in the title:
Yes.
Don’t get me wrong, I love SQL and for ad-hoc exploration it can’t be beaten. There are good, justifiable reasons, for using SQL over PySpark, but that wasn’t your question.
These are just my opinions, others may beg to differ.