A Data Mo del and A Query Language for Ob ject-Orien ted - - PDF document

a data mo del and a query language for ob ject orien ted
SMART_READER_LITE
LIVE PREVIEW

A Data Mo del and A Query Language for Ob ject-Orien ted - - PDF document

A Data Mo del and A Query Language for Ob ject-Orien ted Databases Mano jit Sark ar and Stev en P . Reiss Departmen t of Computer Science Bro wn Univ ersit y Pro vidence, Rho de Island 02912 CS-92-57 Decem b


slide-1
SLIDE 1 A Data Mo del and A Query Language for Ob ject-Orien ted Databases Mano jit Sark ar and Stev en P . Reiss Departmen t
  • f
Computer Science Bro wn Univ ersit y Pro vidence, Rho de Island 02912 CS-92-57 Decem b er 1992
slide-2
SLIDE 2
slide-3
SLIDE 3 A Data Mo del and A Query Language for Ob ject-Orien ted Databases
  • Mano
jit Sark ar Stev en P . Reiss Departmen t
  • f
Computer Science Bro wn Univ ersit y Pro vidence, RI 02912 USA Abstract W e presen t an
  • b
ject-orien ted data mo del, and a p
  • w-
erful declarativ e query language. The data mo del elimi- nates the
  • bje
ct-versus-values dic hotom y b y represen ting all en tities as
  • b
jects. This is ac hiev ed at no loss
  • f
mo d- eling p
  • w
er,
  • r
p erformance. The data mo del pro vides for priv ate
  • wnership
  • f
  • b
jects b y
  • ther
  • b
jects. The
  • p
erational part
  • f
the data mo del is also simple. W e presen t a rule-based query language called OQL (Ob- ject Query Language) based
  • n
the data mo del. OQL creates and manipulates
  • b
jects without explicitly re- ferring to
  • b
ject iden tiers. It is statically t yp ed, and capable
  • f
creating new
  • b
jects
  • f
arbitrary t yp es. It can express recursiv e queries, eliminate duplicates, manipu- late mixture
  • f
tuple-v alued, set-v alued and list-v alued
  • b
jects, and express queries in v
  • lving
inheritance trees. W e presen t an
  • b
ject-algebra, an assignmen t
  • p
erator, and a REPEA T UNTIL lo
  • p
construct whic h are used to implemen t OQL. Reduction
  • f
OQL to algebra, as- signmen t
  • p
eration, and lo
  • p
construct, and reduction
  • f
algebra, assignmen t
  • p
eration, and lo
  • p
construct to OQL are also discussed. 1 Motiv ation W e started in v estigating
  • b
ject-orien ted database sys- tems for constructing abstract information ab
  • ut
pro- grams, called pr
  • gr
am abstr actions, b y retrieving infor- mation from some form
  • f
stored represen tation
  • f
pro- grams, called pr
  • gr
am datab ase. The idea is to generate abstractions b y querying the database, the answ ers to the queries are the target abstractions. These abstrac- tions are subsequen tly visualized graphically , and
  • ur
full system is a pr
  • gr
am visualization system 1 . The data mo del
  • f
  • ur
full program visualization sys- tem is
  • b
ject-orien ted, and w e w an ted a database with a compatible data mo del. This pap er presen ts a data
  • Supp
  • rt
for this researc h w as pro vided b y NSF gran ts CCR9111507 and CCR9113226, b y ARP A
  • rder
8225 and b y ONR gran t N00014-91-J-40 52 1 Readers in terested in
  • ur
program visualization system are referred to [16 ] mo del, and a query language to b e used with
  • ur
pro- gram visualization system. The query language presen ted in this pap er is named OQL (Ob ject Query Language). OQL is declarativ e, and highly expressiv e. W e use the query language for b
  • th
denition and generation
  • f
abstractions. A declarativ e language can mak e this tasks easier. Our goal is to de- v elop a language that is nearly as easy
  • r
more easy to use than SQL. Higher expressiv e p
  • w
er is desirable b e- cause that allo ws generation
  • f
wider range
  • f
abstrac- tions. Our mapping from abstraction
  • b
jects to their graph- ical visualization is t yp e-based. All the generated ab- stractions therefore m ust ha v e a t yp e. Also, to pro vide eectiv e program visualization,
  • ur
system m ust ha v e the capabilit y to generate abstractions that are not ex- pressed b y existing relationships in the database. OQL is therefore designed for creating
  • b
jects
  • f
an y arbitrary t yp e, and the users can dene a new t yp e at an y time. 2 Con tributions The data mo del presen ted in this pap er represen ts all en- tities as
  • b
jects. The system uses in ternally generated
  • bje
ct identiers for giving
  • b
jects their unique iden tit y . An
  • b
ject also has a state, and a b eha vior. Eac h
  • b
ject b elongs to a class. The class denes the structure
  • f
the
  • b
ject's state, and its b eha vior. Classes are
  • rganized
in inheritance hierarc h y . An
  • b
ject
  • f
a class
  • can
b e used where an
  • b
ject
  • f
  • 's
sup erclass is exp ected. Inher- itance p
  • lymorphism
is pro vided through late binding
  • f
metho ds based
  • n
actual classes
  • f
  • b
jects. Our data mo del is conceptually simple. It a v
  • ids
the
  • bje
cts-versus-values dic hotom y found in
  • ther
data mo dels suc h as in [11 , 12 , 3, 8]. This is ac hiev ed at no extra cost. W e also sho w that it is p
  • ssible
to satisfy a v ariet y
  • f
data mo deling requiremen ts suc h as values
  • f
O 2 , c
  • mp
  • site
  • bje
cts
  • f
ORION [4 , 10], and
  • wn
r ef
  • b-
jects
  • f
EX ODUS within the
  • b
ject-orien ted paradigm. The conceptual simplicit y
  • f
the data mo del do es not im- ply lo w er p erformance. It is p
  • ssible
to engineer in ternal
  • ptimizations
for go
  • d
p erformance. 1
slide-4
SLIDE 4 The query language OQL is the most imp
  • rtan
t con- tribution
  • f
this pap er. The language creates and ma- nipulates
  • b
jects without explicitly referring to
  • b
ject iden tiers. It is statically t yp ed. It is capable
  • f
creating new
  • b
jects
  • f
arbitrary t yp es. It can express recursiv e queries, and p erform duplicate elimination, and manip- ulate mixture
  • f
tuple-v alued, set-v aled, and list-v alued
  • b
jects. It is also capable
  • f
expressing queries in v
  • lving
inheritance trees. OQL is implemen ted using an
  • b
ject-algebra, an as- signmen t
  • p
erator, and a REPEA T UNTIL lo
  • p
con- struct. The algebra pro vides new
  • p
erators for
  • p
er- ating
  • n
mixture
  • f
set-v alued, and list-v alued
  • b
jects. The algebra and the language OQL are pro v ed equiv a- len t in expressiv e p
  • w
er. The data mo del, and the query language is under im- plemen tation. They ha v e b een designed with a practical application in mind. This is discussed in the Motiv a- tion section. Section 3 presen ts the data mo del. The algebraic
  • p
erators along with the assignmen t
  • p
erator and the lo
  • p
construct are describ ed in Section 4. The language OQL, its syn tax, t yp eing, and examples are in Section 5. Section 6 describ es the seman tics
  • f
the OQL programs, its translation to the
  • b
ject-algebra, and re- duction
  • f
the algebraic to OQL. Remaining issues and future researc h are men tioned in Section 7. 3 Data Mo del W e start a formal description
  • f
the data mo del with the follo wing pairwise disjoin t sets:
  • a
nite set
  • f
b asic typ es D
  • a
coun tably innite set
  • f
  • ids
O
  • a
nite set
  • f
attribute names A
  • a
nite set
  • f
metho d names M
  • a
nite set
  • f
class names C 3.1 V alues An
  • b
ject ma y ha v e a value . Only structur e d values can b e v alues
  • f
  • b
jects. Structured v alues are built from atomic values . Eac h mem b er
  • f
the domain asso ciated with a basic t yp e, and eac h mem b er O is an atomic v alue. This is formalized b elo w. 3.1.1 A tomic V alues There are four basic t yp es. These are Integer, Float, Boolean, and String. Hence D = fInteger, Float, Boolean, Stringg. The domains
  • f
basic t yp es are called basic domains. Basic domains are pairwise dis- join t. Eac h domain consists
  • f
a coun tably innite set
  • f
atomic v alues. F
  • r
example, the domain
  • f
t yp e Integer consists
  • f
the set
  • f
all in teger v alues. The atomic v alues in basic domains are also called b asic values as
  • pp
  • sed
to
  • ids.
A typ e is either a class
  • r
a basic t yp e. Classes are built from basic t yp es and classes using the Tuple, Set, and List constructors. A class built using the Tuple constructor is called a tuple-class . Similarl y a class built using the Set,
  • r
the List constructor is called a set- class ,
  • r
a list-class resp ectiv ely . O has three sp ecial mem b ers. These are nulltuple, nullset, and nulllist. They denote undened
  • b
jects
  • f
all tuple-classes, set-classes, and list-classes resp ec- tiv ely . The v alue
  • f
an undened
  • b
ject is assumed to b e unkno wn,
  • r
an empt y-set,
  • r
an empt y-list dep end- ing
  • n
the the class
  • f
the
  • b
ject. Eac h mem b er
  • f
O is also an atomic v alue. 3.1.2 Structured V alues Structured v alues are constructed from atomic v alues using the Tuple, Set, and List constructors. There is
  • ne
sp ecial structured v alue, [ ] whic h is used to denote the v alue an y tuple with zero attributes. Note that [ ] and nulltuple are not the same v alues. The former denotes a structured v alue, while the later is an atomic v alue and the
  • id
  • f
an
  • b
ject whose v alue is undened. Structured v alues are dened formally as follo ws:
  • the
v alue [ ] is a structured v alue
  • eac
h tuple
  • f
atomic v alues [a 1 : v 1 ; a 2 : v 2 ; . . . ; a n : v n ] is a tuple-value , where n > 0, a i 2 A and v i for i = 1; 2; . . . ; n are attribute names, and atomic v alues resp ectiv ely
  • eac
h set
  • f
atomic v alues fv 1 ; v 2 ; . . . ; v n g is a set- value , where n > 0, and v i for i = 1; 2; . . . ; n are atomic v alues
  • eac
h list
  • f
atomic v alues < v 1 ; v 2 ; . . . ; v n > is a list- value where n > 0, and v i for i = 1; 2; . . . ; n are atomic v alues A set-v alued
  • b
ject whose v alue is an empt y-set is con- sidered an undened
  • b
ject. Similarly , a list-v alued
  • b-
ject whose v alue is an empt y-list is also considered an undened
  • b
ject. W e denote the set
  • f
all the struc- tured v alues b y the coun tably innite set V. 3.2 Classes Eac h
  • b
ject b elongs to a class . The class describ es the structure
  • f
the
  • b
ject's v alue, and the
  • b
ject's b eha vior. The syn tax for class denitions is as follo ws: <class de cl> ! Class <class name> ! Class <class name> <class def> <class def> ! [Inherits <sup er class name>] <class struc> [Metho ds f<class metho d>g] <class struc> ! T uple `(' f<attr def>g `)'
slide-5
SLIDE 5 ! Set `(' <b asic domain> `)' ! Set `(' [Own] <class name> `)' ! Set `(' [Own] <class struc> `)' ! List `(' <b asic domain> `)' ! List `(' [Own] <class name> `)' ! List `(' [Own] <class struc> `)' <attr def> ! <attr name> `:' <b asic domain> ! [Own] <attr name> `:' <class name> ! [Own] <attr name> `:' <class struc> <class metho d> ! <metho d sig> <metho d b
  • dy>
<metho d sig> ! <metho d name> `(' f<p ar am def>g `)' `:' <r esult def> <p ar am def> ! <b asic domain> ! <class name> ! <class struc> <r esult def> ! <b asic domain> ! <class name> ! <class struc> <metho d b
  • dy>
! `f' <c
  • de>
`g' A class ma y b e dened b y sp ecifying a name, a sup er- class, a structure, and metho ds. Sup erclass and meth-
  • ds
are
  • ptional.
It is also p
  • ssible
to dene classes implicitly without an y name, sup erclass, and metho ds. Example 3.1 b elo w denes v e explicitly declared classes Point, Vertex, Edge, SegmentedEdge, and CurvedEdge. It also implicitly declares some classes with no name, no sup erclass, no metho ds. The class asso ciated with the attribute bendpoints
  • f
class SegmemtedEdge is suc h a class with structure List(Point). It is also p
  • ssible
to dene r e cursive classes. The syn tax also allo ws a class name to b e declared and used rst, and dened later. Example 3.1: The follo wing are some class declara- tions: Class Point Tuple (x: Float, y: Float) Methods fdistance (Point): Float f
  • gg;
Class Vertex Tuple (Own position: Point, label: String, radius: Float); Class Edge Tuple (source: Vertex, dest: Vertex, label: String) Methods flength (): Float f
  • gg;
Class SegmentedEdge Inherits Edge Tuple (Own bendpoints: List(Point)) Methods flength (): Float f
  • gg;
Class CurvedEdge Inherits Edge Tuple (Own controlpoints: List (Point)) Methods flength (): Float f
  • gg;
2 3.2.1 Structure All classes m ust ha v e a structur e . As sho wn ab
  • v
e, struc- tures are built using the Tuple, Set, and List construc- tors from basic t yp es, and already declared class names. An y
  • b
ject can b e p
  • ten
tially referenced b y man y
  • ther
  • b
jects. Sometimes it is necessary to prohibit suc h sharing, and allo w a class
  • f
  • b
jects to exclusiv ely refer to
  • ther
  • b
jects. This constrain t can b e sp ecied using the \Own" qualier in attribute denitions. An
  • b
ject held b y an attribute qualied as Own cannot b e refer- enced b y more than
  • ne
  • b
ject. 3.2.2 Metho ds A class declaration ma y ha v e zero
  • r
more metho ds as a part
  • f
the class denition. Metho ds dene the
  • b
ject's b eha vior. Eac h metho d is a function, it has a signatur e and a b
  • dy
. The signature is an expression
  • f
the form c : m( 1 ;
  • 2
; . . . ;
  • n
) !
  • r
where c is the r e c eiver class , m is the metho d name ,
  • 1
;
  • 2
; . . . ;
  • n
are the t yp es
  • f
the p ar ameters for some n
  • 0,
and
  • r
is the t yp e
  • f
the r eturn value . A metho d's b
  • dy
is a piece
  • f
co de written in some programming language, and it implemen ts the in tended function. 3.2.3 Inheritance A class declaration ma y sp ecify a sup er class as a part
  • f
its class denition. Inheritance [6 , 7 ] allo ws the user to deriv e new classes from existing classes. Only single- inheritance is allo w ed in
  • ur
data mo del i.e., a class can ha v e at most
  • ne
sup erclass 2 . The inheritance relationship is a partial
  • rder
  • n
the classes, i.e., it is r eexive , antisymmetric and tr ansitive . Since sup erclasses are
  • ptional,
the class hierarc h y is p
  • ten
tially a forest
  • f
man y disjoin t trees, and not a single tree 3 . A class inherits the attributes and the metho ds
  • f
its sup erclass b y default. The structure and metho d suite
  • f
the inheriting class therefore include the inherited at- tributes and metho ds resp ectiv ely . The inheriting class can dene additional attributes and metho ds,
  • r
redene inherited attributes and metho ds. Ho w ev er the resulting structure and metho d suite
  • f
the inheriting class m ust b e compatible to the structure and metho d suite
  • f
its sup erclass resp ectiv ely . F
  • r
denitions
  • f
structural and metho d suite compatibilit y see [17 ]. Sub class Relationshi p : The actual sub class relation- ship m ust b e sp ecied b y the user b y naming the sup er- 2 W e feel single-inherit anc e is adequate for
  • ur
mo deling goal. W e plan to incorp
  • rate
m ultiple-in he rita nce if
  • ur
later needs jus- tify the the additional complexit y . 3 W e therefore do not asso ciate system wide
  • p
erators with an y top-lev el class. In
  • ur
mo del, they are predened
  • p
erators appli- cable to an y
  • b
jects
  • f
compatible classes.
slide-6
SLIDE 6 class during the class denition
  • f
the sub class. Since implicitl y declared classes do not ha v e names, they can- not b e declared to b e sub class
  • r
sup erclass
  • f
an y
  • ther
class. The system therefore can assume that the implic- itly declared classes ha v e no sub class, and
  • ptimize
the represen tation and access
  • f
the
  • b
jects
  • f
suc h classes to ac hiev e b etter p erformance. Sub class relationship is denoted b y the sym b
  • l
\<". If c is a sub class
  • f
c , then c < c . Substit ut ib i li t y: Sub class relationships allo w an
  • b-
ject
  • f
class c to b e used in an y con text exp ecting an
  • b
ject
  • f
class c , where c is a sup erclass
  • f
c. Late Binding: Since an
  • b
ject
  • f
a certain class can b e assigned to a v ariable
  • f
its sup erclass, giv en a metho d call
  • n
a v ariable, sometimes the metho d to b e executed can
  • nly
b e determined at run time based
  • n
the
  • b
ject's actual class. This is kno wn as late binding . Ov erloadin g: Metho d names can also b e
  • verlo
ade d b y dening metho ds with the same name in more than
  • ne
class not related b y sub class-sup erclass relationships. Suc h metho d name
  • v
erloading can b e resolv ed at com- pile time based
  • n
metho d signatures. Class Equiv alence: Tw
  • classes
are e quivalent if they ha v e the same name. The system giv es in ternally gen- erated names to classes declared implicitly as the class asso ciated with the attribute bendpoints in Example 3.1. Implicitly declared classes with same structures are giv en the same in ternally generated name, hence they are equiv alen t. 3.3 Ob jects An
  • b
ject's v alue ma y
  • r
ma y not b e dened. An
  • bje
ct whose v alue is dened is a triple (o; v ; c) where
  • 2
O is the
  • b
ject's
  • id,
v 2 V is the
  • b
ject's v alue, and c 2 C is the
  • b
ject's class. If the v alue
  • f
the
  • b
ject is undened, then its
  • id
m ust b e nulltuple,
  • r
nullset,
  • r
nulllist. An
  • b-
ject whose
  • id
is nulltuple is an
  • b
ject
  • f
some tuple- class. Similarly , an
  • b
ject with
  • id
nullset is an
  • b
ject
  • f
some set-class, and an
  • b
ject with
  • id
nulllist is an
  • b
ject
  • f
some list-class. An
  • b
ject whose v alue is undened is called an undene d
  • bje
ct . Equalit y and Cop ying: The system pro vides three equalit y
  • p
erators and t w
  • cop
y
  • p
erators. The equalit y
  • p
erators test for id-equalit y , shallo w-equalit y , and deep- equalit y . The cop y
  • p
erators return shallo w-cop y and deep-cop y
  • f
a giv en
  • b
ject. These
  • p
erators ha v e their standard meaning as in [15 ], in terested readers ma y also see [17 ]. 3.4 Class Extensions A database sc hema explicitly declares a set
  • f
classes C 2 C. The system main tains an extension for eac h class in C . The extension is the set
  • f
all
  • b
jects
  • f
its asso ciated class. W e dene a function
  • d
, called the disjoint
  • id
assignment , from class names to extensions. If for some n
  • 0,
fo 1 c ;
  • 2
c ; . . . ;
  • n
c g is the extension
  • f
class c, then
  • d
(c) = fo 1 c ;
  • 2
c ; . . . ;
  • n
c g. The function
  • d
is called the disjoin t
  • id
assignmen t b ecause, if c and c are t w
  • dieren
t classes in C , then
  • d
(c) \
  • d
(c ) = . Giv en
  • d
, the
  • id
assignment
  • (inherited
from
  • d
) is a function mapping eac h class name to a set
  • f
  • ids
suc h that
  • (c)
=
  • d
(c) [ f d (c ) j c 2 C ; c < cg. In
  • ther
w
  • rds,
  • maps
a class name to the set
  • f
  • b
jects
  • f
that class and all
  • f
its sub classes. Giv en
  • ,
the in terpretation
  • f
a class c is dened as follo ws:
  • eac
h basic t yp e Integer, String, Float and Boolean has its natural domain
  • for
eac h tuple-class c, domain(c) = fnulltupleg [
  • (c)
  • for
eac h set-class c, domain(c) = fnullsetg [
  • (c)
  • for
eac h list-class c, domain(c) = fnulllistg [
  • (c)
3.5 Database A database consists
  • f
a sc hema S and an instance I . There is a clear separation b et w een the sc hema and the instance in
  • ur
data mo del. 3.5.1 Sc hema A database schema is a 3-tuple (C ;
  • ;
G) where C 2 C is a set
  • f
class names,
  • is
the function mapping class names to class denitions, and G is a set
  • f
glob al vari- ables with asso ciated classes. The sets C and G together act as the en try p
  • in
ts to the database. Ev ery
  • b
ject in the extensions
  • f
C as w ell as ev ery
  • b
ject with a global name is p ersistent . Ev ery
  • b
ject that is a part
  • f
a p ersisten t
  • b
ject is also p ersisten t. The function
  • maps
class names to class denitions. Class hierarc h y in C can b e constructed from the infor- mation a v ailable with the class denitions. 3.5.2 Instances An instanc e
  • f
a database sc hema consists
  • f
a nite set
  • f
  • b
jects and the four functions
  • d
,
  • ;
  • ,
and
  • .
The functions
  • d
;
  • ;
  • ,
and
  • are
dened as follo ws:
  • the
function
  • d
is the disjoin t
  • id
assignmen t
  • the
function
  • is
the
  • id
assignmen t inherited from
  • d
  • The
function
  • maps
  • ids
to v alues for all the de- ned
  • b
jects in the database instance
slide-7
SLIDE 7
  • the
function
  • maps
v ariable names in G to
  • b
jects whic h are the v alues curren tly assigned to the v ari- ables 3.6 Other Data Mo dels The data mo del presen ted in this section eliminates the dic hotom y
  • f
  • bje
ct-versus-values found in
  • ther
data mo dels [3 , 8]. This simplies the mo del, and remo v es an y p
  • ssibilit
y
  • f
confusion b et w een
  • b
jects and v alues as p
  • in
ted
  • ut
in [15 ]. It is ho w ev er p
  • ssible
to ac hiev e the functionalit y and p erformance
  • f
values in
  • ur
data mo del. V alues: V alues can b e though t
  • f
as sp ecial
  • b
jects whic h are nev er shared and ha v e no b eha vior. Since v al- ues are nev er shared, it is not necessary to refer to them indirectly from m ultiple
  • b
jects. It is therefore c heap er to access v alues. Since v alues ha v e to b eha vior, they do not carry an y t yp e related information at run time. It is nev er necessary to p erform a late binding
  • f
an y metho d
  • n
a value based
  • n
its actual t yp e. A v alue
  • f
an y t yp e can b e assigned to a v ariable
  • f
its sup ert yp e. The assignmen t ho w ev er truncates the v alue if necessary . In
  • ur
data mo del, a v alue is an
  • b
ject
  • f
an implic- itly declared class (whic h sp ecies
  • nly
a structure, but no name, no sup ert yp e and no metho d) and qualied as Own. The attribute bendpoints
  • f
class SegmentedEdge in Example 3.1 holds exclusiv ely referenced
  • b
jects. This pro vides
  • b
jects that are nev er shared and ha v e no b eha vior. These
  • b
jects therefore can b e stored and accessed lik e v alues in O 2 data mo del. Since the implic- itly declared classes ha v e no names, there extensions are also not stored as a part
  • f
the database instance. W e p
  • in
t
  • ut,
ho w ev er, that this is
  • nly
an in ternal
  • pti-
mization. T
  • the
  • utside
users these sp ecial
  • b
jects are no dieren t than the
  • ther
  • b
jects. Shared v ersus Own: Sharing and exclusiv e access are
  • rthogonal
issues to information represen tation. W e think these t w
  • issues
should b e k ept
  • rthogonal
in data mo dels. Our data mo del do es this b y pro viding a sepa- rate Own qualier for attributes. It is p
  • ssible
to pro vide c
  • mp
  • site
  • bje
ct
  • f
ORION [4 ], as w ell as
  • wn
r ef [8]
  • b
jects
  • f
EX ODUS within
  • b
ject-orien ted paradigm. T
  • implemen
t com- p
  • site
  • b
jects,
  • ne
has to in tro duce the concept
  • wner-
ship (not exclusiv e access)
  • f
an
  • b
ject b y another
  • b-
ject. The
  • wn
r ef
  • b
jects require b
  • th
exclusiv e access and
  • wnership,
so that when the
  • wner
  • b
ject is deleted, the
  • wned
  • b
jects are also deleted. In principle, suc h b e- ha vior are ac hiev ed b y adding additional constrain ts
  • n
creation, manipulation, and deletion
  • f
  • b
jects in the same basic
  • b
ject graph. 4 Ob ject Algebra The
  • p
erators are categorized in to six sets based
  • n
the t yp es
  • f
the argumen ts they admit. 4.1 Ob ject Op erators CREA TE(class-name, value) !
  • bje
ct : Creates an
  • b-
ject
  • f
the giv en class and v alue. CREA TE(class-name) !
  • bje
ct : Creates an undened
  • b
ject
  • f
the giv en class. SH COPY(obje ct ) !
  • bje
ct : Creates a shallo w-cop y
  • f
the giv en
  • b
ject. DEEP COPY(obje ct ) !
  • bje
ct : Creates a deep-cop y
  • f
the giv en
  • b
ject. INV OKE(obje ct, metho d-name, fobje ctg) !
  • bje
ct : In- v
  • k
es a metho d call, and returns the result. The
  • b
jects follo wing the metho d-name are the actual argumen ts for the call. FIL TER(obje ct , pr e dic ate ) !
  • bje
ct j nul l : Returns the giv en
  • b
ject if the giv en predicate is satised, else it returns nul l . CLASS NODE(class-name) ! set-obje ct : Returns
  • d
(class-name) for a class in the database sc hema. CLASS SUBTREE(class-name) ! set-obje ct : Returns
  • (class-name)
for a class in the database sc hema. 4.2 T uple Op erator TUP CONSTR UCT(fobje ctg) ! tuple-value : Returns a tuple-v alue constructed from the giv en
  • b
jects. The
  • rder
  • f
the comp
  • nen
ts in the returned v alue is same as the
  • rder
  • f
the argumen ts. TUP A TTR(tuple-obje ct , attr-name ) !
  • bje
ct : Re- turns the v alue
  • f
the attribute. TUP COMP(tuple-obje ct, p
  • sition)
!
  • bje
ct : T emp
  • rary
tuple-classes created b y the algebra are not giv en explicit attribute names. Ev ery comp
  • nen
t
  • f
a tuple- v alue has an asso ciated p
  • sition.
This
  • p
erator is used to extract individual comp
  • nen
ts b y p
  • sition.
TUP ADDR(tuple-obje ct , attr-name) ! l-value : It re- turns the l-v alue
  • f
the giv en attribute. It is used to assign v alues to the attribute using the ASSIGN
  • p
era- tor. 4.3 Set Op erators A set is a collection
  • f
  • b
jects without duplicates. SET CONSTR UCT(fobje ctg) ! set-value : Returns a set-v alue costructed from the giv en
  • b
jects. SET UNION(set-obje ct, set-obje ct) ! set-obje ct : Re- turns the union
  • f
the giv en
  • b
jects. SET DIFF(set-obje ct, set-obje ct) ! set-obje ct : Returns
slide-8
SLIDE 8 the dierence
  • f
the giv en
  • b
jects. SET PR ODUCT(set-obje ct, set-obje ct) ! set-obje ct : Returns the cartesian pro duct
  • f
the giv en
  • b
jects. SET DE(set-obje ct , e quality-op) ! set-obje ct : This
  • p-
erator is used to eliminate duplicates. Although eac h
  • b
ject is unique, some
  • b
jects ma y b e shallo w-equal,
  • r
deep-equal to eac h
  • ther.
SET COLLAPSE(set-obje ct) ! list-obje ct : This
  • p
era- tor tak es a set-v alued
  • b
ject whose v alue consists
  • f
a set
  • f
set-v alued
  • b
jects. It pro duces list-ob ject whose v alue is the concatenation
  • f
the v alues
  • f
those set-v alued
  • b-
jects. SET APPL Y(set-obje ct ,
  • p-se
quenc e ) ! set-obje ct : It applies a giv en
  • p
erator sequence
  • n
the elemen ts
  • f
the v alue
  • f
a set-v alued
  • b
ject to pro duce a set-v alued
  • b-
ject. SET TO LIST(set-obje ct ) ! list-obje ct : Returns a list- v alued
  • b
ject created from the
  • b
jects in the set-v alue. 4.4 List Op erators A list is a sequence
  • f
elemen ts
  • f
v ariable length and ma y ha v e duplicate elemen ts. LIST CONSTR UCT(fobje ctg) ! list-value : Returns a list-v alue constructed from the giv en
  • b
jects. The
  • r-
der
  • f
elemen ts in the list is same as the
  • rder
  • f
the argumen ts. LIST CA T(list-obje ct , list-obje ct ) ! list-obje ct : Re- turns a list-v alued
  • b
ject whose v alue is created b y con- catenating the second list to the rst list. LIST DIFF(list-obje ct , list-obje ct ) ! list-obje ct : This
  • p
erator returns a list whic h has all the elemen ts
  • f
the rst list except the elemen ts
  • f
the second list. The
  • rder
  • f
the remaining elemen ts in the returned list in same as the
  • rder
  • f
the elemen ts in the rst list. Example 4.1: Supp
  • se
w e ha v e t w
  • lists
L 1 and L 2 with v alues <1 3 2 1 2 3 5 5 7> and <3 5 3 6 6> then LIST DIFF(L 1 ; L 2 ) is a list with v alue <1 2 1 2 7>. Since 3 and 5 are elemen ts
  • f
L 2 , they cannot b e elemen ts
  • f
the resulting list. The
  • rder
  • f
the remaining elemen ts is preserv ed. LIST PR ODUCT(list-obje ct , list-obje ct ) ! list-obje ct : Returns a list whic h is an
  • r
der e d c artesian pr
  • duct
  • f
the giv en lists. This is not a comm utativ e
  • p
eration. Example 4.2: Supp
  • se
w e ha v e t w
  • lists
L 1 and L 2 with v alues <4 2 5> and <7 9 6>, then LIST PR ODUCT(L 1 ; L 2 ) has v alue <o 1 ;
  • 2
; . . . ;
  • 9
> where
  • i
for i = 1; 2; . . . ; 9 are the
  • ids
  • f
tuples with v alues [4 7], [4 9], [4 6], [2 7], [2 9], [2 6], [5 7], [5 9], and [5 6] resp ectiv ely . LIST DE(list-obje ct , e q-op ) ! list-obje ct : Eliminates duplicates from lists. The rst
  • b
ject is retained. LIST COLLAPSE(list-obje ct ) ! list-obje ct : Returns a list b y concatenating all the lists within the input list in the same
  • rder.
LIST APPL Y(list-obje ct ,
  • p-se
q) ! list-obje ct : Returns a list
  • f
results
  • f
application
  • f
  • p
erator sequence to list elemen ts. LIST TO SET(list-obje ct ) ! set-obje ct : Pro duces a set from the elemen ts
  • f
the list. 4.5 Mixed Op erators SET LIST COLLAPSE(set-obje ct) ! list-obje ct : Re- turns a list, created b y concatenating the lists in the giv en set in an y arbitrary
  • rder.
LIST SET COLLAPSElist-obje ct) ! list-obje ct : Re- turns a list b y con v erting the sets to lists and concate- nating them in the
  • rder
  • f
the giv en list. 4.6 Other Op erations ASSIGN(variable ,
  • bje
ct ) : Assigns a v alue to a v ariable. It
  • p
erates b y creating side eect. It do es not return an y result. REPEA T UNTIL(expr-se quenc e , pr e dic ate ) : Ev aluates the expressions rep eatedly till the predicate is satised. This
  • p
erator is used to ev aluate recursiv e queries. 5 Query Language OQL The Ob ject Query Language OQL is rule-based. It al- lo ws stratied negation. It is statically t yp ed. The lan- guage allo ws
  • ne
to manipulate mixture
  • f
tuple-v alued, set-v alued and list-v alued
  • b
jects
  • b
eying certain t yp e- ing restrictions. It also includes mec hanisms to express queries in v
  • lving
inheritance relationships
  • f
classes. Fi- nally , the language pro vides mec hanisms for creating
  • b-
jects
  • f
arbitrary t yp es. 5.1 Syn tax The syn tax for an OQL program is giv en b elo w. Detailed seman tics are describ ed in Section 6. A pr
  • gr
am consists
  • f
a se quenc e
  • f
statemen ts. Eac h statement is either an assignment
  • r
a rule. An assignmen t assigns an r-value to an l-value if the qualiers are satised. The
  • bje
ct expr ession in the as- signmen t statemen t pro vides an r-v alue, and the p ath expr ession pro vides the l-v alue. The sym b
  • l
\:=" is the assignmen t
  • p
erator. A rule has a he ad and a b
  • dy.
A head is a sp ecial t yp e
  • f
literal with a path expression, an
  • ptional
equalit y
  • p
erator, and an
  • b
ject expression. There are three sys- tem dened equalit y
  • p
erators for id-equalit y , shallo w- equalit y , and deep-equalit y .
slide-9
SLIDE 9 <pr
  • g>
! f<statement>g <statement> ! <assign> ! <rule> <assign> ! <p ath-expr> `:=' <obj-expr> f<qual>g <rule> ! <he ad> ` ' <b
  • dy>
<he ad> ! <p ath-expr> `(' [<e q-op>] <obj-expr> `)' <b
  • dy>
! f<liter al>g <liter al> ! <gen> ! <qual> <gen> ! [:] <class-expr> `(' <var-name> `)' ! [:]<obj-expr> `(' <var-name> `)' <qual> ! [:] <obj-expr> <op> <obj-expr> <p ath-expr> ! <var-name> ! <p ath expr> `.' <attr name> <obj-expr> ! <b asic-value> ! <var-name> ! <obj-expr> `.' <attr-name> ! <obj-expr> `.' <meth-c al l> ! `new' <class-name> `(' <value> `)' ! <c
  • py-op>
<obj-expr> <class-expr> ! <class-name> ! <class-name> `' <value> ! <empty> ! `[' f<attr-name> `:' <obj-expr>g `]' ! `f' f<obj-expr>g `g' ! `<' f<obj-expr>g `>' <meth-c al l> ! <meth-name> `(' f<obj-expr>g ')' Eac h b
  • dy
consists
  • f
a set
  • f
liter als. Eac h literal is either a gener ator
  • r
a qualier. Our data mo del has no r elations. There are
  • nly
set-v alued and list-v alued
  • b
jects. Generators therefore ha v e
  • ne
variable within paren thesis. This v ariables are called r ange variables
  • f
the generators. The sym b
  • l
\:" denotes ne gation. All the range v ariables
  • f
non-negated generators
  • f
a single rule b
  • dy
m ust b e dieren t. A qualier sp ecies a condition. A class expr ession stands for a set
  • f
  • b
jects
  • f
that class. If c is a class name, then the expression c stands for the extension
  • f
that class, and c stands for the union
  • f
the extension
  • f
the class and the extensions
  • f
all its sub classes. The \."
  • p
erator in the path expression either ex- tracts an attribute from a tuple-v alue,
  • r
in v
  • k
es a metho d
  • n
an
  • b
ject. A metho d call needs the metho d name, and the required n um b er
  • f
  • b
ject expressions for actual argumen ts. The \new"
  • p
erator creates a new
  • b
ject with the giv en class and value. A v alue is a structured v alue. If the v alue is empt y , the \new"
  • p
erator returns an un- dened
  • b
ject
  • f
the giv en class. 5.2 T yping Restrictions OQL programs are statically t yp ed. There is a t yp e asso ciated with eac h path expression,
  • b
ject expression, class expression, and basic v alue. A
  • b
ject expression
  • f
class c can b e assigned to a path expression
  • f
class c
  • r
a sup erclass
  • f
class c
  • nly
. In the head
  • f
a rule, if
  • is
the t yp e asso ciated with the
  • b
ject expression, then the t yp e asso ciated with the path expression m ust b e either Set( )
  • r
List( ) where
  • is
a sup ert yp e
  • f
  • .
In a generator literal, if
  • is
the class name used in the class expression, then the t yp e asso ciated with the class expression is Set( ), and the t yp e asso ciated with its range v ariable is
  • .
Similarly , if Set( ) is the t yp e asso ciated with the
  • b
ject expression, then the t yp e
  • f
its range v ariable is
  • .
In a qualier, the equalit y
  • p
erators m ust b e applied to
  • b
ject expressions
  • f
same t yp e. In path and
  • b
ject expressions, the attributes and metho ds m ust b e dened at the appropriate classes, and the argumen ts for the metho d calls m ust b e
  • b
ject ex- pressions
  • f
required t yp es. In an
  • b
ject expression, the \new"
  • p
erator m ust b e pro vided with a v alue appropriate for the giv en class. Finally , if the head
  • f
a rule has a path expression
  • f
t yp e List( ) for some t yp e
  • ,
then the generators in the rule b
  • dy
ma y
  • nly
b e
  • b
ject expressions follo w ed b y range v ariables within paren thesis, and the t yp es
  • f
the
  • b
ject expressions can
  • nly
b e list-classes. This re- striction is necessary in
  • rder
to dene a deterministic
  • rder
for the elemen ts
  • f
the list in the head. Since sets are unordered, allo wing sets w
  • uld
mak e the
  • rder
  • f
the elemen ts non-deterministic. It is ho w ev er p ermissible to use list-v alued
  • b
jects in b
  • dy
, and path expressions
  • f
set-class in the head. 5.3 Examples Example 5.1 Set Filter: Let V b e a set
  • f
v ertices. Vertex class is declared in Example 3.1. W e w an t to create a set
  • f
  • b
jects with the label, and position
  • f
v ertices
  • f
radius greater than 10.0. This query is expressed as follo ws: Class City Tuple(name: String, loc: Point); C: Set(City); C(= s new City([name: v.label, loc: sh-copy(v.posit ion)] )) V(v), v.radius > 10.0 This query declares a new class City, and a new v ariable C
  • f
the newly declared class. It uses the \new"
  • p
era- tor and the \sh-copy"
  • p
erator to create new
  • b
jects. The cop y
  • p
erator is necessary b ecause the position attribute
  • f
the Vertex class is qualied as Own. This qualication prev en ts sharing
  • f
the
  • b
jects held b y the p
  • sition
attribute. The program also uses the shallo w- equalit y
  • p
erator \= s " to eliminate duplicates. 2 Example 5.2 Nesting and Unnesting: Let T b e an y arbitrary t yp e in the follo wing declarations.
slide-10
SLIDE 10 Class C1 Tuple(a1: T, a2: Set(T)); Class C2 Tuple(b1: T, b2: T); R1, R3: C1; R2: C2; Assume that initially R1 holds a set
  • f
  • b
jects
  • f
class C1, and
  • ther
t w
  • v
ariables hold undened
  • b
jects. W e w an t to unnest R1 in to R2, and then nest R2 in to R3. The program b elo w unnests R1 in to R2: R2( new C2([b1: x.a1, b2: y])) R1(x), x.a2(y) The follo wing program nests R2 in to R3: R3(= s new C1([a1: x.b1, a2: nullset])) R2(x) y.a2( sh-copy(x.b2)) R3(y), R2(x), y.a1 = s x.b1 Notice the unnesting program uses the id-equalit y
  • p
er- ator, and the nesting program uses the shallo w-equalit y
  • p
erator in the rst rule, and id-equalit y in the second rule along with a cop y
  • p
erator. The cop y
  • p
erator en- sures that nesting and unnesting
  • p
eration will b e in- v erse
  • p
erations. 2 Example 5.3 T ransitiv e Closure: Consider a set
  • f
  • b
jects E
  • f
class Edge as in Example 3.1. W e w an t to compute the transitiv e closure
  • f
E and create a new set
  • f
  • b
jects R
  • f
class Reachable as declared b elo w. The follo wing program p erforms is computation: Class Reachable Tuple(s: Vertex, d: Vertex); R(= s new Reachable([s: e.source, d: e.dest]) E(e) R(= s new Reachable([s: r.source, d: e.dest]) R(r), E(e), r.d
  • e.source
The program ab
  • v
e uses the shallo w-equalit y
  • p
erator in the heads. This ensures that R do es not con tain du- plicate (sour c e, destination) pairs. The program b elo w is another v ersion
  • f
the query . R( new Reachable([s: e.source, d: e.dest]) E(e) R( new Reachable([s: r.source, d: e.dest]) R(r), E(e), r.d
  • e.source
This program uses the id-equalit y
  • p
erator in the heads. This program therefore ma y cause R to con tain duplicate (sour c e, destination) pairs if there is more than
  • ne
path from source to destination. This program will also nev er terminate if there are cycles in the graph. 2 Example 5.4 Inheritance T ree Queries: This ex- ample uses the Edge, SegmentedEdge, and CurvedEdge classes dened in Example 3.1. The query b elo w re- triev es all the database edges whic h are neither seg- men ted nor curv ed, and
  • f
length less than 20.0: E1: Edge; E1( e) Edge(e), e.length() < 20.0 All database edges
  • f
length less than 20.0 are retriev ed b y the follo wing query: E2: Edge; E2( e) Edge(e), e.length() < 20.0 All database edges
  • f
length less than 20.0 except the segmen ted edges are retriev ed b y the follo wing query: E3: Edge; E3( e) Edge(e), : SegmentedEdge(e), e.length() < 20.0 This example sho ws the use
  • f
class extensions, and the class expressions in v
  • lving
\" and \:"
  • p
erators for dealing with class hierarc hies. 2 OQL is capable expressing a wide range
  • f
queries suc h p
  • werset
c
  • mputation
and gr
  • uping.
In terested readers can nd more examples in [18 ]. 6 Seman ti cs
  • f
OQL The seman tics
  • f
OQL is dened b y an algorithm that translates OQL programs in to algebraic
  • p
erations, as- signmen t
  • p
erations and REPEA T UNTIL lo
  • ps.
In this section w e describ e an informal and in tuitiv e mean- ing for OQL programs. V ariables: OQL is similar in spirit to Datalog [20 ]. OQL programs computes v alues
  • f
database v ariables whose v alues are undened from database v ariables whose v alues are dened. These are called intensional datab ase variables
  • r
IDB v ariables and extensional datab ase variables
  • r
EDB v ariables resp ectiv ely . Classes: W e also call the classes that are part
  • f
the database sc hema the EDB classes, while the classes de- ned in an OQL program are IDB classes. IDB classes are not part
  • f
the sc hema, and they do not tak e part in the inheritance hierarc h y , their extensions are not stored in the database, and they cannot b e used in the class ex- pressions. 6.1 Expressions P ath Expressions: P ath expressions are used to na v- igate through the
  • b
ject graph. A p ath expr ession is a v ariable name follo w ed b y a sequence
  • f
zero
  • r
more at- tribute names separated b y \."
  • p
erators. It has b
  • th
l-v alue, and r-v alue. The l-v alue and the r-v alue
  • f
the path expression E , denoted b y L V AL(E ) and R V AL(E ) resp ectiv ely , are dened as follo ws:
  • if
it is a v ariable name, then L V AL(E ) and R V AL(E ) are the l-v alue and the r-v alue
  • f
the v ari- able resp ectiv ely
slide-11
SLIDE 11
  • if
it is
  • f
the form <p ath-expr>.<attr-name>, then L V AL(E ) = TUP ADDR(R V AL(p ath-expr), attr- name), and R V AL(E ) = TUP A TTR(R V AL(p ath- expr), attr-name) Ob ject Expressions: Ob ject expressions ha v e
  • nly
r- v alues. The v alue
  • f
an
  • b
ject expression E denoted b y R V AL(E ) is dened as follo ws:
  • if
it is a basic v alue, the basic v alue is the v alue
  • f
the
  • b
ject expression
  • if
it is
  • f
the form <obj-expr>.<attr-name> then R V AL(E ) = TUP A TTR(R V AL(obj-expr), attr- name)
  • if
it is
  • f
the form <obj-expr> 1 .<meth-name> (<obj-expr> 2 , <obj-expr> 3 ; . . . ; <obj-expr> n ), then R V AL(E ) = INV OKE(R V AL<obj-expr)> 1 , <meth-name>, R V AL(<obj-expr)> 2 , R V AL(<obj- expr)> 3 ; . . . ; R V AL(<obj-expr)> n )
  • if
it is
  • f
the form new <class-name>(<value>), then R V AL(E ) = CREA TE(class-name, value)
  • if
it is
  • f
the form <c
  • py-op><obj-expr>,
then R V AL(E ) = SH COPY(R V AL(obj-expr))
  • r
DEEP COPY(R V AL(obj-expr)) dep ending
  • n
whether <c
  • py-op>
sp ecies a shallo w-cop y
  • r
a deep-cop y resp ectiv ely Class Expressions: Class expressions are used to de- note class extensions. They
  • nly
ha v e r-v alues. Let c b e the name
  • f
an EDB class. Then the v alue
  • f
the class expression c, denoted b y R V AL(c), is CLASS NODE(c), and the v alue
  • f
the class expression c, R V AL(c) = CLASS SUBTREE(c) 6.2 Restrictions Monotonicit y: OQL programs do not delete database
  • b
jects, and do not mo dify the existing v alue
  • f
an y v ariable
  • f
an y tuple-class. They ma y insert
  • b
jects in to sets, and app end
  • b
jects to lists. but they do not remo v e
  • b
jects from sets,
  • r
lists. Safet y: All the OQL programs m ust b e safe. Safet y is necessary to ensure niteness
  • f
IDB sets and lists. An OQL program is safe if all the rules in the program are safe. A rule is safe if all the v ariables app earing in the rule are limite d . The limite d v ariables are dened as follo ws.
  • an
y EDB v ariable, IDB v ariable,
  • r
range v ariable
  • f
a non-ne gate d generator is limited
  • v
ariable x is limited if it app ears in a qualier suc h as x
  • E
,
  • r
E
  • x,
where E is an
  • b
ject expression
  • v
ariable x is limited if it app ears in a qualier literal suc h as x
  • y
,
  • r
y
  • x,
where y is a v ariable already kno wn to b e limited

name FILTER = v label 20.0 v radius ASSIGN TUPLE_ATTR TUPLE_ATTR s

Figure 1: Query tree for a simple assignmen t

= 20.0 radius SET_APPLY V1 FILTER V2 [INPUT] [INPUT] ASSIGN TUPLE_ATTR s

Figure 2: Expression tree for a simple rule 6.3 Simple Statemen ts An OQL program consists
  • f
a se quenc e
  • f
statemen ts. Eac h statemen t is either an assignmen t statemen t
  • r
a rule. The follo wing is a simple program with a set
  • f
declarations, an assignmen t statemen t, and a rule. As- sume that v, and V1 are EDB v ariables
  • f
t yp e Vertex, and Set(Vertex) resp ectiv ely . name: String; V2: Set(Vertex); name := v.label, v.radius = s 20.0 V2(x) V1(x), x.radius = s 20.0 An assignmen t statemen t can
  • nly
dene v alues
  • f
unde- ned v ariables. This is required to ensure monotonicit y . The rst statemen t ab
  • v
e assigns a string to IDB v ari- able name if the qualier v.radius = 20.0 is satised, else the v alue
  • f
name remains undened. This statemen t is translated to the query tree in Figure 1. The second statemen t is a rule. The b
  • dy
  • f
the rule has the generator V1(x), and the qualier x = 20.0. The v ariable x is the r ange variable. The generator can b e though t
  • f
as the predicate (x 2 V1). The quali- er has the
  • b
vious in terpretation as a predicate. Sim- ilarly , the head
  • f
the rule V2(x) can b e in terpreted as the predicate (x 2 V2). In tuitiv ely , a rule means that whenev er the predicates in the b
  • dy
are satised, the head predicate m ust also b e satised. This accomplished b y the expression tree in Figure 2. The no des denoted b y \[INPUT]" are the elemen ts
  • f
the set
  • n
whic h the SET APPL Y
  • p
erator
  • p
erates. 6.4 Dep endency Graph and Recursion A dep endency gr aph
  • f
a program describ es the w a y IDB and EDB v ariables dep end
  • n
  • ne
another. There is an
slide-12
SLIDE 12 arc from v ariable P to v ariable Q if there is rule with a b
  • dy
literal P and with a head literal Q. A program is r e cursive if its dep endency graph has at least
  • ne
cycle. A program with acyclic dep endency graph is r e cursion- fr e e. All v ariables that are
  • n
  • ne
more cycles are called r e cursive variables. A v ariable is non-recursiv e if it is not part
  • f
an y cycle. A recursiv e program ma y ha v e non-recursiv e v ariables. 6.5 Recursion-F ree Negation-F ree OQL If the rules are not recursiv e, w e can
  • rder
the the no des
  • f
the Dep endency graph P 1 ; P 2 ; . . . ; P n so that if there is an arc P i ! P j then i < j . W e can then compute the v alues for the v ariables P 1 ; P 2 ; . . . ; P n in that
  • rder,
kno wing that when w e w
  • rk
  • f
P i the v alues for all the v ariables that are required to compute P i are already kno wn. The computation is done in t w
  • steps,
i) rst compute the v alues corresp
  • nding
to the rule b
  • dies,
ii) then com bine the results from the rules that compute the same IDB v ariable. Prev en tin g Loss
  • f
Ob jects: The seman tics
  • f
the language ensures no \information loss". Co v erting a list to a set ma y cause loss
  • f
information due to elimination
  • f
duplicates. Con v erting a set to a list causes no loss
  • f
information b ecause the set can b e reconstructed from the list. All implicit con v ersions are therefore done from set to list
  • nly
. When sets and lists and lists are mixed in the rule b
  • dy
, sets are implicitly con v erted to lists for applying the LIST PR ODUCT
  • p
erator. The
  • p
erators SET COLLAPSE, LIST COLLAPSE, SET LIST COLLAPSE, and LIST SET COLLAPSE ha v e b een designed to return lists for the same reason. A list is con v erted to a set
  • nly
when explicitly ask ed. OQL do es not allo w explicit con v ersion
  • f
sets to lists b ecause the
  • rdering
  • f
the elemen ts w
  • uld
b e unkno wn. Duplicate Eliminati
  • n:
Duplicate elimination is ex- pressed b y sp ecifying an equalit y
  • p
erator in the head literal suc h as in the rule L2(= d y) L1(y). Assume that L1 is an EDB v ariable
  • f
t yp e List(T) for some t yp e T. The head
  • f
this rule stands for the predicate \there is
  • ne
  • b
ject in L2 that is deep-equal to y". This rule is translated to ASSIGN(L2, LIST DE(L1, = d )). Join Queries: Join queries are translated to SET PR ODUCT
  • r
LIST PR ODUCT
  • p
erations, and FIL TER
  • p
eration to select resulting tuples. Example 6.1 Join Queries: Assume that L1, L2 are EDB v ariables, and L3 is an IDB v ariable in the follo wing program. Class C1 Tuple(a: T, b: T); Class C2 Tuple(a: T, c: T); Class C3 Tuple(a: T, b: T, c: T); ASSIGN FILTER LIST_PRODUCT LIST_APPLY LIST_APPLY CREATE = TUP_COMP TUP_COMP TUP_COMP TUP_COMP TUP_COMP TUP_CONSTRUCT "C3" #1 #2 #3 #1 #3 L1 L2 L3 [INPUT] [INPUT] [INPUT] [INPUT] [INPUT] [INPUT] s Figure 3: Expression tree for program in Example 6.1

S2 LIST_APPLY LIST_PRODUCT CONVERT_TO_LIST SET_COLLAPSE S1 S1 COVERT_TO_SET #1 #2 CREATE [INPUT] [INPUT] ASSIGN "Pair" TUP_CONSTRUCT TUP_COMP TUP_COMP

Figure 4: Expression tree for program in Example 6.2 L1: List(C1); L2: List(C2); C3: List(C3); L3(new C3([a: x.a, b: x.b, c: y.c])) L1(x), L2(y), x.a = y.a The expression tree for this program is in gure 3. 2 Deriv ed Generators: The path expressions for some generators are constructed from the range v ariables
  • f
  • ther
generators. The former t yp e
  • f
generators are called derive d gener ators. They are said to b e deriv ed from the generators whose range v ariables are used to construct them. Deriv ed generators are translated to expressions in v
  • lving
COLLAPSE
  • p
erators. Example 6.2 Deriv ed Generators: Assume that S1 is an EDB v ariable
  • f
t yp e Set(List(T), and S2 is the IDB v ariable in the follo wing program. This program is translated in to the expression tree in Figure 4. Class Pair Tuple(a1: List(T), a2: T); S2: Pair; S2(new Pair([a1: x, a2: y]) S1(x), x(y) 2 Order
  • f
List Elemen ts: The
  • rder
  • f
the elemen ts in the IDB list
  • f
a rule is same as the
  • rder
  • f
the elemen ts in the list computed b y the rule b
  • dy
. If the rule b
  • dy
has m ultiple generators, the elemen ts in the list computed b y the rule b
  • dy
is determined b y the left to righ t
  • rdering
  • f
the generators. The generators
  • n
the left are more signican t in
  • rdering
the elemen ts as
slide-13
SLIDE 13 sho wn in the follo wing example. Example 6.3 Order
  • f
List Elemen ts: Let L1, and L2 b e t w
  • lists
with v alues <1 2>, and <1.0 2.0>. The follo wing rule computes L3 from L1 and L2. Class Pair Tuple(a1: Integer, a2: Float); L3: Set(Pair); L3(new Pair([a1: x, a2: y])) L1(x), L2(y) The ab
  • v
e program assigns the list
  • f
  • ids
<
  • 1
;
  • 2
;
  • 3
;
  • 4
> to L3, where v alue
  • f
the
  • b
jects are [1 1.0], [1 2.0], [2 1.0], [2 2.0]. In the program b elo w the
  • rder
  • f
the generators in the b
  • dy
has b een c hanged. L3(new Pair([a1: x, a2: y])) L2(y), L1(x) This program assigns a list
  • f
four
  • ids
to L3, but their v alues are [1 1.0], [2 1.0], [1 2.0], [2 2.0] resp ectiv ely . 2 Com binin g Results from Multiple Rules: An IDB v ariable ma y app ear at the head
  • f
sev eral rules. If suc h an IDB v ariable is a set, its v alue is computed b y taking union
  • f
the v alues computed b y the individual rule b
  • d-
ies. If the v ariable is list, its v alue is computed b y con- catenating the v alues computed b y the individual rules. The
  • rder
  • f
concatenation is same as the
  • rder
the
  • rder
  • f
app earance
  • f
the rules in the program. 6.6 Recursiv e Negation-F ree OQL Recursiv e programs are ev aluated b y computing le ast xe d p
  • ints
  • f
OQL equations with a REPEA T UNTIL lo
  • p.
Assume that a program computes v alues
  • f
m IDB v ariables P 1 ; P 2 ; . . . P m . Initially all the IDB v ari- ables are undened. W e in tro duce a temp
  • rary
v ariable Q i for eac h IDB v ariable P i . Q i is assigned the cur- ren t v alue
  • f
P i for all i = 1 to m at the b eginning
  • f
the lo
  • p.
Assume that EXPR(P i ) is the algebraic ex- pression for computing the v alue
  • f
v ariable P i from the curren tly assigned v alues
  • f
Q's, and
  • ther
EDB v ari- ables, basic v alues, metho d names, attribute names and class names. EXPR(P i ) is constructed in the same w a y as for the recursion-free programs. The program b elo w sho ws the least xed p
  • in
t computation. Due to mono- tonicit y , IDB v ariables will
  • nly
gro w in size, hence if the program do esn't sp ecify an innite computation, a xed p
  • in
t will b e reac hed. REPEA T ASSIGN(Q 1 , P 1 ); ASSIGN(Q 2 , P 2 ); . . . ASSIGN(Q m , P m ); ASSIGN(P 1 , EXPR(P 1 )); ASSIGN(P 2 , EXPR(P 2 )); . . . ASSIGN(P m , EXPR(P m )); UNTIL (P 1 = Q 1 ) ^ (P 2 = Q 2 ) ^ . . . ^ (P m = Q m ) The
  • rder
  • f
elemen ts in IDB lists is same as for non- recursiv e programs for eac h individual iteration
  • f
the lo
  • p,
and eac h successiv e iteration app ends the newly computed elemen ts at the end. OQL programs nev er insert elemen ts in to lists at arbitrary lo cations. 6.7 OQL with Negation OQL programs with negation m ust b e safe and str ati- e d. Rules are stratied if whenev er there is a rule with head IDB v ariable P and a negated subgoal with pred- icate Q, there is no path in the dep endency graph from P to Q. One can use the algorithm giv en in [20 ] to test for and nd stratication. A stratied program is ev al- uated stratum b y stratum, starting from the lo w est to the highest. When stratum i is b eing ev aluated, the v alues for the IDB v ariables at lo w er strata ha v e already b een com- puted. Let :Q(x) b e the negated generator at stratum i. The range v ariable x m ust app ear in exactly
  • ne
non- negated generator b y the syn tax rules and the safet y cri- teria. Let this generator b e P (x). Then the v alue
  • f
the negated generator is SET DIFF(P , Q)
  • r
LIST DIFF(P , Q) dep ending
  • n
whether P and Q are sets
  • r
lists re- sp ectiv ely . 6.8 Equiv alence
  • f
OQL and Algebra Reduction
  • f
OQL to algebra : Reduction
  • f
OQL to the algebra is pro v ed b y the algorithm for translating OQL programs to the algebra. W e ha v e already
  • utlined
the basic approac h. Readers ma y nd a formal algorithm in [18 ]. Reduction
  • f
algebra to OQL : Reduction
  • f
the algebra to OQL is pro v ed b y case-based induction. W e
  • mit
most
  • f
the cases as
  • ur
goal is to simply giv e the a v
  • r
  • f
the pro
  • f.
Details can b e found in [18 ]. The pro
  • f
pro ceeds b y induction
  • n
n um b er
  • f
  • p
erators in an algebraic expression E . An algebraic expression consists
  • f
EDB v ariables, IDB v ariables, class names, attribute names, metho d names, basic v alues, equalit y
  • p
erators, predicates, and
  • ne
  • r
more algebraic
  • p
erators. Eac h expression m ust ha v e an ASSIGN
  • p
erator at the ro
  • t
  • f
the expression tree. Base Case: One ASSIGN
  • p
erator in E .
  • Algebra:
ASSIGN(v 1 , v 2 )
  • r
ASSIGN(v 1 , b) In this case v 1 m ust b e an IDB v ariable, v 2 m ust b e an EDB v ariable, and b is a basic v alue. OQL: v 1 := v 2
  • r
v 1 := b Inductiv e Case : Tw
  • r
more
  • p
erators in E . The last
  • p
eration to b e p erformed in a expression is alw a ys an assignmen t. The follo wing are some expressions and their equiv alen t OQL programs:
slide-14
SLIDE 14
  • Algebra:
ASSIGN(E 1 , CREA TE(class-name, E 2 )) OQL: E 1 := new class-name(E 2 )
  • Algebra:
ASSIGN(E 1 ,TUP A TTR(E 2 ,attr-name)) OQL: E 1 := E 2 .attr-name
  • Algebra:
ASSIGN(E 1 , SET PR ODUCT(E 2 , E 3 )) OQL: E 1 (new T empClass([#1: x, #2: y ])) E 2 (x); E 3 (y )
  • Algebra:
ASSIGN(E 1 , SET COLLAPSE(E 2 )) OQL: E 1 (y ) E 2 (x); x(y )
  • Algebra:
ASSIGN(E 1 , SET APPL Y(E 2 ,
  • p-se
q)) OQL: E 1 (op-se q(x)) E 2 (x)
  • Algebra:
ASSIGN(E 1 , LIST CA T(E 2 , E 3 )) OQL: E 1 (x) E 2 (x) E 1 (x) E 3 (x) 6.9 Other Languages and Algebra OQL is partially inuenced b y IQL [1 ]. OQL is ho w ev er simpler than IQL, b ecause it manipulates
  • nly
  • b
jects, it nev er mak es explicit reference to
  • ids,
and it do es not manipulate relations. It is also more p
  • w
erful b ecause it can express duplicate elimination, manipulate lists, handle inheritance trees. IQL is more p
  • w
erful than languages in [5 , 14]. User-lev el query laguages suc h as EX CESS [8] and [2 ] are can b e seen as sublanguages
  • f
OQL. Sha w and Zdonik [19 ], and V aden b erg and DeWitt [21 ] pro vide
  • b
ject-algebra for
  • b
ject-orien ted databases. But neither
  • f
them attempt to manipulate mixture
  • f
sets and lists. A few
  • ther
languages attempt to incorp
  • rate
  • b
ject-
  • rien
ted features in to logic programs. But that is not the goal
  • f
OQL. OQL uses the logic programming paradigm simply to query database
  • b
jects with a declarativ e lan- guage. 7 Conclusions W e ha v e presen ted a data mo del, a query language, and an algebra. The data mo del simplies the existing data mo dels without loss
  • f
mo deling p
  • w
er
  • r
p erformance. The algebra has new
  • p
erators for manipulating mixture
  • f
sets and lists. The query language OQL is the most signican t con tribution
  • f
this pap er. T
  • ur
kno wledge no
  • ther
query language for
  • b
ject-orien ted databases has b een able to com bine the p
  • w
er and simplicit y
  • f
OQL. W e are curren tly in the pro cess
  • f
implem en ting the system. This pap er has not discussed query
  • ptimiza-
tion. W e are in v estigating p
  • ssible
rewriting rules for
  • ptimizing
query trees. OQL is designed to b e an ad ho c query language. It is not suitable for p erforming computation. W e are also planning to in tegrate C++ and OQL to pro vide a com- bined language for querying and computation. The data mo del and OQL ha v e b een designed with a practical application in mind, i.e., program visualiza- tion. W e use OQL for b
  • th
denition and construction
  • f
program abstractions. The suitabilit y
  • f
a database query language for denition
  • f
abstractions remains to b e seen. Shaping OQL to b e an eectiv e abstraction denition language will b e
  • ur
primary researc h goal in future. References [1] S. Abiteb
  • ul,
and P . Kanellakis. Ob ject iden tit y as a query language primitiv e. Pr
  • c.
  • f
A CM SIGMOD Conf., 1989. [2] F. Bancilhon, S. Cluet, and C. Delob el. A query lan- guage for the O 2
  • b
ject-orien ted database system. Pr
  • c.
  • f
2nd DBPL Workshop , 1990. [3] F. Bancilhon, C. Delob el and P . Kanellakis. In tro- duction to the Data Mo del. Building an Obje ct- Oriente d Datab ase System The Story
  • f
O2. Mor gan Kaufman , pp. 61{75, 1992. [4] J. Banerjee, H-T Chou, J. F. Garza, W. Kim, D. W
  • elk,
N. Ballou, and H-J Kim. Data mo del issues for
  • b
ject-orien ted applications. A CM T r ansactions
  • n
Information Systems , 5(1), pp. 3{26, Jan uary , 1987. [5] C. Beeri, S. Naqvi, R. Ramakrishnan, O. Shm ueli, and S. Tsur. Sets and negation in a logic database language (LDL1). Pr
  • c.
  • f
A CM PODS Symp
  • sium,
1987. [6] L. Cardelli. A seman tics
  • f
m ultiple inheritance. In- formation and Computation , 76(1), Jan uary , 1988. [7] L. Cardelli, and P . W egner. On understanding t yp es, data abstractions, and p
  • lymorphism.
A CM Computing Surveys , 17(4), pp. 471-522, Decem b er, 1985. [8] M. Carey , D. DeWitt and S. V anden b erg. A data mo del and query language for Exo dus. Pr
  • c.
  • f
A CM SIGMOD Conf., 1988. [9] D. H. Fishman, D. Beec h, H. P . Cate, E. C. Cho w, T. Connors, J. W. Da vis, N. Derret, C. G. Ho c h, W. Ken t, P . Lyngbaek, B. Mah b
  • d,
M. A. Neimat, T. A. Ry an, and M. C. Shan. Iris: An
  • b
ject-orien ted database managemen t system. A CM T r ansactions
  • n
Information Systems , 5(1), pp. 48{69, Jan ura y , 1987.
slide-15
SLIDE 15 [10] W. Kim, J. Banerjee, H-T Chou, J. F. Garza, and D. W
  • elk.
Comp
  • site
  • b
ject supp
  • rt
in an
  • b
ject-
  • rien
ted database system. Pr
  • c.
  • f
A CM OOPSLA Conf., 1987. [11] C. Lecluse, and P . Ric hard. Manipulation
  • f
struc- tured v alues in
  • b
ject-orien ted databases. Pr
  • c.
  • f
2nd DBPL Workshop , 1989. [12] C. Lecluse, and P . Ric hard. Mo deling complex structures in
  • b
ject-orien ted databases. Pr
  • c.
  • f
A CM PODS Symp
  • sium,
1989. [13] G. M. Kup er, and M. Y. V erdi. A new approac h to database logic. Pr
  • c.
  • f
A CM PODS Symp
  • sium,
1984. [14] G. M. Kup er. The logical data mo del: A new ap- proac h to database logic. PhD Thesis, Stanfor d University, 1985. [15] O 2 T ec hnology . The O 2 User Man ual. June, 1992. [16] S. Reiss, and M. Sark ar. Generating abstrac- tions for visualization. T ec hnical Rep
  • rt
CS-92-35. Computer Scienc e Dep artment, Br
  • wn
University , Septem b er, 1992. [17] M. Sark ar, and S. Reiss. A data mo del for
  • b
ject-
  • rien
ted databases. T ec hnical Rep
  • rt
CS-92-56. Computer Scienc e Dep artment, Br
  • wn
University, Decem b er, 1992. [18] M. Sark ar, and S. Reiss. A query language for
  • b
ject-orien ted databases with tuples, sets and lists. T ec hnical Rep
  • rt
CS-92-57. Computer Scienc e De- p artment, Br
  • wn
University, Decem b er, 1992. [19] G. M. Sha w, and S. B. Zdonik. A query algebra for
  • b
ject-orien ted databases. Pr
  • c.
  • f
Intl. Conf.
  • n
Data Engine ering, pp. 152{162, 1990. [20] J. D. Ullman. Principles
  • f
data and kno wledge- based systems. Computer Scienc e Pr ess . ISBN0- 7167-8158-1, 1988. [21] S. L. V anden b erg, and D. J. DeWitt. Algebraic Sup- p
  • rt
for Complex Ob jects with Arra ys, Iden tit y , and Inheritance. Pr
  • c.
  • f
A CM SIGMOD Conf., 1991.