diff --git a/ADA/databricks_fundamentals.qmd b/ADA/databricks_fundamentals.qmd index 6e3e0ca..aa634f9 100644 --- a/ADA/databricks_fundamentals.qmd +++ b/ADA/databricks_fundamentals.qmd @@ -200,51 +200,4 @@ All compute options can be used both within the Databricks platform and be conne - [Setup Databricks SQL Warehouse with RStudio](/ADA/databricks_rstudio_sql_warehouse.html) - [Setup Databricks Personal Compute cluster with RStudio](/ADA/databricks_rstudio_personal_cluster.html) ---- - -### Creating a personal compute resource - ------------------------------------------------------------------------- - -1. To create your own personal compute resource click the 'Create with DfE Personal Compute' button on the compute page\ - -![](/images/ada-compute-personal.png) - -2. You'll then be presented with a screen to configure the cluster. There are 2 options here under the performance section which you will want to pay attention to; Databricks runtime version, and Node type\ - \ - **Databricks runtime version** - This is the version of the Databricks software that will be present on your compute resource. Generally it is recommended you go with the latest LTS (long term support) version. At the time of writing this is '15.4 LTS'\ - \ - **Node type** - This option determines how powerful your cluster is and there are 2 options available by default:\ - - - Standard 14GB 4-Core Nodes\ - - Large 28GB 8-Core Nodes\ - \ - If you require a larger personal cluster this can be requested by the ADA team.\ - \ - ![](/images/ada-compute-personal-create.png) - -3. Click the 'Create compute' button at the bottom of the page. This will create your personal cluster and begin starting it up. This usually takes around 5 minutes\ - \ - ![](/images/ada-compute-personal-create-button.png) - -4. Once the cluster is up and running the icon under the 'State' header on the 'Compute' page will appear as a green tick\ - \ - ![](/images/ada-compute-ready.png) - -::: callout-note -## Clusters will shut down after being idle for an hour - -Use of compute resources are charged by the hour, and so personal clusters have been set to shut down after being unused for an hour in order to prevent unnecessary cost to the Department. -::: - -::: callout-important -## Packages and libraries - -As mentioned above compute resources have no storage of their own. This means that if you install libraries or packages onto a cluster they will only remain installed until the cluster is stopped. Once re-started those libraries will need to be installed again. - -An alternative to this is to specify packages/libraries to be installed on the cluster at start up. To do this click the name of your cluster from the 'Compute' page, then go to the 'Libraries' tab and click the 'Install new' button. - -Certain packages are installed by default on personal cluster and do not need to be installed manually. The specific packages installed are based on the Databricks Runtime (DBR) version your cluster is set up with. A comprehensive list of packages included in each DBR is available in the [Databricks documentation](https://learn.microsoft.com/en-us/azure/databricks/release-notes/runtime/). -::: - Once you have a compute resource you can begin using Databricks. You can do this either through connecting to Databricks through RStudio, or you can begin coding in the Databricks platforms using scripts, or [Notebooks](/ADA/databricks_notebooks.html). diff --git a/ADA/databricks_rstudio_personal_cluster.qmd b/ADA/databricks_rstudio_personal_cluster.qmd index 64b5c14..c22f4bd 100644 --- a/ADA/databricks_rstudio_personal_cluster.qmd +++ b/ADA/databricks_rstudio_personal_cluster.qmd @@ -4,10 +4,21 @@
-The following instructions set up an ODBC connection between your laptop and your DataBricks cluster, which can then be used in R/RStudio to query data using an ODBC based package or `sparklyr`. Personal clusters are able to run SQL, R, python and scala. They can be used within the DataBricks environment, or through R studio and can be set up yourself if you don't have access to a SQL warehouse or shared cluster. +The following instructions set up an ODBC connection between your laptop and your Databricks cluster, which can then be used in RStudio to query data using an ODBC based package or `sparklyr`. Personal clusters are able to run SQL, R, Python and Scala. They can be used within the Databricks environment, or through RStudio and can be set up yourself if you don't have access to a SQL warehouse or shared cluster.
+::: callout-note + +Please note: This guidance should be followed if you wish to run R scripts from RStudio against data held against tables in Databricks, or if you wish to work with a file held in a Databricks volume. You can read more about volumes on our [Databricks fundamentals page](ADA/databricks_fundamentals.html#volumes). If you only need to run SQL scripts against Databricks data then we would suggest setting up a [SQL warehouse compute connection](/ADA/databricks_rstudio_sql_warehouse.html) instead. +::: + + +You can use data from Databricks with R code in two different ways: + +- In scripts or notebooks via the Databricks environment +- In RStudio via an ODBC connection + ------------------------------------------------------------------------ # Pre-requisites @@ -16,95 +27,214 @@ The following instructions set up an ODBC connection between your laptop and you You must have: -- Access to Databricks -- Access to a personal cluster on DataBricks +- Access to Databricks and the data you'll be working with +- Access to a personal cluster on Databricks - R and RStudio downloaded ------------------------------------------------------------------------ -# Downloading an ODBC driver +## Compute resources + +When your data is moved to Databricks, it will be stored in the Unity Catalog and you will need to use a compute resource to access it from other software such as RStudio. + +A compute resource allows you to run your code using cloud computing power instead of using your laptop's processing power. This means that using compute resources can allow your code to run faster than it would if you ran it locally, as it is like using the processing resources of multiple computers at once. On this page, we will be referring to the use of personal clusters as the compute resource to run your code. + +------------------------------------------------------------------------ + +### Personal clusters + +--- + +A personal cluster is a compute resource that supports the use of multiple code languages (R, SQL, Scala and Python). You can create your own personal cluster within the Databricks interface. + +When you set up your personal cluster, you will be asked to select a runtime for that cluster. Different runtimes allow you to use different features and package versions. Certain packages are installed by default on personal cluster and do not need to be installed manually. The specific packages installed are based on the Databricks Runtime (DBR) version your cluster is set up with. A comprehensive list of packages included in each DBR is available in the [Databricks documentation](https://learn.microsoft.com/en-us/azure/databricks/release-notes/runtime/). + +Compute resources, including personal clusters, have no storage of their own. This means that if you install libraries or packages onto a cluster they will only remain installed until the cluster is stopped. Once re-started those libraries will need to be installed again. + +An alternative to this is to specify packages/libraries to be installed on the cluster at start up. To do this click the name of your cluster from the 'Compute' page, then go to the 'Libraries' tab and click the 'Install new' button. + +::: callout-note +## Clusters will shut down after being idle for an hour + +Use of compute resources are charged by the hour, and so personal clusters have been set to shut down after being unused for an hour in order to prevent unnecessary cost to the Department. +::: + +--- + +## Process + +There are four steps to complete before your connection can be established. These are: + +- Creating a personal compute resource (if you do not already have one) +- Installing an ODBC driver on your laptop to enable a connection between your laptop and Databricks +- Modifying your .Renviron file to establish a connection between RStudio and Databricks +- Adding connection code to your existing scripts in RStudio + +--- + +### Creating a personal compute resource + +------------------------------------------------------------------------ + +1. To create your own personal compute resource click the 'Create with DfE Personal Compute' button on the compute page\ + +![](/images/ada-compute-personal.png) + +2. You'll then be presented with a screen to configure the cluster. There are 2 options here under the performance section which you will want to pay attention to; Databricks runtime version, and Node type\ + \ + **Databricks runtime version** - This is the version of the Databricks software that will be present on your compute resource. Generally it is recommended you go with the latest LTS (long term support) version. At the time of writing this is '15.4 LTS'\ + \ + **Node type** - This option determines how powerful your cluster is and there are 2 options available by default:\ + + - Standard 14GB 4-Core Nodes\ + - Large 28GB 8-Core Nodes\ + \ + If you require a larger personal cluster this can be requested by the ADA team.\ + \ + ![](/images/ada-compute-personal-create.png) + +3. Click the 'Create compute' button at the bottom of the page. This will create your personal cluster and begin starting it up. This usually takes around 5 minutes\ + \ + ![](/images/ada-compute-personal-create-button.png) + +4. Once the cluster is up and running the icon under the 'State' header on the 'Compute' page will appear as a green tick\ + \ + ![](/images/ada-compute-ready.png) + + +------------------------------------------------------------------------ + +## Setting up the ODBC driver ------------------------------------------------------------------------ -1. Install the 'Simba Spark ODBC' driver from the software centre. +::: callout-important +If you have previously set up an ODBC connection, or followed the [set up Databricks SQL Warehouse with RStudio](/ADA/databricks_rstudio_sql_warehouse.html) guidance, then you can skip this step. +::: - i) Open the Software Centre via the start menu. +- Open the Software Centre via the start menu - ii) In the 'Applications' tab, click 'Simba Spark ODBC Driver 64-bit'. ![](../images/databricks-software-centre.png) +- In the 'Applications' tab, click `Simba Spark ODBC Driver 64-bit` - iii) Click install. +::: {align="center"} +![](../images/databricks-software-centre.png) +::: -2. Get connection details for the cluster from Databricks. To set up the connection you will need a few details from your cluster within DataBricks. +- Click install - i) Login to [Databricks](https://adb-6882499576863257.17.azuredatabricks.net/?o=6882499576863257) - ii) Click on the 'Compute' tab in the sidebar. ![](../images/databricks-compute.png) +------------------------------------------------------------------------ - iii) Click on the name of the cluster you want to connect to, and click the 'Advanced options' at the bottom of the cluster page. +### Establishing an RStudio connection using environment variables - iv) Click the 'JDBC/ODBC' tab under 'Advanced options' +------------------------------------------------------------------------ - v) Make a note of the 'Server hostname', 'Port', and 'HTTP Path'. +The `ODBC` package in RStudio allows you to connect to Databricks by creating and modifying three environment variables in your .Renviron file. -3. Get a personal access token from Databricks for authentication. +::: callout-note +If you have previously established a connection between a SQL Warehouse and RStudio, then some of these variables will already be in your .Renviron file. +::: - i) In Databricks, click on your email address in the top right corner, then click 'User settings'. +To set the environment variables, call `usethis::edit_r_environ()`. You will then need to enter the following information: - ii) Go to the 'Developer' tab in the side bar. Next to 'Access tokens', click the 'Manage' button. ![](../images/databricks-access-tokens.png) +``` +DATABRICKS_HOST=