Connect Workday to your favorite reporting tools without moving data.
Learn More →Automate Impala Integration Tasks from PowerShell
Are you in search of a quick and easy way to access Impala data from PowerShell? This article demonstrates how to utilize the Impala Cmdlets and the CData ADO.NET Provider for Impala for tasks like connecting to Impala data, automating operations, downloading data, 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.
PowerShell Cmdlets or ADO.NET Driver?
The Cmdlets are not only a PowerShell interface to Impala, 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.
Once you have acquired the necessary connection properties, accessing Impala data in PowerShell can be enabled in three 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
-
Install the module:
Install-Module ApacheImpalaCmdlets
-
Connect:
$apacheimpala = Connect-ApacheImpala -Server "$Server" -Port "$Port"
-
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
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Impala\lib\System.Data.CData.ApacheImpala.dll")
-
Connect to Impala:
$conn= New-Object System.Data.CData.ApacheImpala.ApacheImpalaConnection("Server=127.0.0.1;Port=21050;") $conn.Open()
-
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()
CodeProject