virtual relvar with new type
Posted: Wed Jul 21, 2010 4:40 pm
Hi,
I am not sure whether this is a feature or not, but given the following (same as previous bug-posts):
TYPE Pt POSSREP {X RATIONAL, Y RATIONAL};
TYPE L# POSSREP {L# CHAR};
TYPE LINESEG POSSREP { LINESEG RELATION {Pt Pt}};
VAR P BASE RELATION {Pt Pt} KEY {Pt};
VAR L BASE RELATION {L# L#} KEY {L#};
VAR LP BASE RELATION {L# L#, Pt Pt} KEY {L#, Pt};
// points
P := RELATION {
TUPLE {Pt Pt(0.0,0.0)},
TUPLE {Pt Pt(0.0,1.0)},
TUPLE {Pt Pt(1.0,0.0)},
TUPLE {Pt Pt(1.0,1.0)}
};
// LP (WHICH POINTS ARE IN WHICH LINESEGMENTS)
//CONSTRAINT LS_CON COUNT(LSPOINTS) = 2;
// line segment id numbers
L := RELATION {
TUPLE {L# L#("L1")},
TUPLE {L# L#("L2")},
TUPLE {L# L#("L3")},
TUPLE {L# L#("L4")},
TUPLE {L# L#("L5")}
};
// linesegment has points
LP := RELATION {
TUPLE {L# L#("L1"),Pt Pt(0.0,0.0)},
TUPLE {L# L#("L1"), Pt Pt(0.0,1.0)},
TUPLE {L# L#("L2"), Pt Pt(0.0,1.0)},
TUPLE {L# L#("L2"), Pt Pt(1.0,1.0)},
TUPLE {L# L#("L3"), Pt Pt(1.0,1.0)},
TUPLE {L# L#("L3"), Pt Pt(1.0,0.0)},
TUPLE {L# L#("L4"), Pt Pt(1.0,0.0)},
TUPLE {L# L#("L4"), Pt Pt(0.0,0.0)}
};
it is possible to define a virtual relvar as follows:
VAR LP2 VIRTUAL (EXTEND LP{L#} ADD (LINESEG(RELATION{ TUPLE{L# L#} } COMPOSE LP) AS LINESEG));
with output:
RELATION {L# L#, LINESEG LINESEG} {
TUPLE {L# L#("L1"), LINESEG LINESEG(RELATION {
TUPLE {Pt Pt(0.0, 0.0)},
TUPLE {Pt Pt(0.0, 1.0)}
})},
TUPLE {L# L#("L2"), LINESEG LINESEG(RELATION {
TUPLE {Pt Pt(0.0, 1.0)},
TUPLE {Pt Pt(1.0, 1.0)}
})},
TUPLE {L# L#("L3"), LINESEG LINESEG(RELATION {
TUPLE {Pt Pt(1.0, 0.0)},
TUPLE {Pt Pt(1.0, 1.0)}
})},
TUPLE {L# L#("L4"), LINESEG LINESEG(RELATION {
TUPLE {Pt Pt(0.0, 0.0)},
TUPLE {Pt Pt(1.0, 0.0)}
})},
TUPLE {L# L#("L5"), LINESEG LINESEG(RELATION {
TUPLE {Pt Pt(0.0, 0.0)}
})}
}
the interesting thing is that you can make the added column of a type LINESEG, which did not yet occur in the base relvars.
it's probably bad practice, but it allows using a new type (here: LINESEG) in a virtual relvar LP2 while the Point data that is introduced while creating a LINESEG relation is stored in the other base relvar P (no redundancy of points). It circumvents the problem that when the type LINESEG is an attribute of the base relvar LP the points defined in a particular LINESEG value cannot be queried from the table P even though they do exist and as such should be present in P
what is your opinion?
I am not sure whether this is a feature or not, but given the following (same as previous bug-posts):
TYPE Pt POSSREP {X RATIONAL, Y RATIONAL};
TYPE L# POSSREP {L# CHAR};
TYPE LINESEG POSSREP { LINESEG RELATION {Pt Pt}};
VAR P BASE RELATION {Pt Pt} KEY {Pt};
VAR L BASE RELATION {L# L#} KEY {L#};
VAR LP BASE RELATION {L# L#, Pt Pt} KEY {L#, Pt};
// points
P := RELATION {
TUPLE {Pt Pt(0.0,0.0)},
TUPLE {Pt Pt(0.0,1.0)},
TUPLE {Pt Pt(1.0,0.0)},
TUPLE {Pt Pt(1.0,1.0)}
};
// LP (WHICH POINTS ARE IN WHICH LINESEGMENTS)
//CONSTRAINT LS_CON COUNT(LSPOINTS) = 2;
// line segment id numbers
L := RELATION {
TUPLE {L# L#("L1")},
TUPLE {L# L#("L2")},
TUPLE {L# L#("L3")},
TUPLE {L# L#("L4")},
TUPLE {L# L#("L5")}
};
// linesegment has points
LP := RELATION {
TUPLE {L# L#("L1"),Pt Pt(0.0,0.0)},
TUPLE {L# L#("L1"), Pt Pt(0.0,1.0)},
TUPLE {L# L#("L2"), Pt Pt(0.0,1.0)},
TUPLE {L# L#("L2"), Pt Pt(1.0,1.0)},
TUPLE {L# L#("L3"), Pt Pt(1.0,1.0)},
TUPLE {L# L#("L3"), Pt Pt(1.0,0.0)},
TUPLE {L# L#("L4"), Pt Pt(1.0,0.0)},
TUPLE {L# L#("L4"), Pt Pt(0.0,0.0)}
};
it is possible to define a virtual relvar as follows:
VAR LP2 VIRTUAL (EXTEND LP{L#} ADD (LINESEG(RELATION{ TUPLE{L# L#} } COMPOSE LP) AS LINESEG));
with output:
RELATION {L# L#, LINESEG LINESEG} {
TUPLE {L# L#("L1"), LINESEG LINESEG(RELATION {
TUPLE {Pt Pt(0.0, 0.0)},
TUPLE {Pt Pt(0.0, 1.0)}
})},
TUPLE {L# L#("L2"), LINESEG LINESEG(RELATION {
TUPLE {Pt Pt(0.0, 1.0)},
TUPLE {Pt Pt(1.0, 1.0)}
})},
TUPLE {L# L#("L3"), LINESEG LINESEG(RELATION {
TUPLE {Pt Pt(1.0, 0.0)},
TUPLE {Pt Pt(1.0, 1.0)}
})},
TUPLE {L# L#("L4"), LINESEG LINESEG(RELATION {
TUPLE {Pt Pt(0.0, 0.0)},
TUPLE {Pt Pt(1.0, 0.0)}
})},
TUPLE {L# L#("L5"), LINESEG LINESEG(RELATION {
TUPLE {Pt Pt(0.0, 0.0)}
})}
}
the interesting thing is that you can make the added column of a type LINESEG, which did not yet occur in the base relvars.
it's probably bad practice, but it allows using a new type (here: LINESEG) in a virtual relvar LP2 while the Point data that is introduced while creating a LINESEG relation is stored in the other base relvar P (no redundancy of points). It circumvents the problem that when the type LINESEG is an attribute of the base relvar LP the points defined in a particular LINESEG value cannot be queried from the table P even though they do exist and as such should be present in P
what is your opinion?