Commit Graph

209 Commits

Author SHA1 Message Date
Salvo 'LtWorf' Tomaselli
1b049e13f0 Better handling of parenthesis inside string literals
When scanning for the matching parenthesis, string literals
were not taken into account, which would inevitably lead to
errors if one wanted to do a selection on a string containing
a parenthesis.

Now it uses a state-machine to skip the ones that are located
inside literals.
2016-04-09 11:37:28 +02:00
Salvo 'LtWorf' Tomaselli
6bc219c635 Avoid proliferation of parenthesis
The str() function of the parse tree now emits expressions
with much less parenthesis.

This should allow optimized queries to be more readable.
2016-04-09 11:11:25 +02:00
Salvo 'LtWorf' Tomaselli
002aca3f68 Only holds for union
Does not hold for other operations.
2016-04-09 10:07:44 +02:00
Salvo 'LtWorf' Tomaselli
85f2b3c3ee Error message when compilation fails
Within selection, the compilation of the string into python bytecode
can fail.

This shows an appropriate message.
2016-03-31 21:45:59 +02:00
Salvo 'LtWorf' Tomaselli
7661d21da2 Better message for missing fields
Happens in projections, when trying to use a field that does not exist.
2016-03-31 21:45:59 +02:00
Salvo 'LtWorf' Tomaselli
72318bb0e8 Updated copyright notices
With the last year of modification of the file in question.
2016-03-31 21:45:59 +02:00
Salvo 'LtWorf' Tomaselli
ef209ea93f Do not crash on network error while sending survey 2016-03-21 14:50:50 +01:00
Salvo 'LtWorf' Tomaselli
f12e35fef9 Do not crash in case of connection failure
Return None to indicate a network failure.
2016-03-21 14:40:23 +01:00
Salvo 'LtWorf' Tomaselli
ce348149f1 Better code style 2016-01-03 19:43:38 +01:00
Salvo 'LtWorf' Tomaselli
1dd1298ee0 New optimization: useless projection
If a projection is done on every attribute it is useless and
can be removed.

The new optimization does this.
2016-01-03 17:15:04 +01:00
Salvo 'LtWorf' Tomaselli
17410a0b19 Styled code 2016-01-03 16:55:10 +01:00
Salvo 'LtWorf' Tomaselli
d384a902cf Removed redundant check
Assuming that the query is correct, the removed condition must
always be true.
2016-01-03 12:39:48 +01:00
Salvo 'LtWorf' Tomaselli
3b3888e9be New optimization
Turns
        π a,b,c(A) ∪ π a,b,c(B)

    into
        π a,b,c(A ∪ B)

    if A and B are union compatible

Works with union, intersection and difference.
2016-01-03 10:07:23 +01:00
Salvo 'LtWorf' Tomaselli
0dd2ef2f1d Style 2016-01-03 09:28:45 +01:00
Salvo 'LtWorf' Tomaselli
e3877a4682 Added function to split an assignment expression
In the UI, a common pattern was to check if a query was
prefixed by an assignment and in that case, assign the result
to the given name.

This function puts this in a common place, so it can be used from
all the parts where it is needed.
2016-01-02 15:25:43 +01:00
Salvo 'LtWorf' Tomaselli
950a2273c3 New query optimization
A * B ∪ A * C = A * (B ∪ C)
2015-12-31 14:26:28 +01:00
Salvo 'LtWorf' Tomaselli
cd6bd42a2b Use normal strings in intermediate steps
This uses the CallableString object only in the final step and not
during all the intermediate ones.

Since str is a native object, it is faster to use than a normal
object.

This is a very marginal optimization that will not yield any
gains :)
2015-11-20 15:50:09 +01:00
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