Ready to get started?

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

 Download Now

Learn more:

Apache Phoenix Icon Phoenix ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with HBase through Apache Phoenix.

Automate Phoenix Integration Tasks from PowerShell



Are you in search of a quick and easy way to access Phoenix data from PowerShell? This article demonstrates how to utilize the Phoenix Cmdlets for tasks like connecting to Phoenix data, automating operations, downloading data, and more.

The CData Cmdlets for Phoenix are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Phoenix.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to Phoenix, but also an SQL interface; this tutorial shows how to use both to retrieve Phoenix data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Phoenix. To access Phoenix data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Phoenix.

Once you have acquired the necessary connection properties, accessing Phoenix data in PowerShell can be enabled in three steps.

Connect to Apache Phoenix via the Phoenix Query Server. Set the Server and Port (if different from the default port) properties to connect to Apache Phoenix. The Server property will typically be the host name or IP address of the server hosting Apache Phoenix.

Authenticating to Apache Phoenix

By default, no authentication will be used (plain). If authentication is configured for your server, set AuthScheme to NEGOTIATE and set the User and Password properties (if necessary) to authenticate through Kerberos.

PowerShell

  1. Install the module:

    Install-Module ApachePhoenixCmdlets
  2. Connect:

    $apachephoenix = Connect-ApachePhoenix -Server "$Server" -Port "$Port"
  3. Search for and retrieve data:

    $id = "123456" $mytable = Select-ApachePhoenix -Connection $apachephoenix -Table "MyTable" -Where "Id = `'$Id`'" $mytable

    You can also use the Invoke-ApachePhoenix cmdlet to execute SQL commands:

    $mytable = Invoke-ApachePhoenix -Connection $apachephoenix -Query 'SELECT * FROM MyTable WHERE Id = @Id' -Params @{'@Id'='123456'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.ApachePhoenix.ApachePhoenixConnection("Server=localhost;Port=8765;") $conn.Open()
  3. Instantiate the ApachePhoenixDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Id, Column1 from MyTable" $da= New-Object System.Data.CData.ApachePhoenix.ApachePhoenixDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.column1 }