O'Reilly logo

Practical Predictive Analytics by Ralph Winters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Issuing SQL through the R interface

Writing SQL this way consists of constructing a valid SQL string query via the sql function:

  • The query must reference a registered table
  • You can assign the results of the query to a dataframe:

Here is an example of getting a frequency count of the available samples from the registered object out_table. Note that the code begins with %r command which is a special Databricks directive that indicates that the code that follows applies to R. However, it is sometimes necessary to specify this (even in R notebooks), when a previous code chunks has used another language directive, such as %sql, or %python.

        %r         rm(tmp)         tmp <- SparkR::sql(sqlContext, "SELECT sample_bin,   count(*) FROM out_tbl group by sample_bin") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required