![]() |
VOOZH | about |
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.
Accessing and integrating live data from Trino and Presto SQL engines has never been easier with CData. Customers rely on CData connectivity to:
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.
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.
In order to authenticate with LDAP, set the following connection properties:
In order to authenticate with KERBEROS, set the following connection properties:
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'}
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 -Connection $Presto -Columns @('FirstName','LastName') -Values @('MyFirstName', 'MyLastName') -Table Customer -Id "MyId"
$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()
Add-Presto -Connection $Presto -Table Customer -Columns @("FirstName", "LastName") -Values @("MyFirstName", "MyLastName")
$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()
Remove-Presto -Connection $Presto -Table "Customer" -Id "MyId"
$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
Download a free trial of the Presto Data Provider to get started:
Download NowLearn more:
👁 Presto IconRapidly create and deploy powerful .NET applications that integrate with Presto.