Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using local table/variable name to reference columns in relational algebra #205

Open
wants to merge 32 commits into
base: development
Choose a base branch
from

Conversation

rlaiola
Copy link
Contributor

@rlaiola rlaiola commented Apr 13, 2024

Reference issue

None.

What does this implement/fix?

This PR aims at providing a more flexible way to write queries based on the SQL standard and RDBMS implementations such as MySQL, PostgreSQL and MS SQL Server. In summary, it is possible to use the given name of a relation/expression via an assignment (local table/variable) to reference its columns in other relational algebra operators.

Bear in mind that the variable name still has no influence on the schema of the expression and that the names of the attributes/columns are not affected by an assignment. However, the attributes of the output relation can now be accessed using either its original names or the variable name.

Note: To run the tests refer to http://dbis-uibk.github.io/relax/calc/local/uibk/local/0

Test 1: project column of a temp table

t = R
pi t.a (t)
  • Before:
Screen Shot 2024-04-13 at 13 42 30 Screen Shot 2024-04-13 at 13 43 38
  • After:
Screen Shot 2024-04-13 at 13 45 05

How to test this PR?

Test it live at https://rlaiola.github.io/relax/calc/local/uibk/local/0. For automated tests visit https://rlaiola.github.io/relax/test.html

Some casual tests

-- Ex01
t = R
t

-- Ex02
t = R
pi a (t)

-- Ex03
t = R
pi R.a (t)

-- Ex04
t = R
pi t.a (t)

-- Ex05
t = R
pi a (
  sigma a>3 (t)
)

-- Ex06
t = R
pi R.a (
  sigma a>3 (t)
)

-- Ex07
t = R
pi t.a (
  sigma a>3 (t)
)

-- Ex08
t = R
pi a (
  sigma R.a>3 (t)
)

-- Ex09
t = R
pi R.a (
  sigma R.a>3 (t)
)

-- Ex10
t = R
pi t.a (
  sigma R.a>3 (t)
)

-- Ex11
t = R x S
t

-- Ex12
t = R x S
pi a (t)

-- Ex13
t = R x S
pi R.a (t)

-- Ex14
t = R x S
pi t.a (t)

-- Ex15
t = R x S
pi t.a, R.b, S.b, d (t)

-- Ex16
t = R x S
pi t.a, R.b, S.b, d (
  sigma a>3 (t)
)

-- Ex17
t = R x S
pi t.a, R.b, S.b, d (
  sigma R.a>3 (t)
)

-- Ex18
t = R x S
pi t.a, R.b, S.b, d (
  sigma t.a>3 (t)
)

-- Ex19
t = R x S
pi t.a, R.b, S.b, d (
 sigma a>4 and
       d <= 200 and
       R.b=S.b (t)
)

-- Ex20
t = R x S
pi t.a, R.b, S.b, d (
  sigma R.a>4 and
        S.d <= 200 and
        R.b=S.b (t)
)

-- Ex21
t = R x S
pi t.a, R.b, S.b, d (
  sigma t.a>4 and
        t.d <= 200 and
        R.b=S.b (t)
)

-- Ex22
t = R x S
pi t.a, R.b, S.b, d (
  sigma t.a>4 and
        d <= 200 and
        R.b=S.b (t)
)

-- Ex23
t = R x S
pi t.a, R.b, S.b, d (
  sigma a>4 and
        t.d <= 200 and
        R.b=S.b (t)
)

-- Ex24
t = R x S
pi t.a, R.b, S.b, d (
  sigma a>4 and
        S.d <= 200 and
        R.b=S.b (t)
)

-- Ex25
t = R x S
pi t.a, R.b, S.b, d (
  sigma R.a>4 and
        d <= 200 and
        R.b=S.b (t)
)

-- Ex26
t = R join R.b=S.b S
t

-- Ex27
t = R join R.b=S.b S
pi a (t)

-- Ex28
t = R join R.b=S.b S
pi R.a (t)

-- Ex29
t = R join R.b=S.b S
pi t.a (t)

-- Ex30
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (t)

-- Ex31
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma a>3 (t)
)

-- Ex32
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma R.a>3 (t)
)

-- Ex33
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma t.a>3 (t)
)

-- Ex34
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma a>4 and
        d <= 200 and
        R.b=S.b (t)
)

-- Ex35
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma R.a>4 and
        S.d <= 200 and
        R.b=S.b (t)
)

-- Ex36
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma t.a>4 and
        t.d <= 200 and
        R.b=S.b (t)
)

-- Ex37
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma t.a>4 and
        d <= 200 and
        R.b=S.b (t)
)

-- Ex38
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma a>4 and
        t.d <= 200 and
        R.b=S.b (t)
)

-- Ex39
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma a>4 and
        S.d <= 200 and
        R.b=S.b (t)
)

-- Ex40
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma R.a>4 and
        d <= 200 and
        R.b=S.b (t)
)

-- Ex41
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma R.a>4 and
        t.d <= 200 and
        R.b=S.b (t)
)

-- Ex42
t = R join R.b=S.b S
pi t.a, R.b, S.b, d (
  sigma t.a>4 and
        S.d <= 200 and
        R.b=S.b (t)
)

-- Ex43
t = R join R.b=S.b S
tau a asc, d desc (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex44
t = R join R.b=S.b S
tau R.a asc, d desc (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex45
t = R join R.b=S.b S
tau a asc, S.d desc (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex46
t = R join R.b=S.b S
tau R.a asc, S.d desc (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex47
t = R join R.b=S.b S
tau a asc, t.d desc (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex48
t = R join R.b=S.b S
tau t.a asc, d desc (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex49
t = R join R.b=S.b S
tau t.a asc, t.d desc (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex50
t = R join R.b=S.b S
tau R.a asc, t.d desc (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)


-- Ex51
t = R join R.b=S.b S
tau t.a asc, S.d desc (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex52
t = R join R.b=S.b S
gamma a ; count(d)->n (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex53
t = R join R.b=S.b S
gamma t.a ; count(d)->n (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex54
t = R join R.b=S.b S
gamma a ; count(t.d)->n (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex55
t = R join R.b=S.b S
gamma t.a ; count(t.d)->n (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex56
t = R join R.b=S.b S
gamma R.a ; count(t.d)->n (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex57
t = R join R.b=S.b S
gamma t.a ; count(S.d)->n (
  pi R.a, R.b, S.b, S.d (
    sigma t.a>4 and
          S.d <= 200 and
          R.b=S.b (t)
  )
)

-- Ex58
t = R x S
rho a->aa, d->dd (t)

-- Ex59
t = R x S
rho R.a->aa, d->dd (t)

-- Ex60
t = R x S
rho a->aa, S.d->dd (t)

-- Ex61
t = R x S
rho t.a->aa, d->dd (t)

-- Ex62
t = R x S
rho a->aa, t.d->dd (t)

-- Ex63
t = R x S
rho t.a->aa, t.d->dd (t)

-- Ex64
t = R x S
rho R.a->aa, t.d->dd (t)

-- Ex65
t = R x S
rho t.a->aa, S.d->dd (t)

-- Ex66
t = R
pi (t.a * 2)->doublea (t)

@rlaiola rlaiola changed the title Allow using temporary table name to reference a column Allow using temporary table name to reference columns Apr 13, 2024
@rlaiola rlaiola changed the title Allow using temporary table name to reference columns Allow using temporary table name to reference columns in relational algebra Apr 14, 2024
@rlaiola rlaiola changed the title Allow using temporary table name to reference columns in relational algebra Allow using local table/variable name to reference columns in relational algebra Apr 16, 2024
@rlaiola
Copy link
Contributor Author

rlaiola commented Oct 15, 2024

PR #215 must be merged before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant