cancel
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.
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()

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group