Enable everyone in your organization to access their data in the cloud — no code required.
Learn More →Automate Presto Integration Tasks from PowerShell
Are you looking for a quick and easy way to access Presto data from PowerShell? We show how to use the Cmdlets for Presto and the CData ADO.NET Provider for Presto to connect to Presto data and synchronize, automate, download, and more.
The CData Cmdlets for Presto 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 Presto.
Cmdlets or ADO.NET?
The cmdlets are not only a PowerShell interface to the Presto API, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Presto data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Presto. To access Presto data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Presto.
After obtaining the needed connection properties, accessing Presto data in PowerShell consists of three basic steps.
Set the Server and Port connection properties to connect, in addition to any authentication properties that may be required.
To enable TLS/SSL, set UseSSL to true.
Authenticating with LDAP
In order to authenticate with LDAP, set the following connection properties:
- AuthScheme: Set this to LDAP.
- User: The username being authenticated with in LDAP.
- Password: The password associated with the User you are authenticating against LDAP with.
Authenticating with Kerberos
In order to authenticate with KERBEROS, set the following connection properties:
- AuthScheme: Set this to KERBEROS.
- KerberosKDC: The Kerberos Key Distribution Center (KDC) service used to authenticate the user.
- KerberosRealm: The Kerberos Realm used to authenticate the user with.
- KerberosSPN: The Service Principal Name for the Kerberos Domain Controller.
- KerberosKeytabFile: The Keytab file containing your pairs of Kerberos principals and encrypted keys.
- User: The user who is authenticating to Kerberos.
- Password: The password used to authenticate to Kerberos.
PowerShell
-
Install the module:
Install-Module PrestoCmdlets
-
Connect:
$presto = Connect-Presto -Server "$Server" -Port "$Port"
-
Search for and retrieve data:
$id = "123456789" $customer = Select-Presto -Connection $presto -Table "Customer" -Where "Id = `'$Id`'" $customer
You can also use the Invoke-Presto cmdlet to execute SQL commands:
$customer = Invoke-Presto -Connection $presto -Query 'SELECT * FROM Customer WHERE Id = @Id' -Params @{'@Id'='123456789'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Presto\lib\System.Data.CData.Presto.dll")
-
Connect to Presto:
$conn= New-Object System.Data.CData.Presto.PrestoConnection("Server=127.0.0.1;Port=8080;") $conn.Open()
-
Instantiate the PrestoDataAdapter, execute an SQL query, and output the results:
$sql="SELECT FirstName, LastName from Customer" $da= New-Object System.Data.CData.Presto.PrestoDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.firstname $_.lastname }
Update Presto Data
PowerShell
Update-Presto -Connection $Presto -Columns @('FirstName','LastName') -Values @('MyFirstName', 'MyLastName') -Table Customer -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.Presto.PrestoCommand("UPDATE Customer SET Id='123456789' WHERE Id = @myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.Presto.PrestoParameter("@myId","10456255-0015501366"))
$cmd.ExecuteNonQuery()
Insert Presto Data
PowerShell
Add-Presto -Connection $Presto -Table Customer -Columns @("FirstName", "LastName") -Values @("MyFirstName", "MyLastName")
ADO.NET
$cmd = New-Object System.Data.CData.Presto.PrestoCommand("INSERT INTO Customer (Id) VALUES (@myId)", $conn)
$cmd.Parameters.Add(new System.Data.CData.Presto.PrestoParameter("@myId","123456789"))
$cmd.ExecuteNonQuery()
Delete Presto Data
PowerShell
Remove-Presto -Connection $Presto -Table "Customer" -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.Presto.PrestoCommand("DELETE FROM Customer WHERE Id=@myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.Presto.PrestoParameter("@myId","001d000000YBRseAAH"))
$cmd.ExecuteNonQuery()
CodeProject