Hi community,
I hope you're all doing well. I'm currently engaged in a PySpark project where I'm implementing pagination-like functionality using the offset and limit functions. My aim is to retrieve data between a specified starting_index and ending_index without computing the entire dataset in memory.
Here's how I'm currently using these functions:
sliced_df = df.offset(starting_index).limit(ending_index - starting_index)
However, I'm uncertain whether this approach provides reliable results, especially considering partitioned DataFrames. The documentation doesn't offer clear guidance on how these functions behave under such circumstances.
Could someone kindly address the following questions:
- Can I trust that the offset and limit functions will consistently return data between the specified starting_index and ending_index?
- How do these functions behave when applied to partitioned DataFrames?
- Are there any best practices or considerations to ensure correct pagination when using offset and limit, particularly with partitioned DataFrames?
- Is there a recommended approach that balances speed and efficiency without computing the complete dataset in memory?
Additionally, I'd like to mention that I am using db-connect Spark session for this project.