|
| 1 | +--- |
| 2 | +title: "Configure the External Database Connector for Databricks" |
| 3 | +linktitle: "External Database Connector" |
| 4 | +url: /appstore/modules/databricks/external-database-connector/ |
| 5 | +description: "Describes the steps required to use the Mendix External Database connector with Databricks." |
| 6 | +weight: 10 |
| 7 | +--- |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +The [External Database connector](/appstore/modules/external-database-connector/) allows you to connect to databases and select data to use in your app. You can use it to directly test connections and queries during configuration in Studio Pro (design time). For Mendix apps that use Databricks as their database, the External Database connector is the recommended integration option for Mendix 10.20.0 and up. |
| 12 | + |
| 13 | +This how-to describes the steps required to enable your app to use the External Database connector with Databricks. |
| 14 | + |
| 15 | +## Configuring the Connection Between Your Mendix App and Databricks |
| 16 | + |
| 17 | +To connect your Mendix application to Databricks with the External Database connector, follow these steps: |
| 18 | + |
| 19 | +1. [Install the External Database connector](/appstore/modules/external-database-connector/#installation). Please make sure to use the latest version 5.1.1 or higher [External Database Connector](https://marketplace.mendix.com/link/component/219862). As an additional resource on how to use bring your own JDBC driver with the external database connector you can view [this documentation](https://docs.mendix.com/appstore/modules/external-database-connector/#byod) although this explanation is more generic than what will follow in this documentation. |
| 20 | +2. In the **Settings** of you module you can add a **Java Dependency** of the needed Databricks JDBC Driver, this way the dependency will be downloaded on running your project. To enable this you will need the following: |
| 21 | + * **Group ID** - set to **com.databricks** |
| 22 | + * **Artifact ID** - set to **databricks-jdbc** |
| 23 | + * **Version** - set to **2.7.1** |
| 24 | + |
| 25 | + {{< figure src="static/attachments/appstore/platform-supported-content/modules/databricks/JavaDependency.png" >}} |
| 26 | + |
| 27 | + Or alternatively you can download version 2.7.1 of the [JDBC driver](https://www.databricks.com/spark/jdbc-drivers-archive) that Databricks provides and put the .jar file into the userlib of your Mendix project. |
| 28 | +3. Run you Mendix project and run the [Connect to Database wizard](/appstore/modules/external-database-connector/#configuration) and select **Other** as the database type. |
| 29 | + |
| 30 | + {{< figure src="static/attachments/appstore/platform-supported-content/modules/databricks/DatabricksConfig.png" >}} |
| 31 | + |
| 32 | +4. Provide a name for the database connection document. |
| 33 | +5. As a username use "token" and as your password use the personal access token (PAT) that you can generate via the user settings in Databricks: |
| 34 | + |
| 35 | + {{< figure src="static/attachments/appstore/platform-supported-content/modules/databricks/PAT.png" >}} |
| 36 | + |
| 37 | +7. In your Databricks account find the JDBC URL related to the SQL Warehouse or Cluster you are using and copy it into the JDBC URL field and add UID=token;PWD=**PAT** where **PAT** should be replaced with your actual PAT. |
| 38 | + |
| 39 | + {{< figure src="static/attachments/appstore/platform-supported-content/modules/databricks/JDBC_URL.png" >}} |
| 40 | + |
| 41 | +9. Click **Test Connection** to verify the connection details, and then click **Save**. |
| 42 | + |
| 43 | +Your Mendix app now connects to Databricks with the provided connection details. When the connection is successful, you can see your Databricks tables in your Mendix app. |
| 44 | + |
| 45 | +{{< figure src="static/attachments/appstore/platform-supported-content/modules/databricks/Database_structure.png" >}} |
| 46 | + |
| 47 | +You can now configure the queries that you need to run on your Databricks database. The following section of this document provides an example of a common query. For general information about creating queries, see [External Database Connector: Querying a Database](/appstore/modules/external-database-connector/#query-database) and [External Database Connector: Using Query Response](/appstore/modules/external-database-connector/#use-query-response). |
| 48 | + |
| 49 | +## Configuring a Basic Query |
| 50 | + |
| 51 | +In this section we will show you a very basic example of how to use the database connector to execute a query on your Databricks data. To do this you can create some data in your Databricks workspace. Navigate to the SQL Editor in your workspace and run the folowing sql command: |
| 52 | + |
| 53 | +```sql |
| 54 | +CREATE TABLE customerData ( |
| 55 | + name varchar(64), |
| 56 | + address varchar(64), |
| 57 | + postal_code varchar(6), |
| 58 | + gender varchar(64) |
| 59 | +); |
| 60 | + |
| 61 | +INSERT INTO customerData (name, address, postal_code, gender) VALUES |
| 62 | + ('Henk de Vries', 'Klaprooslaan 5, Bloemenstad', '1234AB', 'Male'), |
| 63 | + ('Sanne Verbeek', 'Molendam 8, Waterveen', '2345CD', 'Female'), |
| 64 | + ('Jan-Willem Bos', 'Zonstraat 22, Zomerhoven', '3456EF', 'Male'), |
| 65 | + ('Marieke de Groot', 'Windmolenweg 33, Korenveld', '4567GH', 'Female'), |
| 66 | + ('Bert van Dijk', 'Vlinderplein 15, Lenteveen', '5678JK', 'Male'), |
| 67 | + ('Lotte van Dam', 'Regenboogpad 10, Kleurenburg', '6789LM', 'Female'), |
| 68 | + ('Koen Smits', 'Eikenlaan 2, Bosrijk', '7890NO', 'Male'), |
| 69 | + ('Emma Visser', 'Druppelweg 45, Regenstad', '8901QP', 'Female'), |
| 70 | + ('Thomas Mulder', 'Sterrenhof 7, Hemelrijk', '9012RS', 'Male'), |
| 71 | + ('Sophie Jansen', 'Kersenstraat 12, Fruitdorp', '0123TU', 'Female'); |
| 72 | +``` |
| 73 | +The following image shows where to find the SQL Editor in Databricks: |
| 74 | +{{< figure src="static/attachments/appstore/platform-supported-content/modules/databricks/SQL_Editor.png" >}} |
| 75 | + |
| 76 | +This should have created a table with some entries that can now be queried from your Mendix application. |
| 77 | + |
| 78 | +1. In your Mendix app, in the **App Explorer**, find and open the external connection document that you created with the Connect to Database wizard. |
| 79 | +2. In the **Name** field, enter a name for your query, for example, *CustomerData_Get*. |
| 80 | +3. Enter the following **SQL Query**: |
| 81 | + |
| 82 | + ```sql |
| 83 | + SELECT * FROM customerData |
| 84 | + ``` |
| 85 | + |
| 86 | +4. Click **Run Query**. |
| 87 | + |
| 88 | + {{< figure src="static/attachments/appstore/platform-supported-content/modules/databricks/Query.png" >}} |
| 89 | + |
| 90 | +5. Verify that the results are correct, and then generate the required entity to collect the data in your Mendix application. For more information, see [External Database Connector: Creating an Entity from the Response](/appstore/modules/external-database-connector/#create-entity). |
| 91 | +6. Create a microflow that will run the query by doing the following steps: |
| 92 | + 1. In the **App Explorer**, right-click on the name of your module, and then click **Add microflow**. |
| 93 | + 2. Enter a name for your microflow, for example, *ACT_Customerdata_Get*, and then click **OK**. |
| 94 | + 3. In your **Toolbox**, find the **Query External Database** activity and drag it onto the work area of your microflow. |
| 95 | + 4. Position the **Query External Database** activity between the start and end event of your microflow. |
| 96 | + 5. Double-click the **Query External Database** microflow activity to configure the required parameters. |
| 97 | + 6. In the **Database** section, select your Databricks database. |
| 98 | + 7. In the **Query** list, select the query name that you entered in step 2. |
| 99 | + 10. In the **Output** section, provide the following values: |
| 100 | + * **Return type** - **List of *{your module name}*.customerdata** |
| 101 | + * **Use return value** - set to **Yes** |
| 102 | + * **List name** - enter *Customerdata_list* |
| 103 | + 11. Click **OK**. |
| 104 | + |
| 105 | + {{< figure src="static/attachments/appstore/platform-supported-content/modules/databricks/JA_Query.png" >}} |
| 106 | + |
| 107 | +7. Use the microflow behind a microflow button and use the debugger to test if the objects are properly returned (or build a quick interface). |
0 commit comments