Udostępnij za pośrednictwem


Quickstart: Query Apache HBase in Azure HDInsight with HBase Shell

In this quickstart, you learn how to use Apache HBase Shell to create an HBase table, insert data, and then query the table.

Jeśli nie masz subskrypcji platformy Azure, przed rozpoczęciem utwórz bezpłatne konto.

Wymagania wstępne

Tworzenie tabeli i manipulowanie danymi

Dla większości użytkowników dane są wyświetlane w formacie tabelarycznym:

HDInsight Apache HBase tabular data.

W bazie danych HBase (implementacja rozwiązania Cloud BigTable) te same dane wyglądają następująco:

HDInsight Apache HBase BigTable data.

You can use SSH to connect to HBase clusters, and then use Apache HBase Shell to create HBase tables, insert data, and query data.

  1. Użyj ssh polecenia , aby nawiązać połączenie z klastrem HBase. Zmodyfikuj poniższe polecenie, zastępując CLUSTERNAME nazwą twojego klastra, a następnie wykonaj polecenie.

    ssh sshuser@CLUSTERNAME-ssh.azurehdinsight.net
    
  2. Use hbase shell command to start the HBase interactive shell. Wprowadź następujące polecenie w połączeniu SSH:

    hbase shell
    
  3. Use create command to create an HBase table with two-column families. Wprowadź następujące polecenie:

    create 'Contacts', 'Personal', 'Office'
    
  4. Użyj list polecenia , aby wyświetlić listę wszystkich tabel w bazie danych HBase. Wprowadź następujące polecenie:

    list
    
  5. Użyj put polecenia , aby wstawić wartości w określonej kolumnie w określonym wierszu w określonej tabeli. Wprowadź następujące polecenie:

    put 'Contacts', '1000', 'Personal:Name', 'John Dole'
    put 'Contacts', '1000', 'Personal:Phone', '1-425-000-0001'
    put 'Contacts', '1000', 'Office:Phone', '1-425-000-0002'
    put 'Contacts', '1000', 'Office:Address', '1111 San Gabriel Dr.'
    
  6. Użyj scan polecenia , aby skanować i zwracać Contacts dane tabeli. Wprowadź następujące polecenie:

    scan 'Contacts'
    
  7. Użyj get polecenia , aby pobrać zawartość wiersza. Wprowadź następujące polecenie:

    get 'Contacts', '1000'
    

    You see similar results as using the scan command because there is only one row.

  8. Use delete command to delete a cell value in a table. Wprowadź następujące polecenie:

    delete 'Contacts', '1000', 'Office:Address'
    
  9. Use disable command to disable the table. Wprowadź następujące polecenie:

    disable 'Contacts'
    
  10. Use drop command to drop a table from HBase. Wprowadź następujące polecenie:

    drop 'Contacts'
    
  11. Use exit command to stop the HBase interactive shell. Wprowadź następujące polecenie:

    exit
    

Aby uzyskać więcej informacji na temat schematu tabeli HBase, zobacz Wprowadzenie do projektu schematu bazy danych Apache HBase. Więcej poleceń bazy danych HBase można znaleźć w Podręczniku bazy danych Apache HBase.

Czyszczenie zasobów

Po ukończeniu procedury szybkiego startu możesz usunąć klaster. W usłudze HDInsight dane są przechowywane w usłudze Azure Storage, dzięki czemu można bezpiecznie usunąć klaster, gdy nie jest używany. Opłaty są również naliczane za klaster usługi HDInsight, nawet jeśli nie jest używany. Ponieważ opłaty za klaster są wielokrotnie większe niż opłaty za magazyn, warto usunąć klastry, gdy nie są używane.

Aby usunąć klaster, zobacz Usuwanie klastra usługi HDInsight przy użyciu przeglądarki, programu PowerShell lub interfejsu wiersza polecenia platformy Azure.

Następne kroki

In this quickstart, you learned how to use Apache HBase Shell to create an HBase table, insert data, and then query the table. To learn more about data stored in HBase, the next article will show you how to execute queries with Apache Spark.