agentm / project-m36

Project: M36 Relational Algebra Engine
The Unlicense
894 stars 48 forks source link

some issues in prettyprinting relational expression #270

Closed YuMingLiao closed 3 years ago

YuMingLiao commented 3 years ago

I tried to write a prettyprinter for relational expression. Can't wait to post the work-in-process.

┌──────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬──────────────┐
│name::Text│sub::Text                                                                                                               │super::Text   │
├──────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────────────┤
│"p_sp_fk" │"sp{p#}"                                                                                                                │"p{p#}"       │
│"sp_pkey" │"relation{}{tuple{}}:{a:=sp}:{b:=count(@a)}{b} != relation{}{tuple{}}:{a:=sp{ p#                                        │"relation{}{}"│
│          │                                                                           , s# }}:{b:=count( @a )}{ b }"               │              │
│"s_pkey"  │"relation{  }{ tuple{  } }:{a:=s}:{b:=count( @a )}{ b } != relation{  }{ tuple{  } }:{a:=s{ s# }}:{b:=count( @a )}{ b }"│"relation{}{}"│
│"s_sp_fk" │"sp{s#}"                                                                                                                │"s{s#}"       │
│"p_pkey"  │"relation{  }{ tuple{  } }:{a:=p}:{b:=count( @a )}{ b } != relation{  }{ tuple{  } }:{a:=p{ p# }}:{b:=count( @a )}{ b }"│"relation{}{}"│
└──────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────────┘

any ideas?

agentm commented 3 years ago

Hi @YuMingLiao !

I also had been thinking about an expression to TutorialD generator but was uncertain if it would be useful. Do you have a specific use-case you wish to address?

:showexpr true:{a:=false}

This was due to a bug in the boolean atom parser. Fixed in 28f5d1e4d868ca061f7e8b42688c6ed574f8c02b.

true == false

Relational equality is closed on the relational expressions.

TutorialD (master/main): :showexpr true = true
┌┐
││
├┤
└┘

true != false

Oops- the tutd parser neglected to include this operator. Fixed in f7fc88861d352a97cf2cbb477c02a2be18cce335.

:showexpr false:{a:=1}:{b:=1}

Indeed, Date has a quick fix for this which is implemented in a45300a7145884ef330e28aad2352a889bbda1dd:

:showexpr true:{a:=1,b:=1}
┌──────────┬──────────┐
│a::Integer│b::Integer│
├──────────┼──────────┤
│1         │1         │
└──────────┴──────────┘

:showexpr false:{a:=true}:{b:=@a}

This works now:

:showexpr true:{a:=3,b:=@a}
┌──────────┬──────────┐
│a::Integer│b::Integer│
├──────────┼──────────┤
│3         │3         │
└──────────┴──────────┘
YuMingLiao commented 3 years ago

Hi @agentm !

I also had been thinking about an expression to TutorialD generator but was uncertain if it would be useful. Do you have a specific use-case you wish to address?

What do you mean by "an expression to TutoiralD generator"? I wrote this prettyprinter just for me to understand constraints. It's hard to read ADTs directly. Now I know what it looks like in a relational expression. It use counts and != to make constraints.

Thanks for the fix and explanation!

agentm commented 3 years ago

I assume you made a function of type RelationalExpr -> TutorialDString, right? I think that's a valuable improvement that could be used elsewhere, for example, to dump the database schema to a human-readable string.

agentm commented 3 years ago

I believe the tutd parsing issues in this ticket have been resolved. Please re-open if that is not that case.