|
| 1 | +--- |
| 2 | +title: Hive Warehouse Connector - Apache Zeppelin using Livy - Azure HDInsight |
| 3 | +description: Learn how to integrate Hive Warehouse Connector with Apache Zeppelin on Azure HDInsight. |
| 4 | +author: nis-goel |
| 5 | +ms.author: nisgoel |
| 6 | +ms.reviewer: jasonh |
| 7 | +ms.service: hdinsight |
| 8 | +ms.topic: conceptual |
| 9 | +ms.date: 05/22/2020 |
| 10 | +--- |
| 11 | + |
| 12 | +# Integrate Apache Zeppelin with Hive Warehouse Connector in Azure HDInsight |
| 13 | + |
| 14 | +HDInsight Spark clusters include Apache Zeppelin notebooks with different interpreters. In this article, we'll focus only on the Livy interpreter to access Hive tables from Spark using Hive Warehouse Connector. |
| 15 | + |
| 16 | +## Prerequisite |
| 17 | + |
| 18 | +Complete the [Hive Warehouse Connector setup](apache-hive-warehouse-connector.md#hive-warehouse-connector-setup) steps. |
| 19 | + |
| 20 | +## Getting started |
| 21 | + |
| 22 | +1. Use [ssh command](../hdinsight-hadoop-linux-use-ssh-unix.md) to connect to your Apache Spark cluster. Edit the command below by replacing CLUSTERNAME with the name of your cluster, and then enter the command: |
| 23 | + |
| 24 | + ```cmd |
| 25 | + |
| 26 | + ``` |
| 27 | +
|
| 28 | +1. From your ssh session, execute the following command to note the versions for `hive-warehouse-connector-assembly` and `pyspark_hwc`: |
| 29 | +
|
| 30 | + ```bash |
| 31 | + ls /usr/hdp/current/hive_warehouse_connector |
| 32 | + ``` |
| 33 | +
|
| 34 | + Save the output for later use when configuring Apache Zeppelin. |
| 35 | +
|
| 36 | +## Configure Livy |
| 37 | +
|
| 38 | +Following configurations are required to access hive tables from Zeppelin with the Livy interpreter. |
| 39 | +
|
| 40 | +### Interactive Query Cluster |
| 41 | +
|
| 42 | +1. From a web browser, navigate to `https://LLAPCLUSTERNAME.azurehdinsight.net/#/main/services/HDFS/configs` where LLAPCLUSTERNAME is the name of your Interactive Query cluster. |
| 43 | +
|
| 44 | +1. Navigate to **Advanced** > **Custom core-site**. Select **Add Property...** to add the following configurations: |
| 45 | +
|
| 46 | + | Configuration | Value | |
| 47 | + | ----------------------------- |-------| |
| 48 | + | hadoop.proxyuser.livy.groups | * | |
| 49 | + | hadoop.proxyuser.livy.hosts | * | |
| 50 | +
|
| 51 | +1. Save changes and restart all affected components. |
| 52 | +
|
| 53 | +### Spark Cluster |
| 54 | +
|
| 55 | +1. From a web browser, navigate to `https://CLUSTERNAME.azurehdinsight.net/#/main/services/SPARK2/configs` where CLUSTERNAME is the name of your Apache Spark cluster. |
| 56 | +
|
| 57 | +1. Expand **Custom livy2-conf**. Select **Add Property...** to add the following configuration: |
| 58 | +
|
| 59 | + | Configuration | Value | |
| 60 | + | ----------------------------- |------------------------------------------ | |
| 61 | + | livy.file.local-dir-whitelist | /usr/hdp/current/hive_warehouse_connector/ | |
| 62 | +
|
| 63 | +1. Save changes and restart all affected components. |
| 64 | +
|
| 65 | +### Configure Livy Interpreter in Zeppelin UI (Spark Cluster) |
| 66 | +
|
| 67 | +1. From a web browser, navigate to `https://CLUSTERNAME.azurehdinsight.net/zeppelin/#/interpreter`, where `CLUSTERNAME` is the name of your Apache Spark cluster. |
| 68 | +
|
| 69 | +1. Navigate to **livy2**. |
| 70 | +
|
| 71 | +1. Add the following configurations: |
| 72 | +
|
| 73 | + | Configuration | Value | |
| 74 | + | ----------------------------- |:------------------------------------------:| |
| 75 | + | livy.spark.hadoop.hive.llap.daemon.service.hosts | @llap0 | |
| 76 | + | livy.spark.security.credentials.hiveserver2.enabled | true | |
| 77 | + | livy.spark.sql.hive.llap | true | |
| 78 | + | livy.spark.yarn.security.credentials.hiveserver2.enabled | true | |
| 79 | + | livy.superusers | livy,zeppelin | |
| 80 | + | livy.spark.jars | `file:///usr/hdp/current/hive_warehouse_connector/hive-warehouse-connector-assembly-VERSION.jar`.<br>Replace VERSION with value you obtained from [Getting started](#getting-started), earlier. | |
| 81 | + | livy.spark.submit.pyFiles | `file:///usr/hdp/current/hive_warehouse_connector/pyspark_hwc-VERSION.zip`.<br>Replace VERSION with value you obtained from [Getting started](#getting-started), earlier. | |
| 82 | + | livy.spark.sql.hive.hiveserver2.jdbc.url | Set it to the HiveServer2 Interactive JDBC URL of the Interactive Query cluster. | |
| 83 | + | spark.security.credentials.hiveserver2.enabled | true | |
| 84 | +
|
| 85 | +1. For ESP clusters only, add the following configuration: |
| 86 | +
|
| 87 | + | Configuration| Value| |
| 88 | + |---|---| |
| 89 | + | livy.spark.sql.hive.hiveserver2.jdbc.url.principal | `hive/<headnode-FQDN>@<AAD-Domain>` | |
| 90 | +
|
| 91 | + Replace `<headnode-FQDN>` with the Fully Qualified Domain Name of the head node of the Interactive Query cluster. |
| 92 | + Replace `<AAD-DOMAIN>` with the name of the Azure Active Directory (AAD) that the cluster is joined to. Use an uppercase string for the `<AAD-DOMAIN>` value, otherwise the credential won't be found. Check `/etc/krb5.conf` for the realm names if needed. |
| 93 | +
|
| 94 | +1. Save the changes and restart the Livy interpreter. |
| 95 | +
|
| 96 | +If Livy interpreter isn't accessible, modify the `shiro.ini` file present within Zeppelin component in Ambari. For more information, see [Configuring Apache Zeppelin Security](https://docs.cloudera.com/HDPDocuments/HDP3/HDP-3.0.1/configuring-zeppelin-security/content/enabling_access_control_for_interpreter__configuration__and_credential_settings.html). |
| 97 | +
|
| 98 | +
|
| 99 | +## Running Queries in Zeppelin |
| 100 | +
|
| 101 | +Launch a Zeppelin notebook using Livy interpreter and execute the following |
| 102 | +
|
| 103 | +```python |
| 104 | +%livy2 |
| 105 | +
|
| 106 | +import com.hortonworks.hwc.HiveWarehouseSession |
| 107 | +import com.hortonworks.hwc.HiveWarehouseSession._ |
| 108 | +import org.apache.spark.sql.SaveMode |
| 109 | +
|
| 110 | +# Initialize the hive context |
| 111 | +val hive = HiveWarehouseSession.session(spark).build() |
| 112 | +
|
| 113 | +# Create a database |
| 114 | +hive.createDatabase("hwc_db",true) |
| 115 | +hive.setDatabase("hwc_db") |
| 116 | +
|
| 117 | +# Create a Hive table |
| 118 | +hive.createTable("testers").ifNotExists().column("id", "bigint").column("name", "string").create() |
| 119 | +
|
| 120 | +val dataDF = Seq( (1, "foo"), (2, "bar"), (8, "john")).toDF("id", "name") |
| 121 | +
|
| 122 | +# Validate writes to the table |
| 123 | +dataDF.write.format("com.hortonworks.spark.sql.hive.llap.HiveWarehouseConnector").mode("append").option("table", "hwc_db.testers").save() |
| 124 | +
|
| 125 | +# Validate reads |
| 126 | +hive.executeQuery("select * from testers").show() |
| 127 | +
|
| 128 | +``` |
| 129 | + |
| 130 | +## Next steps |
| 131 | + |
| 132 | +* [HWC and Apache Spark operations](./apache-hive-warehouse-connector-operations.md) |
| 133 | +* [HWC integration with Apache Spark and Apache Hive](./apache-hive-warehouse-connector.md) |
| 134 | +* [Use Interactive Query with HDInsight](./apache-interactive-query-get-started.md) |
0 commit comments