Примечание
Для доступа к этой странице требуется авторизация. Вы можете попробовать войти или изменить каталоги.
Для доступа к этой странице требуется авторизация. Вы можете попробовать изменить каталоги.
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 is a command-line utility to execute SQL.
Если у вас нет подписки Azure, создайте бесплатную учетную запись, прежде чем приступить к работе.
Предпосылки
Кластер Apache HBase. См. статью "Создание кластера " для создания кластера HDInsight. Убедитесь, что выбран тип кластера HBase .
Клиент SSH. Дополнительные сведения см. в руководстве по подключению к HDInsight (Apache Hadoop) с помощью SSH.
Identify a ZooKeeper node
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:
curl -u admin:PASSWORD -sS -G https://CLUSTERNAME.azurehdinsight.net/api/v1/clusters/CLUSTERNAME/services/ZOOKEEPER/components/ZOOKEEPER_SERVER
A portion of the output will look similar to:
{
"href" : "http://hn*.432dc3rlshou3ocf251eycoapa.bx.internal.cloudapp.net:8080/api/v1/clusters/myCluster/hosts/<zookeepername1>.432dc3rlshou3ocf251eycoapa.bx.internal.cloudapp.net/host_components/ZOOKEEPER_SERVER",
"HostRoles" : {
"cluster_name" : "myCluster",
"component_name" : "ZOOKEEPER_SERVER",
"host_name" : "<zookeepername1>.432dc3rlshou3ocf251eycoapa.bx.internal.cloudapp.net"
}
Take note of the value for host_name
for later use.
Создание таблицы и управление данными
You can use SSH to connect to HBase clusters, and then use Apache Phoenix to create HBase tables, insert data, and query data.
С помощью команды
ssh
подключитесь к кластеру HBase. Измените приведенную ниже команду, заменивCLUSTERNAME
именем своего кластера, а затем введите команду:ssh sshuser@CLUSTERNAME-ssh.azurehdinsight.net
Change directory to the Phoenix client. Введите следующую команду:
cd /usr/hdp/current/phoenix-client/bin
Launch SQLLine. Edit the command below by replacing
ZOOKEEPER
with the ZooKeeper node identified earlier, then enter the command:./sqlline.py ZOOKEEPER:2181:/hbase-unsecure
Create an HBase table. Введите следующую команду:
CREATE TABLE Company (company_id INTEGER PRIMARY KEY, name VARCHAR(225));
Use the SQLLine
!tables
command to list all tables in HBase. Введите следующую команду:!tables
Insert values in the table. Введите следующую команду:
UPSERT INTO Company VALUES(1, 'Microsoft'); UPSERT INTO Company VALUES(2, 'Apache');
Query the table. Введите следующую команду:
SELECT * FROM Company;
Delete a record. Введите следующую команду:
DELETE FROM Company WHERE COMPANY_ID=1;
Drop the table. Введите следующую команду:
DROP TABLE Company;
Use the SQLLine
!quit
command to exit SQLLine. Введите следующую команду:!quit
Очистка ресурсов
После завершения быстрого запуска вы можете захотеть удалить кластер. С помощью HDInsight данные хранятся в службе хранилища Azure, поэтому вы можете безопасно удалить кластер, если он не используется. Плата также взимается за кластер HDInsight, даже если он не используется. Так как плата за кластер во многих случаях превышает расходы на хранение, экономия позволяет удалять кластеры, если они не используются.
Инструкции по удалению кластера см. в статье Delete an HDInsight cluster using your browser, PowerShell, or the Azure CLI (Удаление кластера HDInsight с помощью браузера, PowerShell или Azure CLI).
Дальнейшие действия
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.