Ready to get started?

Learn more about the CData ADO.NET Provider for Impala or download a free trial:

Download Now

Automate Impala Integration Tasks from PowerShell

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

The CData Cmdlets for Impala 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 Impala.

Cmdlets or ADO.NET?

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

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

In order to connect to Apache Impala, set the Server, Port, and ProtocolVersion. You may optionally specify a default Database. To connect using alternative methods, such as NOSASL, LDAP, or Kerberos, refer to the online Help documentation.

PowerShell

  1. Install the module:

    Install-Module ApacheImpalaCmdlets
  2. Connect:

    $apacheimpala = Connect-ApacheImpala -Server "$Server" -Port "$Port"
  3. Search for and retrieve data:

    $country = "US" $customers = Select-ApacheImpala -Connection $apacheimpala -Table "Customers" -Where "Country = `'$Country`'" $customers

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

    $customers = Invoke-ApacheImpala -Connection $apacheimpala -Query 'SELECT * FROM Customers WHERE Country = @Country' -Params @{'@Country'='US'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.ApacheImpala.ApacheImpalaConnection("Server=127.0.0.1;Port=21050;") $conn.Open()
  3. Instantiate the ApacheImpalaDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT City, CompanyName from Customers" $da= New-Object System.Data.CData.ApacheImpala.ApacheImpalaDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.city $_.companyname }

Update Impala Data

PowerShell

Update-ApacheImpala -Connection $ApacheImpala -Columns @('City','CompanyName') -Values @('MyCity', 'MyCompanyName') -Table Customers -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.ApacheImpala.ApacheImpalaCommand("UPDATE Customers SET Country='US' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.ApacheImpala.ApacheImpalaParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Impala Data

PowerShell

Add-ApacheImpala -Connection $ApacheImpala -Table Customers -Columns @("City", "CompanyName") -Values @("MyCity", "MyCompanyName")

ADO.NET

$cmd = New-Object System.Data.CData.ApacheImpala.ApacheImpalaCommand("INSERT INTO Customers (Country) VALUES (@myCountry)", $conn) $cmd.Parameters.Add(new System.Data.CData.ApacheImpala.ApacheImpalaParameter("@myCountry","US")) $cmd.ExecuteNonQuery()

Delete Impala Data

PowerShell

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

ADO.NET

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