dfinke / PSDuckDB

PSDuckDB is a PowerShell module that provides seamless integration with DuckDB, enabling efficient execution of analytical SQL queries directly from the PowerShell environment.
MIT License
38 stars 4 forks source link

duckdb.dll not found in AzureAutomation when opening a connection #5

Open larsthelord opened 1 month ago

larsthelord commented 1 month ago

When opening the connection for DataSource = :memory:, the duckdb.dll i not located when running this module in Azure Automation. Tested both for Powershell 5.1 and PowerShell 7.2

Throwing exception points to DuckDBConnectionStringBuilder: image

but the stack trace shows that the duckdb.dll cannot be found: image

I am unsure where the duckdb.dll originates from. I couldn't find it in the DuckDB.NET-repo either, Could you share some information here and i could try to help debugging this.

dfinke commented 1 month ago

Thanks @larsthelord for trying PSDuckDB and reporting thi.

Hmm, not sure. Could you share the script? You can also try psduckdb in the console.

duckdb.dll is here https://github.com/dfinke/PSDuckDB/tree/main/lib and should be local when you do the install-module

larsthelord commented 1 month ago

The script is as simple as it gets.

$ErrorActionPreference = "Stop"
Import-Module PsDuckDb
try{
    $db = New-DuckDBConnection
    $db.Open()
} catch {
    $err = $_
    Get-Error
}

I don't know if you're familiar with Azure Automation, but it's basically a kind of sandbox in Azure that lets you PowerShell scripts.

The modules are installed via a Module-handler in Azure image

image

I did find the duckdb.dll in the repo. But what is it compiled from?

dfinke commented 1 month ago

Yes familiar with Az automation. I have not tried PSDuckDB there.

Are you running it on linux?

Here are details on it. I installed it from the nuget package.

https://duckdb.net/docs/getting-started.html

larsthelord commented 1 month ago

The $PsVersiontalbe in Automation Account says that it is running on Windows, but it is som kind of stripped down container thing. It doesn't allow you to do all of the usual stuff.

$PsVersionTable: image

image from here (https://learn.microsoft.com/en-us/azure/automation/automation-runbook-execution)

I built the DuckDb.dlls for linux and Windows. Got it working in PowerShell in wsl when including the .so-file, but when running it in Automation Account it now throws a different error:

image

So I don't think it is running on Linux.

I also tried adding the windows duckdb.dll and the libduckdb.so, but it just went back to the original exception

larsthelord commented 1 month ago

I've done some more reading. I see that the duckdb.dll is an unmanaged dll compiled from C. This might be the reason is won't work in Azure Automation, and that there is some restriction on unmanaged code.

And when it comes to if the Automation Account is Linux or Windows? It has a weird naming convention for its folders that is a mix of Windows and Linux standard.

Here is cwd, and the ModulePath for PsDuckDb image

When I get some time, I will try creating a simple unmanaged dll, then referencing it in another dll to see if the same problem appears. I will also have a look at putting the unmanaged dll into a combined dll to see if that makes a difference

dfinke commented 1 month ago

@larsthelord thanks for digging in!

dfinke commented 3 days ago

@larsthelord DuckDB update to a new version. I updated PSDuckDB.

It now works on my local PS 5.1. Give it a try.