Commit Graph

342 Commits

Author SHA1 Message Date
Salvo 'LtWorf' Tomaselli
c2a772e797 Compile selection expression
When running a selection, compiling the expression into a code object
so that it does not need to be re-parsed per every iteration.

Since it saves one parse per iteration, the gains become more
noticeable as the size of the relations grow.
2015-11-20 15:48:20 +01:00
Salvo 'LtWorf' Tomaselli
a8c1b2a463 Revert copy on write optimization
In case of multiple renames, all of the resulting relations will point
to the same data, so writing on one and marking its only known copy
as writable would be incorrect.

For this to work, all the references should be kown to all the other
instances.

It is probably not worth to implement it.

Implemented test for the update
2015-11-18 12:15:03 +01:00
Salvo 'LtWorf' Tomaselli
78a2e63e14 Raise TypeError rather than generic Exception 2015-11-18 10:38:41 +01:00
Salvo 'LtWorf' Tomaselli
521ffd5d41 Reduce amount of useless copies
In case of a rename, the original relation and the resulting relations
are pointing to the same set.

In case of functions that change the relation, such as insert, a copy is
created to be able to write on it. But when writing on the other relation
a new copy would have been made too.

This fixes it, now when changing one relation, the other is marked as
writable as well.
2015-11-18 00:05:01 +01:00
Salvo 'LtWorf' Tomaselli
ff3a5935fc Use _make_writable also in delete function
This way the _make_writable can be changed in one place.
2015-11-17 23:52:26 +01:00
Salvo 'LtWorf' Tomaselli
1e464d9d4c Simplified update function
Now avoids duplicating code.
2015-11-17 23:50:58 +01:00
Salvo 'LtWorf' Tomaselli
f0608c7212 Simply __str__ function 2015-11-17 15:44:59 +01:00
Salvo 'LtWorf' Tomaselli
3012a08ff3 Removed unused variable 2015-11-11 17:01:52 +01:00
Salvo 'LtWorf' Tomaselli
bdddb29b64 Removed test code to run the optimizer interactively 2015-11-11 16:36:14 +01:00
Salvo 'LtWorf' Tomaselli
7b26423d90 Typo in variable name 2015-11-11 16:35:49 +01:00
Salvo 'LtWorf' Tomaselli
643adf4d0a Simplify some redundant code 2015-11-06 15:26:26 +01:00
Salvo 'LtWorf' Tomaselli
d5c5707213 load/save improvements 2015-10-10 02:10:33 +02:00
Salvo 'LtWorf' Tomaselli
be4217dec9 removed outdated comment 2015-10-10 02:02:35 +02:00
Salvo 'LtWorf' Tomaselli
6fad0cdf68 Solves mysterious issue
When running relational as an .exe file generated by
py2exe, that line might give an exception. Because of
reasons.

I don't know what the hell is going on and I don't care.
2015-09-14 19:45:09 +02:00
Salvo 'LtWorf' Tomaselli
d597076038 Subtle bug that occurred selecting after a join
Outer joins add the placeholder '---' that is used as some sort of NULL
value.

However select operations on such relations would always fail, because
relations are supposed to only contain values of class rstring, and
the placeholder was added as a regular string.

As a consequence, automatic casting would always fail, and the select
would always raise an exception.

Added a new test case with this specific case in mind.
2015-09-10 12:19:51 +02:00
Salvo 'LtWorf' Tomaselli
f7ac34b761 Fix exception
The reported exception will look uglier but will work for any kind of
weird tokenization that occurred.
2015-09-10 10:13:00 +02:00
Salvo 'LtWorf' Tomaselli
20ebf45271 Parser cleanup
The new method works fine to parse also unary operators.

This commit removes the special case.
2015-09-09 17:31:02 +02:00
Salvo 'LtWorf' Tomaselli
6c8b60cf34 Improve error handling
Provide a better error in case of operator missing
2015-09-09 17:28:12 +02:00
Salvo 'LtWorf' Tomaselli
c30456c43e Fix bug in parser
The excessive stripping would cause "peo ple" to be recognized as
the relation "people" rather than an invalid thing.
2015-09-09 17:23:12 +02:00
Salvo 'LtWorf' Tomaselli
5f3564a398 Fix bug in tokenizer
It would not work with relations named like "l3"
2015-09-09 16:48:17 +02:00
Salvo 'LtWorf' Tomaselli
ab46ad2a54 Typo in comments 2015-09-09 15:22:15 +02:00
Salvo 'LtWorf' Tomaselli
9330090362 Switch to compiled regular expressions
This introduces several advantages:

No longer rely on the cache to be able to contain as many as
needed. It works within relational but it is not assured to be so if it
is used within other projects.

Using compile flags allows slightly simpler expressions.
2015-09-09 15:17:17 +02:00
Salvo 'LtWorf' Tomaselli
d8db1858ae Fix bug: imported removed module
import * would fail, because of a listed module that was removed.
2015-09-09 15:13:44 +02:00
Salvo 'LtWorf' Tomaselli
7742afd046 Removed redundant comments
Just pointing the documentation towards the website so that
only one copy of it must be kept up to date.
2015-08-05 20:32:57 +02:00
Salvo 'LtWorf' Tomaselli
0aa372792f Session management
Adds some functions to store and load an entire session as a binary
blob.

In this way the user does not need to re-load all the relations from the
previous session.
2015-08-03 15:56:37 +02:00
Salvo 'LtWorf' Tomaselli
be7e6fe12d Classes have now names that begin with uppercase
This is more Pythonic and makes the code more readable.

Backwards compatibility is provided by giving an alias with the
previous name of the class.

It will not be broken until the next major release.
2015-07-14 15:39:35 +02:00
Salvo 'LtWorf' Tomaselli
af02b5a59b Improved docstring 2015-07-14 15:08:39 +02:00
Salvo 'LtWorf' Tomaselli
c275c1caf3 Improve performance of __eq__
If the cardinality of two relations does not match, the expensive
rearrange procedure is not performed at all.
2015-07-14 11:11:13 +02:00
Salvo 'LtWorf' Tomaselli
f787630edb Use isinstance rather than comparing class attribute
This allows to create subclasses
2015-07-14 11:09:42 +02:00
Salvo 'LtWorf' Tomaselli
73dd14d9dd Style 2015-07-14 11:01:35 +02:00
Salvo 'LtWorf' Tomaselli
98ac364dc7 Removed encoding string
Not needed in Python 3
2015-07-14 10:43:13 +02:00
Salvo 'LtWorf' Tomaselli
9a570b4386 Use regexp constant
The regexp used was not even the same one…
2015-07-14 10:39:38 +02:00
Salvo 'LtWorf' Tomaselli
33d9545d66 Improved docstring 2015-07-14 10:38:14 +02:00
Salvo 'LtWorf' Tomaselli
e2ab59bcc4 Added public attribute with relation name regexp
Also simplified the function to check whether a name is valid for
a relation.
2015-07-14 10:35:54 +02:00
Salvo 'LtWorf' Tomaselli
9416a9fef9 Removed useless unicode marker from strings
We are using Python3 now, so that is not needed
2015-07-09 23:43:54 +02:00
Salvo 'LtWorf' Tomaselli
df485e4bd4 Make use of callable string
Instead of explicitly using eval, make use of the
new callable string feature
2015-07-09 23:42:52 +02:00
Salvo 'LtWorf' Tomaselli
4f85a545bf parse function returns a callable string
The python string returned by the parser are now directly callable.

They accept an optional parameter for the context.
2015-07-09 23:35:45 +02:00
Salvo 'LtWorf' Tomaselli
f5e8e442a0 Removed unused variables 2015-07-09 23:32:46 +02:00
Salvo 'LtWorf' Tomaselli
f6b4c6708b _rearrange() is an identity if not needed
Operations are possible even when the order of the attributes is
not the same. Because ordering is just an implementation detail and
not an actual part of relational algebra.

A _rearrange() function exists to convert relations to have a similar
format and be able to operate on them.

The function would perform a projection in any case, which would cause
the creation of a new temporary relation, even when the relations where
already using the same order of attributes.

This commit fixes the issue by making it return an identity if the
operation is not necessary.
2015-06-25 16:46:10 +02:00
Salvo 'LtWorf' Tomaselli
95e375f44a Use dictionary comprehension in selection
When doing a selection, a new context (in the form of a dictionary)
is created.

Instead of re-using the same dictionary re-assigning the values, now
use a comprehension to avoid redundant reads.
2015-06-25 16:34:47 +02:00
Salvo 'LtWorf' Tomaselli
bcc7053892 Removed a couple of un-pythonic lines 2015-06-17 17:13:35 +02:00
Salvo 'LtWorf' Tomaselli
59d712e53f Interface handler can suggest names
The interface handler can suggest names for loaded
relations.

This can be used to remove duplicated code.
2015-06-17 16:35:01 +02:00
Salvo 'LtWorf' Tomaselli
226b340969 Create class in maintenance module to help the UIs
The class has methods commonly used by user interfaces, so that
they don't need to be implemented multiple times by different
UIs.
2015-06-16 13:15:11 +02:00
Salvo 'LtWorf' Tomaselli
923e515535 Fix the version checker for python3 2015-06-13 17:39:42 +02:00
Salvo 'LtWorf' Tomaselli
5021f1f8cb Use the insert() method to load files
In this way, checks are performed automatically on every tuple
and code is simplified.

This should make it safer to raise exceptions on files that are
not relations.
2015-06-07 14:03:24 +02:00
Salvo 'LtWorf' Tomaselli
a033cb769a Make header inherit from tupl
Rather than having a header class that contains a list of header,
change it to directly be an immutable tuple.

This simplifies the code because header can now be compared and
indexed like any other tuple.

Code had to be changed all over the place to cope with this new
datatype.
2015-06-06 15:22:11 +02:00
Salvo 'LtWorf' Tomaselli
d754a166a1 Removed duplicated check 2015-06-06 14:17:27 +02:00
Salvo 'LtWorf' Tomaselli
b12ea8d27a Raise exception for duplicated attrs in projection
Rather than ignoring them, raise an exception
2015-06-06 14:15:47 +02:00
Salvo 'LtWorf' Tomaselli
bbc2855cc5 Use list comprehension 2015-06-06 14:12:02 +02:00
Salvo 'LtWorf' Tomaselli
229a83f3ad Missing import 2015-06-06 13:52:39 +02:00