waseigo

waseigo

Hello everyone,

A reader (@brownerd) of Northwind Elixir Traders has stumbled upon a weird issue that I am unable to replicate and it seems that it’s platform-specific.

The code in question is this very basic query:

  def list_top_n_customers_by_order_count(n \\ 5) when is_integer(n) do
    Customer
    |> join(:inner, [c], o in assoc(c, :orders))
    |> group_by([c, o], c.id)
    |> select([c, o], %{id: c.id, name: c.name, num_orders: count(o.id)})
    |> order_by([c, o], desc: count(o.id))
    |> limit(^n)
    |> Repo.all()
  end

When I’m running this function, I get the results just fine:

iex(892)> Insights.list_top_n_customers_by_order_count
[
  %{id: 20, name: "Ernst Handel", num_orders: 10},
  %{id: 63, name: "QUICK-Stop", num_orders: 7},
  %{id: 65, name: "Rattlesnake Canyon Grocery", num_orders: 7},
  %{id: 87, name: "Wartian Herkku", num_orders: 7},
  %{id: 37, name: "Hungry Owl All-Night Grocers", num_orders: 6}
]

When @brownerd runs the same code, he gets this:

** (FunctionClauseError) no function clause matching in anonymous fn/1 in Ecto.Adapters.SQLite3.Connection.group_by/2

The following arguments were given to anonymous fn/1 in Ecto.Adapters.SQLite3.Connection.group_by/2:

 # 1
 %Ecto.Query.ByExpr{
 expr: [{{:., [], [{:&, [], [0]}, :id]}, [], []}],
 file: ".../Northwind/northwind_elixir_traders/lib/northwind_elixir_traders/insights.ex",
 line: 43,
 params: nil,
 subqueries: []
 }
...

We checked our respective dependencies and there is nothing peculiar about them. We both use:

ecto 3.12.5
ecto_sql 3.12.1
ecto_sqlite3 0.15.1
exqlite 0.29.0

There are two differences in environment:

  • @brownerd uses Elixir 1.17, I use 1.18.2 – I doubt that this what causes the issue.
  • @brownerd is on a Mac, I’m on Debian – this smells more like the root cause of the issue.

Has anyone here encountered such an issue before? I have also opened an issue here:

https://github.com/elixir-sqlite/ecto_sqlite3/issues/160

Showing Posts 1 to 10

dimitarvp

dimitarvp

And what of the underlying SQLite versions? I’d think that’s the most likely culprit.

waseigo

waseigo OP

How do I check this? Is it the version of sqlite3_nif.so within ~/.cache/elixir_make/exqlite-nif-2.17-*.tar.gz?

Or does it relate to anything installed on system-level?

dimitarvp

dimitarvp

Both of you should run sqlite3 --version in your terminals and compare.

waseigo

waseigo OP

$ sqlite3 --version
3.40.1 2022-12-28 14:03:47 ...

Does using SQLite from Elixir depend on the version installed system-wide?

Johnny5

Johnny5

Unless you went out of your way to use system resources [1] then your system resources should have little to do with the failures (maybe could be differences in tooling to build the NIF though).

[1] GitHub - elixir-sqlite/exqlite: An SQLite3 driver for Elixir · GitHub

Johnny5

Johnny5

I’m not sure if your test suite is executed using GitHub Actions. However, it would be beneficial to test your code on both Linux and macOS. If you’re not already testing on macOS, it should be added to your testing environment.

waseigo

waseigo OP

sqlite3 --version
3.43.2 2023-10-10

waseigo

waseigo OP

No tests here, I still don’t know anything about testing :confused:

Also, now I regret installing Debian 12 on my 2012 MacBook Air–though it doesn’t really make a difference, if the issue is related with a precompiled binary for aarch64.

dimitarvp

dimitarvp

As a first step I’d suggest both of you upgrade to the latest SQLite, make sure your versions are identical, and test again.

Eliminate the differences in the environments one by one. The SQLite version should be the first thing that’s synchronized.

waseigo

waseigo OP

But how does the SQLite version installed system-wide impact what ex_sqlite uses? I thought it downloaded a precompiled version as a NIF, so since we both use the same package versions, both of our Elixir installations use the same (but most likely compiled for a different CPU arch, as most Macs right now use Apple Silicon)–or not?

tisaak@monster:~$ cd .cache/elixir_make/
tisaak@monster:~/.cache/elixir_make$ ls
exqlite-nif-2.17-x86_64-linux-gnu-0.29.0.tar.gz
tisaak@monster:~/.cache/elixir_make$ tar tf exqlite-nif-2.17-x86_64-linux-gnu-0.29.0.tar.gz 
./sqlite3_nif.so

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews