agentm / project-m36

Project: M36 Relational Algebra Engine
The Unlicense
876 stars 47 forks source link

add with macro with multiple views #212

Closed YuMingLiao closed 5 years ago

YuMingLiao commented 6 years ago

I've made a first pass, using the relation expression state. I use AS instead of := at a first pass just try to help me implement it from SQL WITH. However, It can be changed for any good reason. It supports multiple views. However, it can only reference previous ones.

TutorialD (master/main): :importexample date
TutorialD (master/main): :showexpr WITH (a AS s{s#,city}, b AS a{city}) b
┌──────────┐
│city::Text│
├──────────┤
│"Paris"   │
│"London"  │
│"Athens"  │
└──────────┘
agentm commented 6 years ago

Very cool! I like how straightforward the implementation is and that the macros can nest.

What happens if a temp relvar name overlaps with/shadows an existing name? I suspect we should be proactive and make that an error. What do you think?

YuMingLiao commented 6 years ago

Thanks!

I think the error is covered since I use runState evalDatabaseContextExpr (Assign ...) context, the existing code.

TutorialD (master/main): :importexample date
TutorialD (master/main): :showexpr WITH (s AS p) s
ERR: RelationTypeMismatchError [Attribute "s#" TextAtomType,Attribute "sname" TextAtomType,Attribute "status" IntegerAtomType,Attribute "city" TextAtomType] [Attribute "p#" TextAtomType,Attribute "pname" TextAtomType,Attribute "color" TextAtomType,Attribute "weight" IntegerAtomType,Attribute "city" TextAtomType]
TutorialD (master/main): :showexpr WITH (a AS s,a AS p) a
ERR: RelationTypeMismatchError [Attribute "s#" TextAtomType,Attribute "sname" TextAtomType,Attribute "status" IntegerAtomType,Attribute "city" TextAtomType] [Attribute "p#" TextAtomType,Attribute "pname" TextAtomType,Attribute "color" TextAtomType,Attribute "weight" IntegerAtomType,Attribute "city" TextAtomType]

code reusing Hooray!

agentm commented 6 years ago

But what if the attributes do match? Is there still an error? I would expect a RelVarAlreadyDefinedError.

YuMingLiao commented 6 years ago

Oh, I see. It's not a correct error. I need to define then assign.

YuMingLiao commented 6 years ago

Done!

TutorialD (master/main): :importexample date
TutorialD (master/main): :showexpr WITH (s AS p) s
ERR: RelVarAlreadyDefinedError "s"
TutorialD (master/main): :showexpr WITH (a AS s,a AS p) a
ERR: RelVarAlreadyDefinedError "a"