Google publishes logic programming language Logica

Google has introduced a new declarative logical programming language Logica, designed to manipulate data and translate programs into the SQL language. The new language is aimed at those who want to use logic programming syntax when writing database queries. Currently, the resulting SQL code can be executed in Google BigQuery storage or in PostgreSQL and SQLite DBMS, support of which is still experimental. In the future, it is planned to expand the number of supported SQL dialects. The project code is written in Python and published under the Apache 2.0 license.

Logica continues the evolution of another Google-developed data processing language, Yedalog, and provides a layer of abstraction not available in native SQL. Queries in Logica are programmed in the form of a set of logical statements. Modules, imports, and the ability to use Logica from within the Jupyter Notebook interactive shell are supported. For example, to generate a summary of the most frequently mentioned people in the news for 2020, you can use the following Logica program to access the GDELT database: @OrderBy(Mentions, "mentions desc"); @Limit(Mentions, 10); Mentions(person:, mentions? += 1) distinct :- gdelt-bq.gdeltv2.gkg(persons:, date:), Substr(ToString(date), 0, 4) == "2020", the_persons == Split (persons, ";"), person in the_persons; $ logica mentions.l run Mentions +—————-+—————-+ | person | mentions_count | +—————-+—————-+ | donald trump | 3077130 | | los angeles | 1078412 | | joe biden | 1054827 | | george floyd | 872919 | | boris johnson | 674786 | | barack obama | 438181 | | vladimir putin | 410587 | | bernie sanders | 387383 | | andrew cuomo | 345462 | | las vegas | 325487| +—————-+—————-+

Writing complex queries in SQL leads to the need to write cumbersome multi-line chains that are not obvious to perception, hinder the reuse of parts of the query and make maintenance difficult. SQL can use views and functions for common repetitive calculations, but they don't support imports and don't provide the flexibility of high-level languages ​​(for example, you can't pass a function to a function). Logica allows you to compose programs into small, understandable and reusable logical blocks that can be tested, associated with specific names and grouped into packages available for use in other projects.

Source: opennet.ru

Add a comment