Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
Showing results for 
Search instead for 
Did you mean: 

Retrieve a row from indexed spark data frame.

Valued Contributor II

Hello guys,

I'm having an issue when trying to get a row values from spark data frame.

I have a DF with index column, and i need to be able to return a row based on index in fastest way possible .

I tried to partitionBy index column, optimize with zorder on index column but its still take too much time to get a row. ( zorder didnt change a thing in table files)

to retrieve a row values take 0.5 sec ~ 4 sec

some code i tried:

row = df.where(df.index == x).collect()
row = df.where(df.index == x).take(1)

When using where does spark go on all indexes? or when its found the right one it skip all the rest?

If someone have better so i would like to know.

Thanks for you help !

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!