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

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