We are proud to share our inclusion in the 2024 Gartner Magic Quadrant for Data Integration Tools. We believe this recognition reflects the differentiated business outcomes CData delivers to our customers.
Get the Report →Automate Presto Integration Tasks from PowerShell
Are you in search of a quick and easy way to access Presto data from PowerShell? This article demonstrates how to utilize the Presto Cmdlets for tasks like connecting to Presto data, automating operations, downloading data, 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.
About Presto Data Integration
Accessing and integrating live data from Trino and Presto SQL engines has never been easier with CData. Customers rely on CData connectivity to:
- Access data from Trino v345 and above (formerly PrestoSQL) and Presto v0.242 and above (formerly PrestoDB)
- Read and write access all of the data underlying your Trino or Presto instances
- Optimized query generation for maximum throughput.
Presto and Trino allow users to access a variety of underlying data sources through a single endpoint. When paired with CData connectivity, users get pure, SQL-92 access to their instances, allowing them to integrate business data with a data warehouse or easily access live data directly from their preferred tools, like Power BI and Tableau.
In many cases, CData's live connectivity surpasses the native import functionality available in tools. One customer was unable to effectively use Power BI due to the size of the datasets needed for reporting. When the company implemented the CData Power BI Connector for Presto they were able to generate reports in real-time using the DirectQuery connection mode.
Getting Started
PowerShell Cmdlets or ADO.NET Provider?
The Cmdlets are not only a PowerShell interface to Presto, 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.
Once you have acquired the necessary connection properties, accessing Presto data in PowerShell can be enabled in three 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-Object 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-Object 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-Object System.Data.CData.Presto.PrestoParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject