Membangun aplikasi Java untuk Apache HBase

Pelajari cara membuat aplikasi Apache HBase di Java. Kemudian gunakan aplikasi dengan HBase di Azure HDInsight.

Langkah-langkah dalam dokumen ini menggunakan Apache Maven untuk membuat dan membangun proyek. Maven adalah alat manajemen dan pemahaman proyek perangkat lunak yang memungkinkan Anda membangun perangkat lunak, dokumentasi, dan laporan untuk proyek Java.

Prasyarat

Lingkungan uji

Lingkungan yang digunakan dalam artikel ini adalah komputer yang menjalankan Windows 10. Perintah dijalankan dalam perintah, dan berbagai file diedit dengan Notepad. Mengubah sesuai lingkungan Anda.

Dari prompt perintah, masukkan perintah berikut untuk membuat lingkungan kerja:

IF NOT EXIST C:\HDI MKDIR C:\HDI
cd C:\HDI

Membuat proyek Maven

  1. Masukkan perintah berikut untuk membuat proyek Maven bernama wordcountjava:

    mvn archetype:generate -DgroupId=com.microsoft.examples -DartifactId=hbaseapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
    
    cd hbaseapp
    mkdir conf
    

    Perintah ini membuat direktori bernama hbaseapp pada lokasi saat ini, yang berisi proyek Dasar Maven. Perintah kedua mengubah direktori kerja menjadi hbaseapp. Perintah ketiga membuat direktori baru, conf, yang dapat digunakan nanti. Direktori hbaseapp memuat item berikut ini:

    • pom.xml: Project Object Model (POM) yang berisi informasi dan detail konfigurasi yang digunakan untuk membuat proyek.
    • src\main\java\com\microsoft\examples: Berisi kode aplikasi Anda.
    • src\test\java\com\microsoft\examples: Berisi pengujian untuk aplikasi Anda.
  2. Hapus kode contoh yang dihasilkan. Hapus file AppTest.javapengujian dan aplikasi yang dihasilkan , dan App.java dengan memasukkan perintah berikut:

    DEL src\main\java\com\microsoft\examples\App.java
    DEL src\test\java\com\microsoft\examples\AppTest.java
    

Memperbarui Model Objek Proyek

Untuk referensi lengkap file pom.xml, lihat https://maven.apache.org/pom.html. Buka pom.xml dengan memasukkan perintah berikut:

notepad pom.xml

Menambahkan dependensi

Di pom.xml, tambahkan teks berikut di bagian <dependencies>:

<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-shaded-client</artifactId>
    <version>1.1.2</version>
</dependency>
<dependency>
    <groupId>org.apache.phoenix</groupId>
    <artifactId>phoenix-core</artifactId>
    <version>4.14.1-HBase-1.1</version>
</dependency>

Bagian ini menunjukkan bahwa proyek membutuhkan komponen hbase-client dan phoenix-core. Pada waktu kompilasi, dependensi ini diunduh dari repositori Maven default. Anda dapat menggunakan Pencarian Repositori Maven Central untuk mempelajari selengkapnya tentang dependensi ini.

Penting

Nomor versi klien hbase harus sesuai dengan versi Apache HBase yang disediakan dengan kluster HDInsight Anda. Gunakan tabel berikut ini untuk menemukan nomor versi yang benar.

Versi kluster HDInsight Apache versi HBase untuk digunakan
3.6 1.1.2
4,0 2.0.0

Untuk informasi selengkapnya tentang versi dan komponen HDInsight, lihat Apa saja berbagai komponen Apache Hadoop yang tersedia dengan HDInsight.

Konfigurasi build

Plug-in Maven memungkinkan Anda menyesuaikan tahap build proyek. Bagian ini digunakan untuk menambahkan plug-in, sumber daya, dan opsi konfigurasi build lainnya.

Tambahkan kode berikut ke file pom.xml, lalu simpan dan tutup file. Teks ini harus berada di dalam tag <project>...</project> di file, misalnya, antara </dependencies> dan </project>.

<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
    <resource>
        <directory>${basedir}/conf</directory>
        <filtering>false</filtering>
        <includes>
        <include>hbase-site.xml</include>
        </includes>
    </resource>
    </resources>
    <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
        </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
        <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer">
            </transformer>
        </transformers>
        </configuration>
        <executions>
        <execution>
            <phase>package</phase>
            <goals>
            <goal>shade</goal>
            </goals>
        </execution>
        </executions>
    </plugin>
    </plugins>
</build>

Bagian ini mengonfigurasi sumber daya (conf/hbase-site.xml) yang berisi informasi konfigurasi untuk HBase.

Catatan

Anda juga dapat mengatur nilai konfigurasi melalui kode. Lihat komentar dalam CreateTable contoh.

Bagian ini mengonfigurasi Plugin Pengompilasi Apache Maven dan Plugin Bayangan Apache Maven. Plug-in kompiler digunakan untuk mengompilasi topologi. Plug-in bayangan digunakan untuk mencegah duplikasi lisensi dalam paket JAR yang dibuat oleh Maven. Plugin ini digunakan untuk mencegah kesalahan "file lisensi duplikat" pada durasi di kluster HDInsight. Menggunakan plugin-bayangan-maven dengan implementasi ApacheLicenseResourceTransformer mencegah kesalahan.

Maven-shade-plugin juga menghasilkan uber jar yang berisi semua dependensi yang diperlukan oleh aplikasi.

Unduh hbase-site.xml

Gunakan perintah berikut untuk menyalin konfigurasi HBase dari kluster HBase conf ke direktori. Ganti CLUSTERNAME dengan nama kluster HDInsight, lalu masukkan perintah berikut:

scp sshuser@CLUSTERNAME-ssh.azurehdinsight.net:/etc/hbase/conf/hbase-site.xml ./conf/hbase-site.xml

Buat aplikasi

Menerapkan kelas CreateTable

Masukkan perintah berikut untuk membuat dan membuka file CreateTable.javabaru . Pilih Ya di perintah untuk membuat file baru.

notepad src\main\java\com\microsoft\examples\CreateTable.java

Kemudian salin dan tempel kode Java berikut ke dalam file baru. Lalu tutup file.

package com.microsoft.examples;
import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

public class CreateTable {
    public static void main(String[] args) throws IOException {
    Configuration config = HBaseConfiguration.create();

    // Example of setting zookeeper values for HDInsight
    // in code instead of an hbase-site.xml file
    //
    // config.set("hbase.zookeeper.quorum",
    //            "zookeepernode0,zookeepernode1,zookeepernode2");
    //config.set("hbase.zookeeper.property.clientPort", "2181");
    //config.set("hbase.cluster.distributed", "true");
    //
    //NOTE: Actual zookeeper host names can be found using Ambari:
    //curl -u admin:PASSWORD -G "https://CLUSTERNAME.azurehdinsight.net/api/v1/clusters/CLUSTERNAME/hosts"

    //Linux-based HDInsight clusters use /hbase-unsecure as the znode parent
    config.set("zookeeper.znode.parent","/hbase-unsecure");

    // create an admin object using the config
    HBaseAdmin admin = new HBaseAdmin(config);

    // create the table...
    HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf("people"));
    // ... with two column families
    tableDescriptor.addFamily(new HColumnDescriptor("name"));
    tableDescriptor.addFamily(new HColumnDescriptor("contactinfo"));
    admin.createTable(tableDescriptor);

    // define some people
    String[][] people = {
        { "1", "Marcel", "Haddad", "marcel@fabrikam.com"},
        { "2", "Franklin", "Holtz", "franklin@contoso.com" },
        { "3", "Dwayne", "McKee", "dwayne@fabrikam.com" },
        { "4", "Rae", "Schroeder", "rae@contoso.com" },
        { "5", "Rosalie", "burton", "rosalie@fabrikam.com"},
        { "6", "Gabriela", "Ingram", "gabriela@contoso.com"} };

    HTable table = new HTable(config, "people");

    // Add each person to the table
    //   Use the `name` column family for the name
    //   Use the `contactinfo` column family for the email
    for (int i = 0; i< people.length; i++) {
        Put person = new Put(Bytes.toBytes(people[i][0]));
        person.add(Bytes.toBytes("name"), Bytes.toBytes("first"), Bytes.toBytes(people[i][1]));
        person.add(Bytes.toBytes("name"), Bytes.toBytes("last"), Bytes.toBytes(people[i][2]));
        person.add(Bytes.toBytes("contactinfo"), Bytes.toBytes("email"), Bytes.toBytes(people[i][3]));
        table.put(person);
    }
    // flush commits and close the table
    table.flushCommits();
    table.close();
    }
}

Kode ini adalah CreateTable kelas, yang membuat tabel bernama people dan mengisinya dengan beberapa pengguna yang telah ditentukan.

Mengimplementasikan kelas SearchByEmail

Masukkan perintah berikut untuk membuat dan membuka file SearchByEmail.javabaru . Pilih Ya di perintah untuk membuat file baru.

notepad src\main\java\com\microsoft\examples\SearchByEmail.java

Kemudian salin dan tempel kode Java berikut ke dalam file baru. Lalu tutup file.

package com.microsoft.examples;
import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.filter.RegexStringComparator;
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.util.GenericOptionsParser;

public class SearchByEmail {
    public static void main(String[] args) throws IOException {
    Configuration config = HBaseConfiguration.create();

    // Use GenericOptionsParser to get only the parameters to the class
    // and not all the parameters passed (when using WebHCat for example)
    String[] otherArgs = new GenericOptionsParser(config, args).getRemainingArgs();
    if (otherArgs.length != 1) {
        System.out.println("usage: [regular expression]");
        System.exit(-1);
    }

    // Open the table
    HTable table = new HTable(config, "people");

    // Define the family and qualifiers to be used
    byte[] contactFamily = Bytes.toBytes("contactinfo");
    byte[] emailQualifier = Bytes.toBytes("email");
    byte[] nameFamily = Bytes.toBytes("name");
    byte[] firstNameQualifier = Bytes.toBytes("first");
    byte[] lastNameQualifier = Bytes.toBytes("last");

    // Create a regex filter
    RegexStringComparator emailFilter = new RegexStringComparator(otherArgs[0]);
    // Attach the regex filter to a filter
    //   for the email column
    SingleColumnValueFilter filter = new SingleColumnValueFilter(
        contactFamily,
        emailQualifier,
        CompareOp.EQUAL,
        emailFilter
    );

    // Create a scan and set the filter
    Scan scan = new Scan();
    scan.setFilter(filter);

    // Get the results
    ResultScanner results = table.getScanner(scan);
    // Iterate over results and print  values
    for (Result result : results ) {
        String id = new String(result.getRow());
        byte[] firstNameObj = result.getValue(nameFamily, firstNameQualifier);
        String firstName = new String(firstNameObj);
        byte[] lastNameObj = result.getValue(nameFamily, lastNameQualifier);
        String lastName = new String(lastNameObj);
        System.out.println(firstName + " " + lastName + " - ID: " + id);
        byte[] emailObj = result.getValue(contactFamily, emailQualifier);
        String email = new String(emailObj);
        System.out.println(firstName + " " + lastName + " - " + email + " - ID: " + id);
    }
    results.close();
    table.close();
    }
}

Kelas SearchByEmail dapat digunakan untuk kueri untuk baris berdasarkan alamat email. Karena menggunakan filter ekspresi reguler, Anda dapat memberikan string atau ekspresi reguler saat menggunakan kelas.

Menerapkan kelas DeleteTable

Masukkan perintah berikut untuk membuat dan membuka file DeleteTable.javabaru . Pilih Ya di perintah untuk membuat file baru.

notepad src\main\java\com\microsoft\examples\DeleteTable.java

Kemudian salin dan tempel kode Java berikut ke dalam file baru. Lalu tutup file.

package com.microsoft.examples;
import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;

public class DeleteTable {
    public static void main(String[] args) throws IOException {
    Configuration config = HBaseConfiguration.create();

    // Create an admin object using the config
    HBaseAdmin admin = new HBaseAdmin(config);

    // Disable, and then delete the table
    admin.disableTable("people");
    admin.deleteTable("people");
    }
}

Kelas DeleteTable membersihkan tabel HBase yang dibuat dalam contoh ini dengan menonaktifkan dan menjatuhkan tabel yang dibuat oleh CreateTable kelas.

Membangun dan memaketkan aplikasi

  1. Dari direktori hbaseapp, gunakan perintah berikut untuk membuat file JAR yang berisi aplikasi:

    mvn clean package
    

    Perintah ini membangun dan memaketkan aplikasi ke dalam file .jar ini.

  2. Setelah perintah selesai, direktori hbaseapp/target berisi file bernama hbaseapp-1.0-SNAPSHOT.jar.

    Catatan

    File hbaseapp-1.0-SNAPSHOT.jar adalah uber jar. Ini berisi semua dependensi yang diperlukan untuk menjalankan aplikasi.

Mengunggah JAR dan menjalankan pekerjaan (SSH)

Langkah berikut menggunakan scp untuk menyalin JAR ke headnode utama Apache HBase Anda di kluster HDInsight. Perintah ssh kemudian digunakan untuk terhubung ke kluster dan menjalankan contoh langsung pada headnode.

  1. Unggah jar ke kluster. Ganti CLUSTERNAME dengan nama klaster HDInsight, lalu masukkan perintah berikut:

    scp ./target/hbaseapp-1.0-SNAPSHOT.jar sshuser@CLUSTERNAME-ssh.azurehdinsight.net:hbaseapp-1.0-SNAPSHOT.jar
    
  2. Sambungkan ke klaster HBase. Ganti CLUSTERNAME dengan nama klaster HDInsight, lalu masukkan perintah berikut:

    ssh sshuser@CLUSTERNAME-ssh.azurehdinsight.net
    
  3. Untuk membuat tabel HBase menggunakan aplikasi Java, gunakan perintah berikut ini di koneksi ssh terbuka Anda:

    yarn jar hbaseapp-1.0-SNAPSHOT.jar com.microsoft.examples.CreateTable
    

    Perintah ini membuat tabel HBase bernama orang, dan mengisinya dengan data.

  4. Untuk mencari alamat email yang disimpan dalam tabel, gunakan perintah berikut ini:

    yarn jar hbaseapp-1.0-SNAPSHOT.jar com.microsoft.examples.SearchByEmail contoso.com
    

    Anda menerima hasil berikut:

    Franklin Holtz - ID: 2
    Franklin Holtz - franklin@contoso.com - ID: 2
    Rae Schroeder - ID: 4
    Rae Schroeder - rae@contoso.com - ID: 4
    Gabriela Ingram - ID: 6
    Gabriela Ingram - gabriela@contoso.com - ID: 6
    
  5. Untuk menghapus tabel, gunakan perintah berikut ini:

    yarn jar hbaseapp-1.0-SNAPSHOT.jar com.microsoft.examples.DeleteTable
    

Mengunggah JAR dan menjalankan pekerjaan (PowerShell)

Langkah-langkah berikut menggunakan modul AZ Azure PowerShell AZ untuk mengunggah JAR ke penyimpanan default untuk kluster Apache HBase Anda. Cmdlet HDInsight kemudian digunakan untuk menjalankan contoh dari jarak jauh.

  1. Setelah menginstal dan mengonfigurasi modul AZ, buat file bernama hbase-runner.psm1. Gunakan teks berikut sebagai konten file:

     <#
     .SYNOPSIS
     Copies a file to the primary storage of an HDInsight cluster.
     .DESCRIPTION
     Copies a file from a local directory to the blob container for
     the HDInsight cluster.
     .EXAMPLE
     Start-HBaseExample -className "com.microsoft.examples.CreateTable"
     -clusterName "MyHDInsightCluster"
    
     .EXAMPLE
     Start-HBaseExample -className "com.microsoft.examples.SearchByEmail"
     -clusterName "MyHDInsightCluster"
     -emailRegex "contoso.com"
    
     .EXAMPLE
     Start-HBaseExample -className "com.microsoft.examples.SearchByEmail"
     -clusterName "MyHDInsightCluster"
     -emailRegex "^r" -showErr
     #>
    
     function Start-HBaseExample {
     [CmdletBinding(SupportsShouldProcess = $true)]
     param(
     #The class to run
     [Parameter(Mandatory = $true)]
     [String]$className,
    
     #The name of the HDInsight cluster
     [Parameter(Mandatory = $true)]
     [String]$clusterName,
    
     #Only used when using SearchByEmail
     [Parameter(Mandatory = $false)]
     [String]$emailRegex,
    
     #Use if you want to see stderr output
     [Parameter(Mandatory = $false)]
     [Switch]$showErr
     )
    
     Set-StrictMode -Version 3
    
     # Is the Azure module installed?
     FindAzure
    
     # Get the login for the HDInsight cluster
     $creds=Get-Credential -Message "Enter the login for the cluster" -UserName "admin"
    
     # The JAR
     $jarFile = "wasb:///example/jars/hbaseapp-1.0-SNAPSHOT.jar"
    
     # The job definition
     $jobDefinition = New-AzHDInsightMapReduceJobDefinition `
         -JarFile $jarFile `
         -ClassName $className `
         -Arguments $emailRegex
    
     # Get the job output
     $job = Start-AzHDInsightJob `
         -ClusterName $clusterName `
         -JobDefinition $jobDefinition `
         -HttpCredential $creds
     Write-Host "Wait for the job to complete ..." -ForegroundColor Green
     Wait-AzHDInsightJob `
         -ClusterName $clusterName `
         -JobId $job.JobId `
         -HttpCredential $creds
     if($showErr)
     {
     Write-Host "STDERR"
     Get-AzHDInsightJobOutput `
                 -Clustername $clusterName `
                 -JobId $job.JobId `
                 -HttpCredential $creds `
                 -DisplayOutputType StandardError
     }
     Write-Host "Display the standard output ..." -ForegroundColor Green
     Get-AzHDInsightJobOutput `
                 -Clustername $clusterName `
                 -JobId $job.JobId `
                 -HttpCredential $creds
     }
    
     <#
     .SYNOPSIS
     Copies a file to the primary storage of an HDInsight cluster.
     .DESCRIPTION
     Copies a file from a local directory to the blob container for
     the HDInsight cluster.
     .EXAMPLE
     Add-HDInsightFile -localPath "C:\temp\data.txt"
     -destinationPath "example/data/data.txt"
     -ClusterName "MyHDInsightCluster"
     .EXAMPLE
     Add-HDInsightFile -localPath "C:\temp\data.txt"
     -destinationPath "example/data/data.txt"
     -ClusterName "MyHDInsightCluster"
     -Container "MyContainer"
     #>
    
     function Add-HDInsightFile {
         [CmdletBinding(SupportsShouldProcess = $true)]
         param(
             #The path to the local file.
             [Parameter(Mandatory = $true)]
             [String]$localPath,
    
             #The destination path and file name, relative to the root of the container.
             [Parameter(Mandatory = $true)]
             [String]$destinationPath,
    
             #The name of the HDInsight cluster
             [Parameter(Mandatory = $true)]
             [String]$clusterName,
    
             #If specified, overwrites existing files without prompting
             [Parameter(Mandatory = $false)]
             [Switch]$force
         )
    
         Set-StrictMode -Version 3
    
         # Is the Azure module installed?
         FindAzure
    
         # Get authentication for the cluster
         $creds=Get-Credential
    
         # Does the local path exist?
         if (-not (Test-Path $localPath))
         {
             throw "Source path '$localPath' does not exist."
         }
    
         # Get the primary storage container
         $storage = GetStorage -clusterName $clusterName
    
         # Upload file to storage, overwriting existing files if -force was used.
         Set-AzStorageBlobContent -File $localPath `
             -Blob $destinationPath `
             -force:$force `
             -Container $storage.container `
             -Context $storage.context
     }
    
     function FindAzure {
         # Is there an active Azure subscription?
         $sub = Get-AzSubscription -ErrorAction SilentlyContinue
         if(-not($sub))
         {
             Connect-AzAccount
         }
     }
    
     function GetStorage {
         param(
             [Parameter(Mandatory = $true)]
             [String]$clusterName
         )
         $hdi = Get-AzHDInsightCluster -ClusterName $clusterName
         # Does the cluster exist?
         if (!$hdi)
         {
             throw "HDInsight cluster '$clusterName' does not exist."
         }
         # Create a return object for context & container
         $return = @{}
         $storageAccounts = @{}
    
         # Get storage information
         $resourceGroup = $hdi.ResourceGroup
         $storageAccountName=$hdi.DefaultStorageAccount.split('.')[0]
         $container=$hdi.DefaultStorageContainer
         $storageAccountKey=(Get-AzStorageAccountKey `
             -Name $storageAccountName `
         -ResourceGroupName $resourceGroup)[0].Value
         # Get the resource group, in case we need that
         $return.resourceGroup = $resourceGroup
         # Get the storage context, as we can't depend
         # on using the default storage context
         $return.context = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
         # Get the container, so we know where to
         # find/store blobs
         $return.container = $container
         # Return storage accounts to support finding all accounts for
         # a cluster
         $return.storageAccount = $storageAccountName
         $return.storageAccountKey = $storageAccountKey
    
         return $return
     }
     # Only export the verb-phrase things
     export-modulemember *-*
    

    File ini berisi dua modul:

    • Tambahkan-HDInsightFile - digunakan untuk mengunggah file ke kluster
    • Mulai-HBaseExample - digunakan untuk menjalankan kelas yang dibuat sebelumnya
  2. Simpan hbase-runner.psm1file ini dalamhbaseapp direktori.

  3. Daftarkan modul dengan Azure PowerShell. Buka jendela Azure PowerShell baru dan edit perintah berikut dengan mengganti CLUSTERNAME dengan nama kluster Anda. Masukkan perintah berikut:

    cd C:\HDI\hbaseapp
    $myCluster = "CLUSTERNAME"
    Import-Module .\hbase-runner.psm1
    
  4. Gunakan perintah berikut untuk mengunggah hbaseapp-1.0-SNAPSHOT.jar ke kluster Anda.

    Add-HDInsightFile -localPath target\hbaseapp-1.0-SNAPSHOT.jar -destinationPath example/jars/hbaseapp-1.0-SNAPSHOT.jar -clusterName $myCluster
    

    Jika diminta, masukkan nama dan kata sandi login kluster (admin). Perintah mengunggah hbaseapp-1.0-SNAPSHOT.jar lokasi example/jars di penyimpanan utama untuk kluster Anda.

  5. Untuk membuat tabel menggunakan perintahhbaseapp, gunakan perintah berikut ini:

    Start-HBaseExample -className com.microsoft.examples.CreateTable -clusterName $myCluster
    

    Jika diminta, masukkan nama dan kata sandi login kluster (admin).

    Perintah ini membuat tabel bernama orang HBase pada kluster HDInsight Anda. Perintah ini tidak menampilkan output apa pun di jendela konsol.

  6. Untuk mencari entri dalam tabel, gunakan perintah berikut ini:

    Start-HBaseExample -className com.microsoft.examples.SearchByEmail -clusterName $myCluster -emailRegex contoso.com
    

    Jika diminta, masukkan nama dan kata sandi login kluster (admin).

    Perintah ini menggunakan kelas SearchByEmail untuk mencari baris mana pun tempat contactinformation keluarga kolom dan email kolom, berisi string contoso.com. Anda akan menerima hasil berikut:

    Franklin Holtz - ID: 2
    Franklin Holtz - franklin@contoso.com - ID: 2
    Rae Schroeder - ID: 4
    Rae Schroeder - rae@contoso.com - ID: 4
    Gabriela Ingram - ID: 6
    Gabriela Ingram - gabriela@contoso.com - ID: 6
    

    Menggunakan fabrikam.com untuk -emailRegex nilai mengembalikan pengguna yang memiliki fabrikam.com di bidang email. Anda juga dapat menggunakan ekspresi reguler sebagai istilah pencarian. Misalnya, ^r mengembalikan alamat email yang dimulai dengan huruf 'r'.

  7. Untuk menghapus tabel, gunakan perintah berikut ini:

    Start-HBaseExample -className com.microsoft.examples.DeleteTable -clusterName $myCluster
    

Tidak ada hasil atau hasil yang tidak terduga ketika Start-HBaseExample

Gunakan -showErr parameter untuk melihat kesalahan standar (STDERR) yang dihasilkan saat menjalankan pekerjaan.

Langkah berikutnya

Pelajari cara menggunakan SQLLine dengan Apache HBase