fireproofsocks

fireproofsocks

I was looking over Ecto and CockroachDB issue: (CaseClauseError) no case clause matching - #9 by Ankhers
The basic need we have is that we need many select queries such as this:

SELECT x, y, z
FROM foobar f
WHERE f.x = 'some-condition';

to be modified to include AS OF SYSTEM TIME, like this:

SELECT x, y, z
FROM foobar f
AS OF SYSTEM TIME '-5m'
WHERE f.x = 'some-condition';

These are called follower reads by Cockroach – it’s important to specify this to avoid data sync errors and to take advantage of reading from replicas. It basically allows the query to say “it’s ok if the data is x minutes old”.

The problem is that when Ecto generates the query or renders a fragment, the clauses appear in ways that are considered invalid (from Cockroach’s point of view). I’ve tried a few different things here including the fragment example in the other post as well as including literal clauses, but so far, I haven’t found a winning combination. It would be possible to come up with my own alternative to the from macro, but I’m hoping there’s an easier way.

Thanks in advance for any pointers!

Showing Posts 1 to 7

Ankhers

Ankhers

This is going to be a non-answer to your question but I think the proper way of handling this would be to create a CockroachDB adapter for ecto that can handle these scenarios. The good news is that ~99% of it should already be done.

If you take a look at the official ecto adapters, you will notice that there is a common SQL module that all of the SQL adapters will call. There is no reason we could not do the same with a cockroach adapter calling postgres. We would only need to implement the differences. In this case we could probably do something like

from(
  f in Foo,
  as_of_system_time: ^"-5m",
  where: ...
)

Then the adapter can all the postgres adapter for everything except the :as_of_system_time key and it can do its own thing.

There may be additional work that needs to be done, but this I think would be the way to get started.

fuelen

fuelen

This won’t even compile as the key is unknown.

Ankhers

Ankhers

Of course it does not compile right now. No one created the adapter that my comment is suggesting to make.

fireproofsocks

fireproofsocks OP

Hmm… there is this repo CockroachDB Ecto Adaptor — CockroachDB Ecto Adaptor v1.0.0
It’s been archived because it’s no longer needed (see GitHub - jumpn/ecto_cockroachdb: CockroachDB adaptor for Ecto 3.x · GitHub)

I guess I should figure out the functionality first before worrying about a package name…

Thank you for your suggestions @Ankhers – I’ll see if I can wrap my head around how the Ecto macros are structured.

Ankhers

Ankhers

Let me know if you would like help here. I do not have a project that uses cockroach right now, but I would like an excuse to use it. I might be able to throw something together that can be used as a base.

fuelen

fuelen

I mean, this is not only about adapter.
Building an Ecto.Query doesn’t depend on used adapter in compile time.
In order to add a new keyword, Ecto.Query struct has to be extended.

fireproofsocks

fireproofsocks OP

Right – I’ve just tracked this down in the code and I’ve reached the same conclusion. It seems like maybe what’s needed is more of an augmentation of Ecto.Query and not necessarily a completely separate database adapter. :thinking:

I started inspecting the %Ecto.Query{} struct that gets generated by an Ecto query (e.g. one including the from macro), but I didn’t see any way to manipulate that (granted, this may not be the simplest code to follow)

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
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
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
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
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
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

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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews