Automate Hive Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Apache Hive ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Apache Hive-compatible distributions.

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

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

Cmdlets or ADO.NET?

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

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

Set the Server, Port, TransportMode, and AuthScheme connection properties to connect to Hive.


  1. Install the module:

    Install-Module ApacheHiveCmdlets
  2. Connect:

    $apachehive = Connect-ApacheHive -Server "$Server" -Port "$Port" -TransportMode "$TransportMode"
  3. Search for and retrieve data:

    $country = "US" $customers = Select-ApacheHive -Connection $apachehive -Table "Customers" -Where "Country = `'$Country`'" $customers

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

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


  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.ApacheHive.ApacheHiveConnection("Server=;Port=10000;TransportMode=BINARY;") $conn.Open()
  3. 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 $ $_.companyname }

Update Hive Data


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


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

Insert Hive Data


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


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

Delete Hive Data


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


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