![]() |
VOOZH | about |
The CData Cmdlets for Databricks 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 Databricks.
Accessing and integrating live data from Databricks has never been easier with CData. Customers rely on CData connectivity to:
While many customers are using CData's solutions to migrate data from different systems into their Databricks data lakehouse, several customers use our live connectivity solutions to federate connectivity between their databases and Databricks. These customers are using SQL Server Linked Servers or Polybase to get live access to Databricks from within their existing RDBMs.
Read more about common Databricks use-cases and how CData's solutions help solve data problems in our blog: What is Databricks Used For? 6 Use Cases.
The Cmdlets are not only a PowerShell interface to Databricks, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Databricks data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Databricks. To access Databricks data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Databricks.
Once you have acquired the necessary connection properties, accessing Databricks data in PowerShell can be enabled in three steps.
To connect to a Databricks cluster, set the properties as described below.
Note: The needed values can be found in your Databricks instance by navigating to Clusters, and selecting the desired cluster, and selecting the JDBC/ODBC tab under Advanced Options.
Install the module:
Install-Module DatabricksCmdlets
Connect:
$databricks = Connect-Databricks -Server "$Server" -Port "$Port" -TransportMode "$TransportMode" -HTTPPath "$HTTPPath" -UseSSL "$UseSSL" -User "$User" -Password "$Password"
Search for and retrieve data:
$country = "US" $customers = Select-Databricks -Connection $databricks -Table "Customers" -Where "Country = `'$Country`'" $customers
You can also use the Invoke-Databricks cmdlet to execute SQL commands:
$customers = Invoke-Databricks -Connection $databricks -Query 'SELECT * FROM Customers WHERE Country = @Country' -Params @{'@Country'='US'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Databricks\lib\System.Data.CData.Databricks.dll")
Connect to Databricks:
$conn= New-Object System.Data.CData.Databricks.DatabricksConnection("Server=127.0.0.1;Port=443;TransportMode=HTTP;HTTPPath=MyHTTPPath;UseSSL=True;User=MyUser;Password=MyPassword;")
$conn.Open()
Instantiate the DatabricksDataAdapter, execute an SQL query, and output the results:
$sql="SELECT City, CompanyName from Customers"
$da= New-Object System.Data.CData.Databricks.DatabricksDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.city $_.companyname
}
Update-Databricks -Connection $Databricks -Columns @('City','CompanyName') -Values @('MyCity', 'MyCompanyName') -Table Customers -Id "MyId"
$cmd = New-Object System.Data.CData.Databricks.DatabricksCommand("UPDATE Customers SET Country='US' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Databricks.DatabricksParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Databricks -Connection $Databricks -Table Customers -Columns @("City", "CompanyName") -Values @("MyCity", "MyCompanyName")
$cmd = New-Object System.Data.CData.Databricks.DatabricksCommand("INSERT INTO Customers (Country) VALUES (@myCountry)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Databricks.DatabricksParameter("@myCountry","US")))
$cmd.ExecuteNonQuery()
Remove-Databricks -Connection $Databricks -Table "Customers" -Id "MyId"
$cmd = New-Object System.Data.CData.Databricks.DatabricksCommand("DELETE FROM Customers WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Databricks.DatabricksParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the Databricks Data Provider to get started:
Download NowLearn more:
👁 Databricks IconRapidly create and deploy powerful .NET applications that integrate with Databricks.