AlexR2D2 / duckdbex

The Library embeds C++ DuckDB database into you Elixir application.
MIT License
72 stars 16 forks source link

ArgumentError on mac m1 #9

Closed ruslandoga closed 2 months ago

ruslandoga commented 1 year ago

👋

Here's what I'm running on:

$ uname -a
Darwin mac3.local 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:39:35 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T8103 arm64

Here's what I'm doing:

iex(1)> Mix.install [:duckdbex], force: true
Resolving Hex dependencies...
Resolution completed in 0.032s
New:
  cc_precompiler 0.1.7
  duckdbex 0.2.3
  elixir_make 0.7.6
* Getting duckdbex (Hex package)
* Getting cc_precompiler (Hex package)
* Getting elixir_make (Hex package)
==> elixir_make
Compiling 6 files (.ex)
Generated elixir_make app
==> cc_precompiler
Compiling 3 files (.ex)
Generated cc_precompiler app
==> duckdbex
Compiling 3 files (.ex)
Generated duckdbex app
:ok

iex(2)> {:ok, conn} = Duckdbex.open()
{:ok, #Reference<0.2113251800.2909405206.141355>}

iex(3)> Duckdbex.query(conn, "select 1 + 1")
** (ArgumentError) argument error
    (duckdbex 0.2.3) Duckdbex.NIF.query(#Reference<0.2113251800.2909405206.141355>, "select 1 + 1")
    iex:5: (file)
jtippett commented 2 months ago

Hey @ruslandoga i think the problem is the force install. I don't know exactly what's happening under the covers but it doesn't work after just being force-installed in the same session.

Opening another session works fine:

Interactive Elixir (1.17.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Mix.install [:duckdbex]
:ok
iex(2)> {:ok, db} = Duckdbex.open()
{:ok, #Reference<0.3592413063.3482976278.227186>}
iex(3)> {:ok, conn} = Duckdbex.connection(db)
{:ok, #Reference<0.3592413063.3482976283.226873>}
iex(4)> {:ok, result} = Duckdbex.query(conn, "SELECT 1;")
{:ok, #Reference<0.3592413063.3482976278.227189>}
iex(5)> Duckdbex.columns(result)
["1"]
AlexR2D2 commented 2 months ago

Hi @ruslandoga could you try the latest release? It looks like you were previously installing precompiled macOS binaries for Intel Arc, but now the binaries are precompiled for ARM

jtippett commented 2 months ago

Hey @AlexR2D2 I'm on M1 mac as well and can confirm that it fails as shown if installed for the first time in iex as reported, but works fine when loaded from a mix.exs or in another iex session (without force: true).

The problem is Mix.install [:duckdbex], force: true and being installed in the same session as it's then being used.

ruslandoga commented 2 months ago

👋 @AlexR2D2

iex(1)> Mix.install [:duckdbex]
Resolving Hex dependencies...
Resolution completed in 0.097s
New:
  cc_precompiler 0.1.10
  duckdbex 0.3.2
  elixir_make 0.8.4
* Getting duckdbex (Hex package)
* Getting cc_precompiler (Hex package)
* Getting elixir_make (Hex package)
==> elixir_make
Compiling 8 files (.ex)
Generated elixir_make app
==> cc_precompiler
Compiling 3 files (.ex)
Generated cc_precompiler app
==> duckdbex
Downloading precompiled NIF to /Users/x/Library/Caches/duckdbex-nif-2.17-aarch64-apple-darwin-0.3.2.tar.gz
Compiling 3 files (.ex)
Generated duckdbex app
:ok
iex(2)>  {:ok, conn} = Duckdbex.open()
{:ok, #Reference<0.2243614080.10354711.37132>}
iex(3)> Duckdbex.query(conn, "select 1 + 1")
** (ArgumentError) argument error
    (duckdbex 0.3.2) Duckdbex.NIF.query(#Reference<0.2243614080.10354711.37132>, "select 1 + 1")
    iex:3: (file)
iex(3)>
ruslandoga commented 2 months ago

This is the first ever install of duckdbex on this system

$ uname -a
Darwin mac4.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:16:46 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8112 arm64

It's M2 now :)

jtippett commented 2 months ago

@ruslandoga if you open a new iex and do the exact same thing again does it work?

ruslandoga commented 2 months ago

👋 @jtippett

iex(1)> Mix.install [:duckdbex]
:ok
iex(2)> {:ok, conn} = Duckdbex.open()
{:ok, #Reference<0.4148936330.816185365.169429>}
iex(3)> Duckdbex.query(conn, "select 1 + 1")
** (ArgumentError) argument error
    (duckdbex 0.3.2) Duckdbex.NIF.query(#Reference<0.4148936330.816185365.169429>, "select 1 + 1")
    iex:3: (file)
jtippett commented 2 months ago

OK, that is weird.

 % uname -a
Darwin black-lagoon 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000 arm64
% iex
Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]

Interactive Elixir (1.17.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Mix.install [:duckdbex]
:ok
iex(2)> {:ok, db} = Duckdbex.open()
{:ok, #Reference<0.1054172198.279838750.82317>}
iex(3)> {:ok, conn} = Duckdbex.connection(db)
{:ok, #Reference<0.1054172198.279838750.82320>}
iex(4)> {:ok, result} =Duckdbex.query(conn, "select 1 + 1")
{:ok, #Reference<0.1054172198.279838750.82321>}
iex(5)> Duckdbex.columns(result)
["(1 + 1)"]
ruslandoga commented 2 months ago

One difference I'm seeing is that I'm on Erlang/OTP 27 [erts-15.0].

$ elixir -v
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.17.1 (compiled with Erlang/OTP 27)
ruslandoga commented 2 months ago

Ah, silly me. I'm using it wrong.

iex(2)> {:ok, db} = Duckdbex.open()
iex(3)> {:ok, conn} = Duckdbex.connection(db)
jtippett commented 2 months ago

Oh. I think it's because you're running the query on the db ref. You need to get the conn ref.

jtippett commented 2 months ago

Lol. Well i missed it too...

ruslandoga commented 2 months ago

I think it's because you're running the query on the db ref. You need to get the conn ref.

Yes, thank you! Sorry for the false alarm :)

AlexR2D2 commented 2 months ago

and i missed it too ))))