|
1 | 1 | ---
|
2 |
| -title: Use Apache Phoenix and SQLLine with HBase in Azure HDInsight |
| 2 | +title: 'Quickstart: Query Apache HBase in Azure HDInsight - Apache Phoenix' |
3 | 3 | description: Learn how to use Apache Phoenix in HDInsight. Also, learn how to install and set up SQLLine on your computer to connect to an HBase cluster in HDInsight.
|
4 | 4 | author: hrasheed-msft
|
5 | 5 | ms.reviewer: jasonh
|
6 | 6 |
|
7 | 7 | ms.service: hdinsight
|
8 | 8 | ms.custom: hdinsightactive
|
9 |
| -ms.topic: conceptual |
10 |
| -ms.date: 01/03/2018 |
| 9 | +ms.topic: quickstart |
| 10 | +ms.date: 05/08/2019 |
11 | 11 | ms.author: hrasheed
|
12 |
| - |
13 | 12 | ---
|
14 |
| -# Use Apache Phoenix with Linux-based Apache HBase clusters in HDInsight |
15 |
| -Learn how to use [Apache Phoenix](https://phoenix.apache.org/) in Azure HDInsight, and how to use SQLLine. For more information about Phoenix, see [Apache Phoenix in 15 minutes or less](https://phoenix.apache.org/Phoenix-in-15-minutes-or-less.html). For the Phoenix grammar, see [Apache Phoenix grammar](https://phoenix.apache.org/language/index.html). |
16 | 13 |
|
17 |
| -> [!NOTE] |
18 |
| -> For Phoenix version information about HDInsight, see [What's new in the Apache Hadoop cluster versions provided by HDInsight](../hdinsight-component-versioning.md). |
19 |
| -> |
20 |
| -> |
| 14 | +# Quickstart: Query Apache HBase in Azure HDInsight with Apache Phoenix |
21 | 15 |
|
22 |
| -## Use SQLLine |
23 |
| -[SQLLine](http://sqlline.sourceforge.net/) is a command-line utility to execute SQL. |
| 16 | +In this quickstart, you learn how to use the Apache Phoenix to run HBase queries in Azure HDInsight. Apache Phoenix is a SQL query engine for Apache HBase. It is accessed as a JDBC driver, and it enables querying and managing HBase tables by using SQL. [SQLLine](http://sqlline.sourceforge.net/) is a command-line utility to execute SQL. |
24 | 17 |
|
25 |
| -### Prerequisites |
26 |
| -Before you can use SQLLine, you must have the following items: |
| 18 | +If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
27 | 19 |
|
28 |
| -* **An Apache HBase cluster in HDInsight**. To create one, see [Get started with Apache HBase in HDInsight](./apache-hbase-tutorial-get-started-linux.md). |
| 20 | +## Prerequisites |
29 | 21 |
|
30 |
| -When you connect to an HBase cluster, you need to connect to one of the [Apache ZooKeeper](https://zookeeper.apache.org/) VMs. Each HDInsight cluster has three ZooKeeper VMs. |
| 22 | +* An Apache HBase cluster. See [Create cluster](../hadoop/apache-hadoop-linux-tutorial-get-started.md#create-cluster) to create an HDInsight cluster. Ensure you choose the **HBase** cluster type. |
31 | 23 |
|
32 |
| -**To get the ZooKeeper host name** |
| 24 | +* An SSH client. For more information, see [Connect to HDInsight (Apache Hadoop) using SSH](../hdinsight-hadoop-linux-use-ssh-unix.md). |
33 | 25 |
|
34 |
| -1. Open [Apache Ambari](https://ambari.apache.org/) by browsing to **https://\<cluster name\>.azurehdinsight.net**. |
35 |
| -2. To sign in, enter the HTTP (cluster) user name and password. |
36 |
| -3. In the left menu, select **ZooKeeper**. Three **ZooKeeper Server** instances are listed. |
37 |
| -4. Select one of the **ZooKeeper Server** instances. On the **Summary** pane, find the **Hostname**. It looks similar to *zk1-jdolehb.3lnng4rcvp5uzokyktxs4a5dhd.bx.internal.cloudapp.net*. |
| 26 | +## Identify a ZooKeeper node |
38 | 27 |
|
39 |
| -**To use SQLLine** |
| 28 | +When you connect to an HBase cluster, you need to connect to one of the Apache ZooKeeper nodes. Each HDInsight cluster has three ZooKeeper nodes. Curl can be used to quickly identify a ZooKeeper node. Edit the curl command below by replacing `PASSWORD` and `CLUSTERNAME` with the relevant values, and then enter the command in a command prompt: |
40 | 29 |
|
41 |
| -1. Connect to the cluster by using SSH. For more information, see [Use SSH with HDInsight](../hdinsight-hadoop-linux-use-ssh-unix.md). |
| 30 | +```cmd |
| 31 | +curl -u admin:PASSWORD -sS -G https://CLUSTERNAME.azurehdinsight.net/api/v1/clusters/CLUSTERNAME/services/ZOOKEEPER/components/ZOOKEEPER_SERVER |
| 32 | +``` |
42 | 33 |
|
43 |
| -2. In SSH, use the following commands to run SQLLine: |
| 34 | +A portion of the output will look similar to: |
44 | 35 |
|
45 |
| - cd /usr/hdp/current/phoenix-client/bin |
46 |
| - ./sqlline.py <ZOOKEEPER SERVER FQDN>:2181:/hbase-unsecure |
47 |
| -3. To create an HBase table, and insert some data, run the following commands: |
| 36 | +```output |
| 37 | + { |
| 38 | + "href" : "http://hn1-brim.432dc3rlshou3ocf251eycoapa.bx.internal.cloudapp.net:8080/api/v1/clusters/myCluster/hosts/zk0-brim.432dc3rlshou3ocf251eycoapa.bx.internal.cloudapp.net/host_components/ZOOKEEPER_SERVER", |
| 39 | + "HostRoles" : { |
| 40 | + "cluster_name" : "myCluster", |
| 41 | + "component_name" : "ZOOKEEPER_SERVER", |
| 42 | + "host_name" : "zk0-brim.432dc3rlshou3ocf251eycoapa.bx.internal.cloudapp.net" |
| 43 | + } |
| 44 | +``` |
48 | 45 |
|
49 |
| - CREATE TABLE Company (COMPANY_ID INTEGER PRIMARY KEY, NAME VARCHAR(225)); |
| 46 | +Take note of the value for `host_name` for later use. |
50 | 47 |
|
51 |
| - !tables |
| 48 | +## Create a table and manipulate data |
52 | 49 |
|
53 |
| - UPSERT INTO Company VALUES(1, 'Microsoft'); |
| 50 | +You can use SSH to connect to HBase clusters, and then use Apache Phoenix to create HBase tables, insert data, and query data. |
54 | 51 |
|
55 |
| - SELECT * FROM Company; |
| 52 | +1. Use `ssh` command to connect to your HBase cluster. Edit the command below by replacing `CLUSTERNAME` with the name of your cluster, and then enter the command: |
56 | 53 |
|
57 |
| - !quit |
| 54 | + ```cmd |
| 55 | + |
| 56 | + ``` |
58 | 57 |
|
59 |
| -For more information, see the [SQLLine manual](http://sqlline.sourceforge.net/#manual) and [Apache Phoenix grammar](https://phoenix.apache.org/language/index.html). |
| 58 | +2. Change directory to the Phoenix client. Enter the following command: |
60 | 59 |
|
61 |
| -## Next steps |
62 |
| -In this article, you learned how to use Apache Phoenix in HDInsight. To learn more, see these articles: |
| 60 | + ```bash |
| 61 | + cd /usr/hdp/current/phoenix-client/bin |
| 62 | + ``` |
| 63 | +
|
| 64 | +3. Launch [SQLLine](http://sqlline.sourceforge.net/). Edit the command below by replacing `ZOOKEEPER` with the ZooKeeper node identified earlier, then enter the command: |
| 65 | +
|
| 66 | + ```bash |
| 67 | + ./sqlline.py ZOOKEEPER:2181:/hbase-unsecure |
| 68 | + ``` |
| 69 | +
|
| 70 | +4. Create an HBase table. Enter the following command: |
| 71 | +
|
| 72 | + ```sql |
| 73 | + CREATE TABLE Company (company_id INTEGER PRIMARY KEY, name VARCHAR(225)); |
| 74 | + ``` |
| 75 | +
|
| 76 | +5. Use the SQLLine `!tables` command to list all tables in HBase. Enter the following command: |
| 77 | +
|
| 78 | + ```sqlline |
| 79 | + !tables |
| 80 | + ``` |
| 81 | +
|
| 82 | +6. Insert values in the table. Enter the following command: |
| 83 | +
|
| 84 | + ```sql |
| 85 | + UPSERT INTO Company VALUES(1, 'Microsoft'); |
| 86 | + UPSERT INTO Company VALUES(2, 'Apache'); |
| 87 | + ``` |
| 88 | +
|
| 89 | +7. Query the table. Enter the following command: |
63 | 90 |
|
64 |
| -* [HDInsight HBase overview][hdinsight-hbase-overview]. |
65 |
| - Apache HBase is an Apache, open-source, NoSQL database built on Apache Hadoop that provides random access and strong consistency for large amounts of unstructured and semistructured data. |
66 |
| -* [Provision Apache HBase clusters on Azure Virtual Network][hdinsight-hbase-provision-vnet]. |
67 |
| - With virtual network integration, Apache HBase clusters can be deployed to the same virtual network as your applications, so applications can communicate directly with HBase. |
68 |
| -* [Configure Apache HBase replication in HDInsight](apache-hbase-replication.md). Learn how to set up Apache HBase replication across two Azure datacenters. |
| 91 | + ```sql |
| 92 | + SELECT * FROM Company; |
| 93 | + ``` |
69 | 94 |
|
| 95 | +8. Delete a record. Enter the following command: |
| 96 | +
|
| 97 | + ```sql |
| 98 | + DELETE FROM Company WHERE COMPANY_ID=1; |
| 99 | + ``` |
| 100 | +
|
| 101 | +9. Drop the table. Enter the following command: |
| 102 | +
|
| 103 | + ```hbase |
| 104 | + DROP TABLE Company; |
| 105 | + ``` |
| 106 | +
|
| 107 | +10. Use the SQLLine `!quit` command to exit SQLLine. Enter the following command: |
| 108 | +
|
| 109 | + ```sqlline |
| 110 | + !quit |
| 111 | + ``` |
| 112 | +
|
| 113 | +## Clean up resources |
| 114 | +
|
| 115 | +After you complete the quickstart, you may want to delete the cluster. With HDInsight, your data is stored in Azure Storage, so you can safely delete a cluster when it is not in use. You are also charged for an HDInsight cluster, even when it is not in use. Since the charges for the cluster are many times more than the charges for storage, it makes economic sense to delete clusters when they are not in use. |
| 116 | +
|
| 117 | +To delete a cluster, see [Delete an HDInsight cluster using your browser, PowerShell, or the Azure CLI](../hdinsight-delete-cluster.md). |
| 118 | +
|
| 119 | +## Next steps |
70 | 120 |
|
71 |
| -[azure-portal]: https://portal.azure.com |
72 |
| -[vnet-point-to-site-connectivity]: https://msdn.microsoft.com/library/azure/09926218-92ab-4f43-aa99-83ab4d355555#BKMK_VNETPT |
| 121 | +In this quickstart, you learned how to use the Apache Phoenix to run HBase queries in Azure HDInsight. To learn more about Apache Phoenix, the next article will provide a deeper examination. |
73 | 122 |
|
74 |
| -[hdinsight-hbase-provision-vnet]:apache-hbase-provision-vnet.md |
75 |
| -[hdinsight-hbase-overview]:apache-hbase-overview.md |
| 123 | +> [!div class="nextstepaction"] |
| 124 | +> [Apache Phoenix in HDInsight](../hdinsight-phoenix-in-hdinsight.md) |
76 | 125 |
|
| 126 | +## See Also |
77 | 127 |
|
| 128 | +* [SQLLine manual](http://sqlline.sourceforge.net/#manual). |
| 129 | +* [Apache Phoenix grammar](https://phoenix.apache.org/language/index.html). |
| 130 | +* [Apache Phoenix in 15 minutes or less](https://phoenix.apache.org/Phoenix-in-15-minutes-or-less.html) |
| 131 | +* [HDInsight HBase overview](./apache-hbase-overview.md) |
0 commit comments