Logica – Declarative logic programming language for data

by voaton 11/16/2024, 7:09 PMwith 66 comments

by dangon 11/16/2024, 7:37 PM

Related:

Google is pushing the new language Logica to solve the major flaws in SQL - https://news.ycombinator.com/item?id=29715957 - Dec 2021 (1 comment)

Logica, a novel open-source logic programming language - https://news.ycombinator.com/item?id=26805121 - April 2021 (98 comments)

by Agrailloon 11/16/2024, 9:52 PM

I think it is a good direction imho. Once being familiar with SQL I learned Prolog a little and similarities struck me. I wasn't the first one sure, and there are others who summarized it better than me [1] (2010-2012):

Each can do the other, to a limited extent, but it becomes increasingly difficult with even small increases in complexity. For instance, you can do inferencing in SQL, but it is almost entirely manual in nature and not at all like the automatic forward-inferencing of Prolog. And yes, you can store data(facts) in Prolog, but it is not at all designed for the "storage, retrieval, projection and reduction of Trillions of rows with thousands of simultaneous users" that SQL is.

I even wanted to implement something like Logica at the moment, primarily trying to build a bridge through a virtual table in SQLite that would allow storing rules as mostly Prolog statements and having adapters to SQL storage when inference needs facts.

[1]: https://stackoverflow.com/a/2119003

by Y_Yon 11/16/2024, 7:49 PM

If, like me, your first reaction is that this looks suspiciously like Datalog then you may be interested to learn that they indeed consider Logical to be "in the the Datalog family".

by usgroupon 11/17/2024, 8:15 AM

Its nice to see Logica has come on a bit. A year or two ago I tried to use this in production and it was very buggy.

The basic selling point is a compositional query language, so that over-time one may have a library of re-usable components. If anyone really has built such a library I'd love to know more about how it worked out in practice. It isn't obvious to me how those decorators are supposed to compose and abstract on first look.

Its also not immediately obvious to me how complicated your library of SQL has to be for this approach to make sense. Say I had a collection of 100 moderately complex and correlated SQL queries, and I was to refactor them into Logica, in what circumstances would it yield a substantial benefit versus (1) doing nothing, (2) creating views or stored procedures, (3) using DBT / M4 or some other preprocessor for generic abstraction.

by taericon 11/16/2024, 9:39 PM

I find the appeals to composition tough to agree with. For one, most queries begin as ad hoc questions. And can usually be tossed after. If they are needed for speed, it is the index structure that is more vital than the query structure. That and knowing what materialized views have been made with implications on propagation delays.

Curious to hear battle stories from other teams using this.

by anorak27on 11/17/2024, 1:18 AM

There's also Malloy[0] from Google that compiles into SQL

> Malloy is an experimental language for describing data relationships and transformations.

[0]: https://github.com/malloydata/malloy

by avodonosovon 11/16/2024, 10:38 PM

> Composite(a * b) distinct :- ...

Wait, does Logica factorize the number passed to this predicate when unifying the number with a * b?

So when we call Composite (100) it automatically tries all a's and b's who give 100 when m7ltiplied

I'd be curious to see the SQL it transpiles to.

by usgroupon 11/17/2024, 9:50 AM

Has anyone used Datalog with Datomic in anger? If so, what are your thoughts about Logica, and how does the proposition differ in your experience?

by transfireon 11/17/2024, 3:23 AM

Nice idea, but the syntax seems hacky.

by foobarquxon 11/16/2024, 9:56 PM

There don't seem to be any examples of how to connect to an existing (say sqlite) database even though it says you should try logica if "you already have data in BigQuery, PostgreSQL or SQLite,". How do you connect to an existing sqlite database?

by cess11on 11/16/2024, 9:26 PM

If this is how you want to compile to SQL, why not invent your own DCG with Prolog proper?

It should be easy enough if you're somewhat fluent in both languages, and has the perk of not being some Python thing at a megacorp famous for killing its projects.

by cynicalsecurityon 11/17/2024, 5:13 AM

This is going to be a hell in production. Someone is going to write queries in this new language and then wonder why the produced MySQL queries in production take 45 minutes to execute.

by riku_ikion 11/16/2024, 7:52 PM

Only one active committer on github..

by thenaturaliston 11/16/2024, 8:13 PM

I don't want to come off as too overconfident, but would be very hard pressed to see the value of this.

At face value, I shudder at the syntax.

Example from their tutorial:

EmployeeName(name:) :- Employee(name:);

Engineer(name:) :- Employee(name:, role: "Engineer");

EngineersAndProductManagers(name:) :- Employee(name:, role:), role == "Engineer" || role == "Product Manager";

vs. the equivalent SQL:

SELECT Employee.name AS name

FROM t_0_Employee AS Employee

WHERE (Employee.role = "Engineer" OR Employee.role = "Product Manager");

SQL is much more concise, extremely easy to follow.

No weird OOP-style class instantiation for something as simple as just getting the name.

As already noted in the 2021 discussion, what's actually the killer though is adoption and, three years later, ecosystem.

SQL for analytics has come an extremely long way with the ecosystem that was ignited by dbt.

There is so much better tooling today when it comes to testing, modelling, running in memory with tools like DuckDB or Ibis, Apache Iceberg.

There is value to abstracting on top of SQL, but it does very much seem to me like this is not it.