26 Renaming with as
The as operator changes the output attribute name of a path tail.
For example:
u.student.name as studentName
The path still reaches student names, but the output attribute is named studentName
instead of name.
Its denotation as a frame is:
studentName=N:String
where
∃S:Student
u.student(S)
∧ S.name(N)
Restrictions on where as can be used
The as operator can be used wherever there is a single output attribute to rename.
This limits how it can be used after tuple construction:
a.() as x // wrong
a.(b) as x // allowed
a.(b, c) as x // wrong
Renaming inside tuple construction
Renaming is often used inside tuple construction, because path tails such as
student.name and course.code would otherwise have output names taken from their
final attributes.
u.enrolment.(student.name as studentName, course.code as courseCode)
The path tails are still evaluated from the same enrolment. The as clauses only
choose the output attribute names.
Avoiding name clashes
Renaming is also useful when two outputs would otherwise have the same name:
u.enrolment.(student.name as studentName, course.department.name as departmentName)
Both path tails would otherwise output an attribute named name. The as clauses
give them distinct output names.