![]() |
VOOZH | about |
The CData Cmdlets for HBase are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to HBase.
The Cmdlets are not only a PowerShell interface to HBase, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete HBase data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for HBase. To access HBase data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for HBase.
Once you have acquired the necessary connection properties, accessing HBase data in PowerShell can be enabled in three steps.
Set the Port and Server to connect to Apache HBase.
Install the module:
Install-Module ApacheHBaseCmdlets
Connect:
$apachehbase = Connect-ApacheHBase -Server "$Server" -Port "$Port"
Search for and retrieve data:
$shipcity = "New York" $customers = Select-ApacheHBase -Connection $apachehbase -Table "Customers" -Where "ShipCity = `'$ShipCity`'" $customers
You can also use the Invoke-ApacheHBase cmdlet to execute SQL commands:
$customers = Invoke-ApacheHBase -Connection $apachehbase -Query 'SELECT * FROM Customers WHERE ShipCity = @ShipCity' -Params @{'@ShipCity'='New York'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for HBase\lib\System.Data.CData.ApacheHBase.dll")
Connect to HBase:
$conn= New-Object System.Data.CData.ApacheHBase.ApacheHBaseConnection("Server=127.0.0.1;Port=8080;")
$conn.Open()
Instantiate the ApacheHBaseDataAdapter, execute an SQL query, and output the results:
$sql="SELECT CustomerName, Price from Customers"
$da= New-Object System.Data.CData.ApacheHBase.ApacheHBaseDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.customername $_.price
}
Update-ApacheHBase -Connection $ApacheHBase -Columns @('CustomerName','Price') -Values @('MyCustomerName', 'MyPrice') -Table Customers -Id "MyId"
$cmd = New-Object System.Data.CData.ApacheHBase.ApacheHBaseCommand("UPDATE Customers SET ShipCity='New York' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ApacheHBase.ApacheHBaseParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-ApacheHBase -Connection $ApacheHBase -Table Customers -Columns @("CustomerName", "Price") -Values @("MyCustomerName", "MyPrice")
$cmd = New-Object System.Data.CData.ApacheHBase.ApacheHBaseCommand("INSERT INTO Customers (ShipCity) VALUES (@myShipCity)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ApacheHBase.ApacheHBaseParameter("@myShipCity","New York")))
$cmd.ExecuteNonQuery()
Remove-ApacheHBase -Connection $ApacheHBase -Table "Customers" -Id "MyId"
$cmd = New-Object System.Data.CData.ApacheHBase.ApacheHBaseCommand("DELETE FROM Customers WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ApacheHBase.ApacheHBaseParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the HBase Data Provider to get started:
Download NowLearn more:
👁 Apache Hbase IconRapidly create and deploy powerful .NET applications that integrate with HBase columnar databases.