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

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
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
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
subsaharancoder
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews