إنشاء تطبيقات Java لـ Apache HBase
تعرف على كيفية إنشاء تطبيق Apache HBase بـ Java. ثم استخدم التطبيق مع HBase على Azure HDInsight.
تستخدم الخطوات الواردة في هذا المستند Apache Maven لإنشاء المشروع وبنائه. Maven هي أداة لفهم وإدارة مشروع برمجي تتيح لك إنشاء برامج وتوثيق وتقارير لمشاريع Java.
المتطلبات الأساسية
نظام مجموعة Apache HBase على HDInsight. راجع البدء باستخدام Apache HBase.
Apache Mavenتم تثبيته بشكل صحيح وفقاً لـ Apache. Maven هو نظام بناء مشروع لمشاريع Java.
عميل SSH. لمزيد من المعلومات، يرجى الرجوع إلى الاتصال بـ HDInsight (Apache Hadoop) باستخدام SSH .
إذا كنت تستخدم PowerShell، فأنت بحاجة إلى وحدة AZ.
محرر نصوص. تستخدم هذه المقالة Microsoft Notepad.
بيئة الاختبار
كانت البيئة المستخدمة في هذه المقالة عبارة عن جهاز كمبيوتر يعمل بنظام التشغيل Windows 10. تم تنفيذ الأوامر في موجه الأوامر، وتم تحرير الملفات المختلفة باستخدام المفكرة. قم بالتعديل وفقاً لبيئتك.
من موجه الأوامر، أدخل الأوامر التالية لإنشاء بيئة عمل:
IF NOT EXIST C:\HDI MKDIR C:\HDI
cd C:\HDI
إنشاء مشروع Maven
أدخل الأمر التالي لإنشاء مشروع Maven باسم hbaseapp:
mvn archetype:generate -DgroupId=com.microsoft.examples -DartifactId=hbaseapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false cd hbaseapp mkdir conf
يقوم هذا الأمر بإنشاء دليل يسمى
hbaseapp
في الموقع الحالي، والذي يحتوي على مشروع Maven الأساسي. الأمر الثاني يغير دليل العمل إلىhbaseapp
. يقوم الأمر الثالث بإنشاء دليل جديد، ،conf
والذي يمكن استخدامه لاحقا. يحتوي دليلhbaseapp
على العناصر التالية:pom.xml
: يحتوي نموذج عنصر المشروع (POM) على معلومات وتفاصيل التكوين المستخدمة لبناء المشروع.src\main\java\com\microsoft\examples
: يحتوي على التعليمة البرمجية للتطبيق الخاص بك.src\test\java\com\microsoft\examples
: يحتوي على اختبارات لتطبيقك.
قم بإزالة مثال التعليمة البرمجية الذي تم إنشاؤه. احذف ملفات
AppTest.java
الاختبار والتطبيق التي تم إنشاؤها ، وعنApp.java
طريق إدخال الأوامر التالية:DEL src\main\java\com\microsoft\examples\App.java DEL src\test\java\com\microsoft\examples\AppTest.java
قم بتحديث نموذج عنصر المشروع
للحصول على مرجع كامل لملف pom.xml، راجع https://maven.apache.org/pom.html. افتح pom.xml
بإدخال الأمر التالي:
notepad pom.xml
إضافة تبعيات
في pom.xml
، أضف النص التالي في <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>
يشير هذا القسم إلى أن المشروع يحتاج إلى مكونات hbase-client وPhoenix-core . في وقت التحويل البرمجي، تُحمل هذه التبعيات من مستودع Maven الافتراضي. يمكنك استخدام Maven Central Repository Search لمعرفة المزيد حول هذه التبعية.
هام
يجب أن يتطابق رقم إصدار عميل hbase مع إصدار Apache HBase الذي يتم توفيره مع مجموعة HDInsight الخاصة بك. استخدم الجدول التالي للعثور على رقم الإصدار الصحيح.
نسخة نظام مجموعة HDInsight | إصدار Apache HBase المراد استخدامه |
---|---|
3.6 | 1.1.2 |
4.0 | 2.0.0 |
لمزيد من المعلومات حول إصدارات ومكونات HDInsight، راجع ما هي مكونات Apache Hadoop المختلفة المتوفرة مع HDInsight.
ضبط البنية
تتيح لك المكونات الإضافية لـ Maven بتخصيص مراحل بناء المشروع. يستخدم هذا القسم لإضافة المكونات الإضافية والموارد وخيارات تكوين الإنشاء الأخرى.
أضف التعليمات البرمجية التالية إلى ملف pom.xml
، ثم احفظ وأغلق الملف. يجب أن يكون هذا النص داخل العلامات <project>...</project>
في الملف، على سبيل المثال، بين </dependencies>
و</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>
يقوم هذا القسم بتكوين مورد (conf/hbase-site.xml
) يحتوي على معلومات التكوين لـ HBase.
إشعار
يمكنك أيضاً تعيين قيم التكوين عبر التعليمة البرمجية. انظر التعليقات في المثال CreateTable
.
يعمل هذا القسم أيضاً على تكوين Apache Maven Compiler Plugin وApache Maven Shade Plugin. يُستخدم المكون الإضافي للمحول البرمجي لتحويل الطوبولوجيا. يتم استخدام المكون الإضافي للظل لمنع تكرار الترخيص في حزمة JAR التي تم إنشاؤها بواسطة Maven. يتم استخدام هذا المكون الإضافي لمنع خطأ "ملفات الترخيص المكررة" في وقت التشغيل على مجموعة HDInsight. يؤدي استخدام maven-shade-plugin مع تنفيذ ApacheLicenseResourceTransformer
إلى منع حدوث الخطأ.
وينتج أيضًا إضافة ظل Maven uber jar التي تحتوي على جميع التبعيات المطلوبة من قبل التطبيق.
تنزيل ملف hbase-site.xml
استخدم الأمر التالي لنسخ تكوين HBase من نظام مجموعة HBase إلى الدليل conf
. استبدل CLUSTERNAME
باسم مجموعة HDInsight ثم أدخل الأمر:
scp sshuser@CLUSTERNAME-ssh.azurehdinsight.net:/etc/hbase/conf/hbase-site.xml ./conf/hbase-site.xml
قم بإنشاء التطبيق
تطبيق فئة CreateTable
أدخل الأمر التالي لإنشاء ملف CreateTable.java
جديد وفتحه. حدد Yes عند المطالبة لإنشاء ملف جديد.
notepad src\main\java\com\microsoft\examples\CreateTable.java
ثم انسخ والصق التعليمات البرمجية Java التالية في الملف الجديد. ثم أغلق الملف.
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();
}
}
هذه التعليمة البرمجية هي فئة CreateTable
، التي تنشئ جدولاً باسم people
وتعبئته ببعض المستخدمين المحددين مسبقاً.
تنفيذ فئة SearchByEmail
أدخل الأمر التالي لإنشاء ملف SearchByEmail.java
جديد وفتحه. حدد Yes عند المطالبة لإنشاء ملف جديد.
notepad src\main\java\com\microsoft\examples\SearchByEmail.java
ثم انسخ والصق التعليمات البرمجية Java التالية في الملف الجديد. ثم أغلق الملف.
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();
}
}
يمكن استخدام الفئة SearchByEmail
للاستعلام عن الصفوف بواسطة عنوان البريد الإلكتروني. نظراً لأنه يستخدم عامل تصفية تعبير عادي، يمكنك توفير سلسلة نصية أو تعبير عادي عند استخدام الفئة.
تطبيق فئة DeleteTable
أدخل الأمر التالي لإنشاء ملف DeleteTable.java
جديد وفتحه. حدد Yes عند المطالبة لإنشاء ملف جديد.
notepad src\main\java\com\microsoft\examples\DeleteTable.java
ثم انسخ والصق التعليمات البرمجية Java التالية في الملف الجديد. ثم أغلق الملف.
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");
}
}
تنظف الفئة DeleteTable
جداول HBase التي تم إنشاؤها في هذا المثال من خلال تعطيل وإفلات الجدول الذي تم إنشاؤه بواسطة الفئة CreateTable
.
بناء التطبيق وحزمه
من الدليل
hbaseapp
، استخدم الأمر التالي لإنشاء ملف JAR يحتوي على التطبيق:mvn clean package
يقوم هذا الأمر ببناء التطبيق وحزمه في ملف .jar.
عند اكتمال الأمر، يحتوي الدليل
hbaseapp/target
على ملف باسمhbaseapp-1.0-SNAPSHOT.jar
.إشعار
ملف
hbaseapp-1.0-SNAPSHOT.jar
هو uber jar. يحتوي على جميع التبعيات المطلوبة لتشغيل التطبيق.
تحميل JAR وتشغيل الوظائف (SSH)
تستخدم الخطوات التالية scp
لنسخ JAR إلى عقدة الرأس الأساسية في Apache HBase على مجموعة HDInsight. ثم يتم استخدام الأمر ssh
للاتصال بالمجموعة وتشغيل المثال مباشرة على العقدة الرئيسية.
قم بتحميل الجرة على النظام مجموعة. استبدل
CLUSTERNAME
باسم مجموعة HDInsight ثم أدخل الأمر التالي:scp ./target/hbaseapp-1.0-SNAPSHOT.jar sshuser@CLUSTERNAME-ssh.azurehdinsight.net:hbaseapp-1.0-SNAPSHOT.jar
الاتصال نظام مجموعة HBase. استبدل
CLUSTERNAME
باسم مجموعة HDInsight ثم أدخل الأمر التالي:ssh sshuser@CLUSTERNAME-ssh.azurehdinsight.net
لإنشاء جدول HBase باستخدام تطبيق Java، استخدم الأمر التالي في اتصال ssh المفتوح الخاص بك:
yarn jar hbaseapp-1.0-SNAPSHOT.jar com.microsoft.examples.CreateTable
يقوم هذا الأمر بإنشاء جدول HBase يسمى people، ويملؤه بالبيانات.
للبحث عن عناوين البريد الإلكتروني المخزنة في الجدول، استخدم الأمر التالي:
yarn jar hbaseapp-1.0-SNAPSHOT.jar com.microsoft.examples.SearchByEmail contoso.com
تتلقى النتائج التالية:
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
لحذف الجدول، استخدم الأمر التالي:
yarn jar hbaseapp-1.0-SNAPSHOT.jar com.microsoft.examples.DeleteTable
قم بتحميل JAR وتشغيل المهام (PowerShell)
تستخدم الخطوات التالية وحدة Azure PowerShell AZ لتحميل JAR إلى وحدة التخزين الافتراضية لمجموعة Apache HBase. ثم يتم استخدام أوامر HDInsight لتشغيل الأمثلة عن بعد.
بعد تثبيت وتكوين وحدة AZ، قم بإنشاء ملف باسم
hbase-runner.psm1
. استخدام النص التالي كمحتويات هذا الملف:<# .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 *-*
يحتوي هذا الملف على وحدتين:
- Add-HDInsightFile - تستخدم لتحميل الملفات إلى المجموعة
- Start-HBaseExample - تُستخدم لتشغيل الفئات التي تم إنشاؤها مسبقاً
احفظ ملف
hbase-runner.psm1
في الدليلhbaseapp
.قم بتسجيل الوحدات النمطية باستخدام Azure PowerShell. افتح نافذة Azure PowerShell جديدة وقم بتحرير الأمر التالي عن طريق استبدال
CLUSTERNAME
باسم نظام المجموعة الخاص بك. ثم أدخل الأوامر التالية:cd C:\HDI\hbaseapp $myCluster = "CLUSTERNAME" Import-Module .\hbase-runner.psm1
استخدم الأمر التالي لتحميل
hbaseapp-1.0-SNAPSHOT.jar
إلى مجموعتك.Add-HDInsightFile -localPath target\hbaseapp-1.0-SNAPSHOT.jar -destinationPath example/jars/hbaseapp-1.0-SNAPSHOT.jar -clusterName $myCluster
عند المطالبة، أدخل اسم تسجيل الدخول إلى المجموعة (المسؤول) وكلمة المرور. يقوم الأمر بتحميل
hbaseapp-1.0-SNAPSHOT.jar
إلى الموقعexample/jars
في التخزين الأساسي للمجموعة الخاصة بك.لإنشاء جدول باستخدام
hbaseapp
، استخدم الأمر التالي:Start-HBaseExample -className com.microsoft.examples.CreateTable -clusterName $myCluster
عند المطالبة، أدخل اسم تسجيل الدخول إلى المجموعة (المسؤول) وكلمة المرور.
يقوم هذا الأمر بإنشاء جدول يسمى أشخاص في HBase على مجموعة HDInsight الخاصة بك. لا يُظهر هذا الأمر أي إخراج في نافذة وحدة التحكم.
للبحث عن مدخلات في الجدول، استخدم الأمر التالي:
Start-HBaseExample -className com.microsoft.examples.SearchByEmail -clusterName $myCluster -emailRegex contoso.com
عند المطالبة، أدخل اسم تسجيل الدخول إلى المجموعة (المسؤول) وكلمة المرور.
يستخدم هذا الأمر الفئة
SearchByEmail
للبحث عن أي صفوف تحتوي فيها عائلة الأعمدةcontactinformation
والعمودemail
على السلسلةcontoso.com
. يجب أن تتلقى النتائج التالية: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
يؤدي استخدام fabrikam.com للقيمة
-emailRegex
إلى إرجاع المستخدمين الذين لديهم fabrikam.com في حقل البريد الإلكتروني. يمكنك أيضاً استخدام التعبيرات العادية كمصطلح بحث. على سبيل المثال، يعرض ^ r عناوين البريد الإلكتروني التي تبدأ بالحرف "r".لحذف الجدول، استخدم الأمر التالي:
Start-HBaseExample -className com.microsoft.examples.DeleteTable -clusterName $myCluster
لا توجد نتائج أو نتائج غير متوقعة عند استخدام Start-HBaseExample
استخدم المَعلمة -showErr
لعرض الخطأ القياسي (STDERR) الذي تم إنتاجه أثناء تشغيل الوظيفة.