Google is pushing the new language Logica to solve the major flaws in SQL!
On April 12, 2021, Google introduced a new open-source logic programming language-Logica on its open-source blog.
Logica, named after logic and aggregation, which means logic + aggregation. Therefore, as the name implies, the creation of Logica further expands the classic logic programming syntax, especially in aggregation (refers to content selection, analysis, classification of relevant data, and finally analysis to obtain the desired result, mainly refers to any scalar value that can be generated from an array Data conversion process).
Not only did Google pack a ticket in its blog post: “You will love it!”, it also expressed its pride on Logica on Twitter, saying that it “can be compiled into SQL and run on Google BigQuery”:
To solve the shortcomings of SQL, Logica came into being
Before introducing Logica in detail, we must first clarify the meaning of “logic programming”.
Logic programming has been developed in academia since the late 1960s. Unlike conventional problem solving through setting steps, the process of logic programming is “facts + rules = results”, that is, set the rules that answers must conform to solve the problem. So logic programming is actually bringing the formal logic style into computer programming, where the program is written as a set of logic statements.
Among logic programming languages, the most representative examples are Prolog and Datalog, and the Logica introduced by Google this time is a language belonging to the Datalog family.
Datalog is a data query language. Because it has the same starting point as relational databases: it treats data as relations and data processing as a series of processing of these relations. Therefore, Datalog is used to design interactions with large-scale relational databases. But in the way of data processing, Datalog is different from the general language SQL for processing data: Datalog is inspired by the mathematical grammar of first-order logic, while SQL follows the grammar of the natural language.
SQL, which was invented in the 1970s, has developed so much after half a century. As small as smartwatches, as large as enterprise IT solution systems, you can see SQL in reading and writing data, and even the browser you are using while reading this article may contain a built-in SQL database.
The fundamental reason for this phenomenon is that SQL is developed based on natural language, which allows countless people without formal computer programming and mathematics training to access the database smoothly, and this is also a defect that SQL cannot make up for.
In SQL, it is often clear that the logic program is very simple, but the corresponding SQL query examples are complicated to understand. It often happens that a query needs to write hundreds of lines of sentences, not to mention that to maintain the old-fashioned COBOL spirit of the 70s, capital letters are often used throughout.
This is secondary. The main drawback of SQL is that it has very limited support for abstraction.
Good programming should be to create small, understandable, reusable logic fragments, and these logic fragments have to be tested, named, and organized into packages, which can then be used to construct more useful logic fragments. Such a workflow is reasonable and convenient, but SQL does not support it.
Therefore, to solve the shortcomings of SQL, Logica came into being.
Developers can “try a taste”.
As a logic programming language, Logica uses mathematical proposition logic specially designed by mathematicians, which simplifies the expression of complex sentences, can compile logic programs into SQL expressions, and is on Google BigQuery due to the convenience of logic programming syntax. Run (experimental support for PostgreSQL and SQLite).
Also, compared to the processing of disjunction and negation that may be encountered when converting from Datalog to SQL, Logica will try to make various choices for this to improve the readability of the generated SQL structure as much as possible, so that users Able to write programs that execute effectively.
Therefore, compared with SQL, Logica is more concise and supports reusable abstraction mechanisms that SQL lacks. It also supports modules and imports. It can also be used in interactive Python notebooks, and even makes testing queries natural and easy.
At present, Logica has been open-sourced under the Apache 2.0 license, and some code examples of Logica are shown on GitHub.
Google engineers also suggest that the majority of developers can try Logica, they think “you’ll like it”. Because even if it is not really used in the project, learning a powerful and new language will help developers generate new inspiration in the field of data processing and computing.
And, Logica may also be particularly suitable for the following three types of developers:
- Already use logic programming and need more powerful computing power;
- Use SQL, but not satisfied with its readability;
- I want to learn logic programming and apply it to big data processing.
Logica officials also stated that it plans to support more SQL statements and engines in the future, so programmers who are interested in this may be able to “try new things”.
Logica: organizing your data queries, making them universally reusable and fun
We present Logica, a novel open-source Logic Programming language. A successor to Yedalog (a language developed at…