Automate Hive Integration Tasks from PowerShell
The CData ADO.NET Provider for Hive is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Hive.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for Hive; this tutorial shows how to use the Provider to create, retrieve, update, and delete Hive data.
Once you have acquired the necessary connection properties, accessing Hive data in PowerShell can be enabled in three steps.
Set the Server, Port, TransportMode, and AuthScheme connection properties to connect to Hive.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Hive\lib\System.Data.CData.ApacheHive.dll") -
Connect to Hive:
$conn= New-Object System.Data.CData.ApacheHive.ApacheHiveConnection("Server=127.0.0.1;Port=10000;TransportMode=BINARY;") $conn.Open() -
Instantiate the ApacheHiveDataAdapter, execute an SQL query, and output the results:
$sql="SELECT City, CompanyName from Customers" $da= New-Object System.Data.CData.ApacheHive.ApacheHiveDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.city $_.companyname }
Update Hive Data
$cmd = New-Object System.Data.CData.ApacheHive.ApacheHiveCommand("UPDATE Customers SET Country='US' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ApacheHive.ApacheHiveParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert Hive Data
$cmd = New-Object System.Data.CData.ApacheHive.ApacheHiveCommand("INSERT INTO Customers (Country) VALUES (@myCountry)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ApacheHive.ApacheHiveParameter("@myCountry","US")))
$cmd.ExecuteNonQuery()
Delete Hive Data
$cmd = New-Object System.Data.CData.ApacheHive.ApacheHiveCommand("DELETE FROM Customers WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.ApacheHive.ApacheHiveParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject