Ready to get started?

Download a free trial of the HBase Data Provider to get started:

 Download Now

Learn more:

Apache Hbase Icon HBase ADO.NET Provider

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

Automate HBase Integration Tasks from PowerShell



Are you in search of a quick and easy way to access HBase data from PowerShell? This article demonstrates how to utilize the HBase Cmdlets for tasks like connecting to HBase data, automating operations, downloading data, 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.

PowerShell Cmdlets or ADO.NET Provider?

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.

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-Object 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-Object 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-Object System.Data.CData.ApacheHBase.ApacheHBaseParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()