cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to display Sparklyr table in a clean readable format similar to the output of display()?

SG_
New Contributor II

There exist a Databricksโ€™s built-in display() function (see documentation here) which allow users to display R or SparkR dataframe in a clean and human readable manner where user can scroll to see all the columns and perform sorting on the columns. See image below:

ewFTT.jpgIs there a way to display tables that are output from sparklyr in such a manner in Databricks? Obviously I am not able to use function directly on the sparklyr table hence I attempted to convert the sparklyr table into a R dataframe before using display() function but was hit with java.lang.IllegalArgumentException: Invalid type N error.

h3hff 

1 REPLY 1

rich_goldberg
New Contributor II

I found that the display() function returned this issue when it came across date-type fields that were NULL. The following function seemed to fix the problem:

library(tidyverse)
library(lubridate)
 
display_fixed = function(df) {
    df %>% 
        mutate( across( where(is.instant), ~if_else( is.na(.x), as_datetime("1900-01-01"), as_datetime(.x)) ) ) %>% 
        display()
}

Try the following in your test example:

dat2 %>% collect(n=10) %>% display_fixed()

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.