UNI DKE U03/11: Relational Algebra Interpreter

Introduction

The Relation Algebra Interpreter (or short RA Interpreter) is a program which can read CSV tables and perform some basic relation algebra on it, that is to say: Project, Join and Select operations.

This program was written for learning purposes. If you find it useful for anything else, keep in mind, that it was probably not designed to do what you want.

Compilation

If you are on a Linux system with the GNU Ada Compiler GNAT installed, it should be enough to type make to build this program. If you want to use Docker, you may either build this image with docker build . or run it directly with

docker run -it --rm masysma/uni-dke-u03-11-ra-interpreter

Otherwise, you will need to compile the program with any Ada 2012 compiler. The main file is ra_interpreter.adb.

Usage

The program runs interactively on the console and takes commands as input and prints resulting tables directly to the console.

Format your files as comma separated value, for example like test/t1.csv

File,Lines
gpl.ads,24
ra_interpreter.adb,26
csv.ads,32
func.ads,37

The first row is considered the schema of this relation which you can interactively load as follows:

RA> read(t1, test/t1.csv)

You will not get an answer, because you just load the relation into memory under the name t1 (first parameter to read).

In order to print a table, select all of its rows:

RA> SEL[1](t1)
ooooooooooooooooooooooooooooo
  File                Lines
+++++++++++++++++++++++++++++
  gpl.ads             24
  ra_interpreter.adb  26
  csv.ads             32
  func.ads            37
ooooooooooooooooooooooooooooo

It pretty-printed the relation.

Now, let’s add a condition to the select statement:

RA> SEL[(File = "csv.ads")](t1)
oooooooooooooooooo
  File     Lines
++++++++++++++++++
  csv.ads  32
oooooooooooooooooo

Note the parentheses around the condition, we wrote SEL[(...)]. If you consult what help has to say about this:

RA> help
[...]
Bool:  (v = v)    Compares values.
[...]

It says, that you have to put a comparison in parentheses This simplifies parsing but is a bit more to write. Also, comparison only works for values. You cannot compare Booleans with this program.

Finally, let’s have a look at an example for Natural Joining. Load the relation from test/t2.csv as t2 and perform a join on the two tables:

RA> load(t2, test/t2.csv)
RA> JOIN(t1,t2)
ooooooooooooooooooooooooooooooooooooooooo
  File                Lines  Size/Bytes
+++++++++++++++++++++++++++++++++++++++++
  gpl.ads             24     858
  ra_interpreter.adb  26     1038
  csv.ads             32     1126
  func.ads            37     1400
ooooooooooooooooooooooooooooooooooooooooo

… It works as expected joining the two relations on the common field File.

Explore the other options by viewing help. Most of them work as expected.

Issues

As this was created for learning purposes, it’s features are only rudimentary. Especially, you can not

Programming Language
This was written in Ada as a means of getting to know that language. Thus, there are probably a lot of beginner’s mistakes in there…

Ma_Sys.ma Website 5 (1.0.0) – no Flash, no JavaScript, no Webfont, no Copy Protection, no Mobile First. No bullshit. No GUI needed. Works with any browser.

Created: 2016/05/05 23:55:56 | Revised: 2020/02/17 23:58:50 | Tags: uni, dke, relation, algebra, interpreter, ra | Version: 1.0.0 | SRC (Pandoc MD) | GPL

Ma_Sys.ma Relation Algebra Interpreter 1.0.0.0, Copyright (c) 2016 Ma_Sys.ma. For further info send an e-mail to Ma_Sys.ma@web.de.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.