![]() |
VOOZH | about |
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.
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.
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'}
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-ApacheImpala -Connection $ApacheImpala -Columns @('City','CompanyName') -Values @('MyCity', 'MyCompanyName') -Table Customers -Id "MyId"
$cmd = New-Object System.Data.CData.ApacheImpala.ApacheImpalaCommand("UPDATE Customers SET Country='US' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ApacheImpala.ApacheImpalaParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-ApacheImpala -Connection $ApacheImpala -Table Customers -Columns @("City", "CompanyName") -Values @("MyCity", "MyCompanyName")
$cmd = New-Object System.Data.CData.ApacheImpala.ApacheImpalaCommand("INSERT INTO Customers (Country) VALUES (@myCountry)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ApacheImpala.ApacheImpalaParameter("@myCountry","US")))
$cmd.ExecuteNonQuery()
Remove-ApacheImpala -Connection $ApacheImpala -Table "Customers" -Id "MyId"
$cmd = New-Object System.Data.CData.ApacheImpala.ApacheImpalaCommand("DELETE FROM Customers WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ApacheImpala.ApacheImpalaParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Impala Data Provider to get started:
Download NowLearn more:
👁 Apache Impala IconRapidly create and deploy powerful .NET applications that integrate with Impala.