Google Logica is an open source declarative logic programming language in the field of data manipulation. Yedalog was predecessor of Logica. Yedalog was also created at Google before. Logica is for data scientists, engineers and other specialists who want to use logic programming syntax while writing queries and pipelines to run on Big Query.
Logica stands for Logic with aggregation.
Why to check Google Logica?
Compiler compiles Logica to StandardSQL and gives developer access to the power of BigQuery engine with the easy usability of logic programming syntax. This is helpful because BigQuery is much more powerful than state of the art native logic programming engines.
Explore logica if you find yourself in one or the below conditions:
Already using a programming language and require more computational power.
Readability is a concern while using SQL.
You are keen to learn a logic programming and apply it to Big Data Use cases.
Hearing Logic programming for the first time. What is it?
Logic programming is a declarative programming standard where the program is written with a set of logical executable statements.
This programming concept was first developed in academia from the late 60s. Prolog and Datalog are the most common examples of logic programming languages.
Logica is one of the languages of the Datalog family.
Datalog and relational databases start from the same thought process,
Conceptualize data as relations and data manipulation as a sequence of operations over these relations. But Datalog and SQL differ from operation aspects. Datalog is inspired completely by the mathematical syntax whereas SQL follows the syntax of natural language.
SQL was based on the natural language to give access to databases to the developer community without formal training in any programming languages. This usability may become pricy when the logic that you want to express is important. There are many examples present over internet of hard-to-read SQL queries that correspond to simple logic programs.
How does Google Logica work?
Logica compiles written logic program into a SQL programming expression, so it can be executed on BigQuery (SQL Engine).
Among database practitioners Datalog and SQL are known to be very much similar. The conversion from Datalog to SQL and back is often straight. However there are a few small differences, for e.g. how to utilize disjunction and negation. In Logica, Google has tried to make SQL structure as easy as possible, thus empowering user to write programs that are executed very efficiently.
How to learn?
Tutorial and examples show how to access Logica from CoLab. You can also install Logica command line tool.
To run Logica programs on BigQuery you will need a Google Cloud Project. Once you have a project you can run Logica programs in CoLab providing your project id.
To run Logica locally you need Python3.
Google Cloud Project is the only thing you need to run Google Logica in Colab, see Hello World example.
You can install Logica command with
pip as follows.
# Install. python3 -m pip install logica # Run: # To see usage message. python3 -m logica # To print SQL for HelloWorld program. python3 -m logica - print Greet <<<'Greet(greeting: "Hello world!")'
PATH includes Python’s
bin folder then you will also be able to run it simply as
logica - print Greet <<<'Greet(greeting: "Hello world!")'
Alternatively, you can clone GitHub repository:
git clone https://github.com/evgskv/logica cd logica ./logica - print Greet <<<'Greet(greeting: "Hello world!")'
Here a couple examples of how Logica code looks like.
Find prime numbers less than 30.
# Define natural numbers from 1 to 29. N(x) :- x in Range(30); # Define primes. Prime(prime: x) :- N(x), x > 1, ~( N(y), y > 1, y != x, Mod(x, y) == 0 );
The Logica tutorial is already available on Google.
Developers should start learning Logica if they are working with Google platforms and Big Data world. This is here to stay. Keep looking for more Teknonauts.com
Ashish is technology freak with around 10+ years of experience in IT Landscape. He started his journey as a device driver programmer in 2010. From that point he has evolved as a Mobility and IOT Architect, he completed his M.Tech from BITS Pilani as System Architect. He is working as IOT Architect at Siemens currently.