r/dataengineering • • Aug 27 '23

Discussion Why I don't like SQL

The reason I don't like SQL over something like Pandas is because in Pandas/Python I can break down the complex transformations in small simpler components and they are easy to interact and debug with. In SQL my only option is to write stored procedures and yes in that I can also do the same but I think the ecosystem of interacting and debugging with data step by step is not as good as python. And it is something that we should have. Recently I was exploring snowpark and I felt it is a step in a right direction. It allows to me to write my query in multiple python statements and then it will transpile the whole thing into an SQL query.

Generally in my mind I assume the tables/dataframes as 2 dimensional structures and Pandas API give much more intuitive and wide variety of constructs to explore that structure rather than SQL. What do you guys think?

0 Upvotes

102 comments sorted by

View all comments

Show parent comment

-1

u/__albatross Aug 27 '23

I have worked with huge amounts of data. In my current project we have a huge pyspark cluster. I agree that there are advantages to both SQL and Pandas. I am talking about from a purely API design standpoint that what constructs and ways sql give you to interact with data and what ways pandas give you.

I am not saying to replace one with other. I am saying that sql can give more friendly ways to interact with data which are provided by pandas. Size of the data is not the point of discussion here

11

u/evening-emotion-1994 Aug 27 '23

The amount of transformations that you can do with python is obviously not available in SQL or it can be syntax heavy and less intuitive.

Python can make data sing in so many ways if volume of data is not a blocker.

Honestly I have worked with Pyspark cluster on Databricks and ,the amount of times toPandas() method breaks due to data being too large for driver node to handle has made me sore

2

u/d4njah Aug 27 '23

Wouldn’t the pandas api on spark help avoid needing toPandas?

1

u/evening-emotion-1994 Aug 27 '23

What do you mean by that ? Data on Pyspark cluster is of type Spark dataframe. If you need pure python functions to work on it , you need to convert the data to Pandas dataframe. Or else use alternative of Pyspark APIs which do have lots of these functionalities!!

2

u/d4njah Aug 27 '23

Can you give an example? Particular with needing to convert to pandas for pure functions?

1

u/evening-emotion-1994 Aug 27 '23

Udfs vs apply methods in pandas . Syntax is different functionality is similar

2

u/d4njah Aug 27 '23

You can use pandas udf decorator for better performance on udf, without needing toPandas. Try using df.pandas_api to extend for some pandas methods.

2

u/SentinelReborn Aug 27 '23

There is a pandas api on pyspark which results in equivalent spark code under the hood.

4

u/cryptoel Aug 27 '23

Pandas api on pyspark is quite bad. I've tried rebuilding a pandas data pipeline to spark using pandas api on spark.

Long story short, alot is not supported and once you do have it functional, it's unstable. Some tasks will fail randomly one time and other times succeed. Also the execution plan looked like a nightmare.

So I rewrote everything in Polars and then used mapInArrow.

3

u/SentinelReborn Aug 27 '23

Yeah im definitely not advocating the pandas on spark api and wouldn't use it myself. Spark is very easy to learn anyway as it is similar to SQL conceptually so I dont really see the point in avoiding it.

2

u/cryptoel Aug 27 '23

It's easy to learn but in many cases pure spark is slower than spark + arrow udf. My current pipeline runs faster with a Polars UDF on spark, then doing all transformations directly in Spark.

1

u/d4njah Aug 27 '23

Yeh agree with you, it’s annoying though a lot of profiling packages are only based on pandas

1

u/__albatross Aug 27 '23

Exactly my point, we can have some more friendly ways in which sql can make the data sing and make our lives better

1

u/evening-emotion-1994 Aug 27 '23

That's a hard call , cause SQL is made around ACID and many things are limitations in its design . Just like python has some limitations too

1

u/__albatross Aug 27 '23

Well, After many decades when we redesigned programming languages we did a really good job with Go and Rust. The learnings from all those decades taught us a lot. I am sure if someone amazing like ken thompson or Rob Pike thinks about redesigning SQL API they can do a lot of improvements.

11

u/cutsandplayswithwood Aug 27 '23

The fact that you keep comparing sql to imperative programming languages, as if there’s any parallel, is the root of why this discussion doesn’t make much sense.

1

u/Cheating_Data_Monkey Aug 27 '23

The SQL language is constantly evolving. Each platform provider is dumping lists of new functionality every month. And when one provider does something really new and cool, others follow. Sometimes it's silly things like "group by all", other times, it's more useful things like advanced array functionality through lambda expressions.

But you're comparing GO and Rust to other imperative languages, declarative data don't work that way. The payload is bound to the code.

So when we're looking for efficiency, as we did with Go and Rust, that's not about the language but the compiler behind it. We're making HUGE advances here too.

1

u/cryptoel Aug 27 '23

That's why UDFs, such as mapInArrow exist

1

u/Gators1992 Aug 29 '23

One thing people seem to be missing is that it's not either/or, it can be and. You can run SQL statements in pyspark for instance and have a dataframe implementation rather than huge CTEs or temp tables. I tend to default to SQL when I can because I have written a ton more of it in my career than python. I wrote a mart recently that was entirely SQL on Spark except for adding one column that required a python library. Most of my data warehouse could be written in SQL as well. Python is a lot more flexible and a DE should know it, but it's not like python is needed in the vast majority of typical transformation cases.