Automate HBase Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

HBase ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with HBase columnar databases.



Are you looking for a quick and easy way to access HBase data from PowerShell? We show how to use the Cmdlets for HBase and the CData ADO.NET Provider for HBase to connect to HBase data and synchronize, automate, download, and more.

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.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the HBase API, 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.

After obtaining the needed connection properties, accessing HBase data in PowerShell consists of three basic steps.

Set the Port and Server to connect to Apache HBase.

PowerShell

  1. Install the module:

    Install-Module ApacheHBaseCmdlets
  2. Connect:

    $apachehbase = Connect-ApacheHBase -Server "$Server" -Port "$Port"
  3. 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'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for HBase\lib\System.Data.CData.ApacheHBase.dll")
  2. Connect to HBase:

    $conn= New-Object System.Data.CData.ApacheHBase.ApacheHBaseConnection("Server=127.0.0.1;Port=8080;") $conn.Open()
  3. 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 HBase Data

PowerShell

Update-ApacheHBase -Connection $ApacheHBase -Columns @('CustomerName','Price') -Values @('MyCustomerName', 'MyPrice') -Table Customers -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.ApacheHBase.ApacheHBaseCommand("UPDATE Customers SET ShipCity='New York' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.ApacheHBase.ApacheHBaseParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert HBase Data

PowerShell

Add-ApacheHBase -Connection $ApacheHBase -Table Customers -Columns @("CustomerName", "Price") -Values @("MyCustomerName", "MyPrice")

ADO.NET

$cmd = New-Object System.Data.CData.ApacheHBase.ApacheHBaseCommand("INSERT INTO Customers (ShipCity) VALUES (@myShipCity)", $conn) $cmd.Parameters.Add(new System.Data.CData.ApacheHBase.ApacheHBaseParameter("@myShipCity","New York")) $cmd.ExecuteNonQuery()

Delete HBase Data

PowerShell

Remove-ApacheHBase -Connection $ApacheHBase -Table "Customers" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.ApacheHBase.ApacheHBaseCommand("DELETE FROM Customers WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.ApacheHBase.ApacheHBaseParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()