Apache HBase için Java uygulamaları oluşturma

Java'da Apache HBase uygulaması oluşturmayı öğrenin. Ardından uygulamayı Azure HDInsight üzerinde HBase ile kullanın.

Bu belgedeki adımlarda projeyi oluşturmak ve oluşturmak için Apache Maven kullanılır. Maven, Java projeleri için yazılım, belge ve rapor oluşturmanıza olanak tanıyan bir yazılım proje yönetimi ve kavrama aracıdır.

Ön koşullar

Test ortamı

Bu makale için kullanılan ortam, Windows 10 çalıştıran bir bilgisayardı. Komutlar bir komut isteminde yürütüldü ve çeşitli dosyalar Not Defteri ile düzenlendi. Ortamınız için uygun şekilde değiştirin.

Bir komut isteminden aşağıdaki komutları girerek çalışma ortamı oluşturun:

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

Maven projesi oluşturma

  1. hbaseapp adlı bir Maven projesi oluşturmak için aşağıdaki komutu girin:

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

    Bu komut, temel bir Maven projesi içeren geçerli konumda adlı hbaseapp bir dizin oluşturur. İkinci komut çalışma dizinini olarak hbaseappdeğiştirir. Üçüncü komut, confdaha sonra kullanılabilecek yeni bir dizin oluşturur. Dizin hbaseapp aşağıdaki öğeleri içerir:

    • pom.xml: Proje Nesne Modeli (POM), projeyi oluşturmak için kullanılan bilgileri ve yapılandırma ayrıntılarını içerir.
    • src\main\java\com\microsoft\examples: Uygulama kodunuzu içerir.
    • src\test\java\com\microsoft\examples: Uygulamanızın testlerini içerir.
  2. Oluşturulan örnek kodu kaldırın. Oluşturulan test ve uygulama dosyalarını AppTest.javasilin ve App.java aşağıdaki komutları girin:

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

Proje Nesne Modelini Güncelleştirme

pom.xml dosyasının tam başvurusu için bkz https://maven.apache.org/pom.html. . Aşağıdaki komutu girerek açın pom.xml :

notepad pom.xml

Bağımlılık ekleme

içinde pom.xmlbölümüne aşağıdaki metni <dependencies> ekleyin:

<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>

Bu bölüm, projenin hbase-client ve phoenix-core bileşenlerine ihtiyacı olduğunu gösterir. Derleme zamanında, bu bağımlılıklar varsayılan Maven deposundan indirilir. Bu bağımlılık hakkında daha fazla bilgi edinmek için Maven Merkezi Depo Araması'nı kullanabilirsiniz.

Önemli

hbase-client sürüm numarası, HDInsight kümenizle birlikte sağlanan Apache HBase sürümüyle eşleşmelidir. Doğru sürüm numarasını bulmak için aşağıdaki tabloyu kullanın.

HDInsight küme sürümü Kullanılacak Apache HBase sürümü
3.6 1.1.2
4,0 2.0.0

HDInsight sürümleri ve bileşenleri hakkında daha fazla bilgi için bkz . HDInsight ile kullanılabilen farklı Apache Hadoop bileşenleri nelerdir?

Yapı yapılandırması

Maven eklentileri, projenin derleme aşamalarını özelleştirmenize olanak sağlar. Bu bölüm eklentiler, kaynaklar ve diğer derleme yapılandırma seçeneklerini eklemek için kullanılır.

Dosyaya pom.xml aşağıdaki kodu ekleyin ve dosyayı kaydedip kapatın. Bu metin dosyadaki etiketlerin <project>...</project> içinde olmalıdır; örneğin, ile </project>arasında</dependencies>.

<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>

Bu bölümde, HBase için yapılandırma bilgilerini içeren bir kaynak (conf/hbase-site.xml) yapılandırılır.

Dekont

Yapılandırma değerlerini kod aracılığıyla da ayarlayabilirsiniz. Örnekteki yorumlara CreateTable bakın.

Bu bölüm ayrıca Apache Maven Derleyici Eklentisi ve Apache Maven Gölge Eklentisi'ni yapılandırır. Derleyici eklentisi topolojiyi derlemek için kullanılır. Gölge eklentisi, Maven tarafından oluşturulan JAR paketinde lisans yinelemesini önlemek için kullanılır. Bu eklenti, HDInsight kümesinde çalışma zamanında "yinelenen lisans dosyaları" hatasını önlemek için kullanılır. Uygulamayla maven-shade-plugin kullanılması ApacheLicenseResourceTransformer hatayı önler.

Maven-shade-plugin ayrıca uygulamanın gerektirdiği tüm bağımlılıkları içeren bir uber jar dosyası oluşturur.

hbase-site.xml dosyasını indirin

HBase yapılandırmasını HBase kümesinden dizine kopyalamak için conf aşağıdaki komutu kullanın. yerine CLUSTERNAME HDInsight kümenizin adını yazın ve komutunu girin:

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

Uygulamayı oluşturma

CreateTable sınıfı uygulama

Yeni bir dosya CreateTable.javaoluşturmak ve açmak için aşağıdaki komutu girin. Yeni bir dosya oluşturmak için istemde Evet'i seçin.

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

Ardından aşağıdaki Java kodunu kopyalayıp yeni dosyaya yapıştırın. Ardından dosyayı kapatın.

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();
    }
}

Bu kod, adlı people bir tablo oluşturan ve önceden tanımlanmış bazı kullanıcılarla dolduran sınıfıdırCreateTable.

SearchByEmail sınıfı uygulama

Yeni bir dosya SearchByEmail.javaoluşturmak ve açmak için aşağıdaki komutu girin. Yeni bir dosya oluşturmak için istemde Evet'i seçin.

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

Ardından aşağıdaki Java kodunu kopyalayıp yeni dosyaya yapıştırın. Ardından dosyayı kapatın.

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();
    }
}

sınıfı, SearchByEmail satırları e-posta adresine göre sorgulamak için kullanılabilir. Normal ifade filtresi kullandığından, sınıfını kullanırken bir dize veya normal ifade sağlayabilirsiniz.

DeleteTable sınıfı uygulama

Yeni bir dosya DeleteTable.javaoluşturmak ve açmak için aşağıdaki komutu girin. Yeni bir dosya oluşturmak için istemde Evet'i seçin.

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

Ardından aşağıdaki Java kodunu kopyalayıp yeni dosyaya yapıştırın. Ardından dosyayı kapatın.

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");
    }
}

sınıfı, DeleteTable sınıfı tarafından oluşturulan tabloyu devre dışı bırakıp bırakarak bu örnekte oluşturulan HBase tablolarını CreateTable temizler.

Uygulamayı derleme ve paketleme

  1. Dizinden hbaseapp aşağıdaki komutu kullanarak uygulamayı içeren bir JAR dosyası oluşturun:

    mvn clean package
    

    Bu komut uygulamayı derler ve bir .jar dosyasına paketler.

  2. Komut tamamlandığında, hbaseapp/target dizin adlı hbaseapp-1.0-SNAPSHOT.jarbir dosya içerir.

    Dekont

    Dosya hbaseapp-1.0-SNAPSHOT.jar bir uber jar dosyasıdır. Uygulamayı çalıştırmak için gereken tüm bağımlılıkları içerir.

JAR'ı karşıya yükleme ve işleri çalıştırma (SSH)

Aşağıdaki adımlar, JAR'ı HDInsight kümesindeki Apache HBase'inizin birincil baş düğümüne kopyalamak için kullanılır scp . Ardından ssh komutu kümeye bağlanmak ve örneği doğrudan baş düğümde çalıştırmak için kullanılır.

  1. Jar dosyasını kümeye yükleyin. değerini HDInsight kümenizin adıyla değiştirin CLUSTERNAME ve aşağıdaki komutu girin:

    scp ./target/hbaseapp-1.0-SNAPSHOT.jar sshuser@CLUSTERNAME-ssh.azurehdinsight.net:hbaseapp-1.0-SNAPSHOT.jar
    
  2. HBase kümesine Bağlan. değerini HDInsight kümenizin adıyla değiştirin CLUSTERNAME ve aşağıdaki komutu girin:

    ssh sshuser@CLUSTERNAME-ssh.azurehdinsight.net
    
  3. Java uygulamasını kullanarak bir HBase tablosu oluşturmak için açık ssh bağlantınızda aşağıdaki komutu kullanın:

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

    Bu komut people adlı bir HBase tablosu oluşturur ve bunu verilerle doldurur.

  4. Tabloda depolanan e-posta adreslerini aramak için aşağıdaki komutu kullanın:

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

    Aşağıdaki sonuçları alırsınız:

    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. Tabloyu silmek için aşağıdaki komutu kullanın:

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

JAR'ı karşıya yükleme ve işleri çalıştırma (PowerShell)

Aşağıdaki adımlar, JAR'ı Apache HBase kümenizin varsayılan depolama alanına yüklemek için Azure PowerShell AZ modülünü kullanır. HdInsight cmdlet'leri daha sonra örnekleri uzaktan çalıştırmak için kullanılır.

  1. AZ modülünü yükleyip yapılandırdıktan sonra adlı hbase-runner.psm1bir dosya oluşturun. Bu dosyanın içeriği olarak aşağıdaki metni kullanın:

     <#
     .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 *-*
    

    Bu dosya iki modül içerir:

    • Add-HDInsightFile - Dosyaları kümeye yüklemek için kullanılır
    • Start-HBaseExample - daha önce oluşturulan sınıfları çalıştırmak için kullanılır
  2. hbase-runner.psm1 Dosyayı dizine hbaseapp kaydedin.

  3. Modülleri Azure PowerShell'e kaydedin. Yeni bir Azure PowerShell penceresi açın ve öğesini kümenizin adıyla değiştirerek CLUSTERNAME aşağıdaki komutu düzenleyin. Ardından aşağıdaki komutları girin:

    cd C:\HDI\hbaseapp
    $myCluster = "CLUSTERNAME"
    Import-Module .\hbase-runner.psm1
    
  4. kümenize yüklemek hbaseapp-1.0-SNAPSHOT.jar için aşağıdaki komutu kullanın.

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

    İstendiğinde küme oturum açma (yönetici) adını ve parolasını girin. komutu, öğesini kümenizin birincil depolama alanında bulunan konuma yükler hbaseapp-1.0-SNAPSHOT.jarexample/jars .

  5. kullanarak hbaseapptablo oluşturmak için aşağıdaki komutu kullanın:

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

    İstendiğinde küme oturum açma (yönetici) adını ve parolasını girin.

    Bu komut, HDInsight kümenizde HBase'de people adlı bir tablo oluşturur. Bu komut konsol penceresinde herhangi bir çıkış göstermez.

  6. Tablodaki girdileri aramak için aşağıdaki komutu kullanın:

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

    İstendiğinde küme oturum açma (yönetici) adını ve parolasını girin.

    Bu komut, sütun ailesinin ve sütunun contactinformation dizesini contoso.comiçerdiği satırları aramak için sınıfını kullanırSearchByEmail.email Aşağıdaki sonuçları almanız gerekir:

    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
    

    Değer için -emailRegex fabrikam.com kullanıldığında, e-posta alanında fabrikam.com olan kullanıcılar döndürülüyor. Arama terimi olarak normal ifadeleri de kullanabilirsiniz. Örneğin, ^r, 'r ' harfiyle başlayan e-posta adreslerini döndürür.

  7. Tabloyu silmek için aşağıdaki komutu kullanın:

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

Start-HBaseExample kullanılırken hiçbir sonuç veya beklenmeyen sonuç yok

-showErr İşi çalıştırırken oluşturulan standart hatayı (STDERR) görüntülemek için parametresini kullanın.

Sonraki adımlar

SQLLine'ı Apache HBase ile kullanmayı öğrenin