Automate Hive Integration Tasks from PowerShell

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Are you in search of a quick and easy way to access Hive data from PowerShell? This article demonstrates how to utilize the Hive Cmdlets for tasks like connecting to Hive data, automating operations, downloading data, and more.

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.

  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=127.0.0.1;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 $_.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()

Ready to get started?

Download a free trial of the Apache Hive Data Provider to get started:

 Download Now

Learn more:

Apache Hadoop Hive Icon Apache Hive ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Hive.