CIS550 Handout 41 CIS 550 Fall 2001 Handout 4 Object Oriented Databases.

Slides:



Advertisements
Similar presentations
COP4540 Database Management System Midterm Review
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Why Object-Oriented DBMS? Abstract data types Interface with host programming language (the impedance mismatch). Object identity: (peter, 40, {(john, 15,
SQL Introduction Standard language for querying and manipulating data Structured Query Language Many standards out there: SQL92, SQL2, SQL3. Vendors support.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5 Modified by Donghui Zhang.
1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
Object Databases Baochuan Lu. outline Concepts for Object Databases Object Database Standards, Languages, and Design Object-Relational and Extended-Relational.
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Chapter 5 Types. 5-2 Topics in this Chapter Values vs. Variables Types vs. Representations Type Definition Operators Type Generators SQL Facilities.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Object-Orientation in Query Languages By: Toan Nguyen Class: CS 157A.
FALL 2004CENG 351 File Structures and Data Management1 SQL: Structured Query Language Chapter 5.
Database Principles Relational Algebra. Database Principles What is Relational Algebra? It is a language in which we can ask questions (query) of a database.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #3.
Programs with SQL Host language + Embedded SQL Preprocessor Host Language + function calls Host language compiler Host language program Preprocessor Host.
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
Database Systems More SQL Database Design -- More SQL1.
Object Oriented Databases - Overview
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Object and Object- Relational Databases.
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
Ch5: ER Diagrams - Part 2 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
XML-QL A Query Language for XML Charuta Nakhe
Visual Basic: An Object Oriented Approach 5: Structured Programming.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Why Object-Oriented DBMS? Abstract data types (relational data model is too simple). Interface with host programming language Managing large number of.
1 ICS 184: Introduction to Data Management Lecture Note 10 SQL as a Query Language (Cont.)
ADVANCED DATABASE SYSTEMS DR. FATEMEH AHMADI- ABKENARI SEPTEMBER Object Databases.
8 October, 2001DBIS4 - RLC108 Object Query Language The need for ad hoc querying What SQL does What OQL must do OQL syntax and examples.
©Silberschatz, Korth and Sudarshan9.1Database System Concepts Chapter 9: Object-Oriented Databases Nested Relations Complex Types and Object Orientation.
Instructor: Jinze Liu Fall Basic Components (2) Relational Database Web-Interface Done before mid-term Must-Have Components (2) Security: access.
Clinical Quality Language (CQL) Bryn Rhodes Chris Moesel Mark Kramer.
1 Relational Algebra. 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports.
Chapter 21 C OQL Copyright © 2004 Pearson Education, Inc.
Chapter 21 Object Database Standards, Languages, and Design Copyright © 2004 Pearson Education, Inc.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
OOPSLA LAB. 1 Chapter 4 Object Query Languages Prof. Hyoung-Joo Kim OOPSLA Lab. Dept. of Computer Engineering Seoul National University.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
CSE 6331 © Leonidas Fegaras OODB1 Object-Oriented Databases and the ODMG Standard.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 4 Relational Algebra.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
11-1 CHAPTER 11 Concepts for Object-Oriented Databases.
1 CSCE Database Systems Anxiao (Andrew) Jiang The Database Language SQL.
COMP3030 Database Management System Final Review
1 Spring 2000 Christophides Vassilis THE ODMG OBJECT QUERY LANGUAGE: OQL.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Himanshu GuptaCSE 532-SQL-1 SQL. Himanshu GuptaCSE 532-SQL-2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying.
The Object-Oriented Database System Manifesto Malcolm Atkinson, François Bancilhon, David deWitt, Klaus Dittrich, David Maier, Stanley Zdonik DOOD'89,
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples. v If the.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe Chapter 12 Outline Overview of Object Database Concepts Object-Relational Features Object Database.
Aggregator Stage : Definition : Aggregator classifies data rows from a single input link into groups and calculates totals or other aggregate functions.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Object Relational Databases
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Lecture 9 Symbol Table and Attributed Grammars
Why Object-Oriented DBMS?
Object-Oriented Databases and the ODMG Standard
More SQL: Complex Queries,
Slides are reused by the approval of Jeffrey Ullman’s
CS 440 Database Management Systems
CS 405G: Introduction to Database Systems
IST 210: Organization of Data
More SQL: Complex Queries, Triggers, Views, and Schema Modification
The Relational Algebra
Select-From-Where Statements Multirelation Queries Subqueries
Presentation transcript:

CIS550 Handout 41 CIS 550 Fall 2001 Handout 4 Object Oriented Databases

CIS550 Handout 42 Why OODBS? Consider a relational database in which we have information about Books: Problem: Redundancy in design is forced by the fact that we cannot have set valued attributes. ISBN Title Author Keyword Publisher Compilers J.D. Ullman Compiler Addison Wesley Compilers J.D. Ullman Grammar Addison Wesley Compilers A.V. Aho Compiler Addison Wesley Compilers A.V. Aho Grammar Addison Wesley Compilers J.E. Hopcroft Compiler Addison Wesley Compilers J.E. Hopcroft Grammar Addison Wesley

CIS550 Handout 43 “Normalized” Design We could imagine another design: ISBN Title Publisher Compilers Addison Wesley ISBN Author ISBN Keyword J.D. Ullman Compiler A.V. Aho Grammar J.E. Hopcroft

CIS550 Handout 44 Problems with Normalized Design The “object” book has been split over different relations. Artificial keys are introduced when modeling sets of sets. E.g. Cars can be be bought with certain features (CD, air conditioning, leather seats, etc). For each car, various packages of these features are available, each package being a particular set of features.

CIS550 Handout 45 Problems, cont. Impossible to represent order in relational data model While SQL can perform “group-by”, it cannot return a grouped result. E.g. “Give me all the authors together with a list of books written by that author”. We can call SQL from a “host” PL, but can we call external programs from SQL?

CIS550 Handout 46 The natural solution This is an example of the nested relational model, in which values may themselves be sets or tuples. What we’d like is a type system that allows us freely to combine sets and tuples (non- 1NF relations) This implies new operators: nest and unnest. ISBN Title Authors Keywords Publisher Compilers {J.D. Ullman, {Compiler, Addison Wesley A.V. Aho, Grammar} J.E. Hopcroft}

CIS550 Handout 47 Unnest Given nested relation R on the previous slide, we can unnest on one of the set- valued fields: ISBN Title Author Keyword Publisher Compilers J.D. Ullman {Compiler, Addison Wesley Grammar} Compilers A.V. Aho {Compiler, Addison Wesley Grammar} Compilers J.E. Hopcroft {Compiler, Addison Wesley Grammar} : UNNEST (R) {Author}

CIS550 Handout 48 Nest We can also and get back the original relation. But this isn't true in general! Consider the following example: (R) {Author} NEST A B 1 {2,3} 1 {3,4}

CIS550 Handout 49 Object-orientation Complex type system, including atomic types (string, integer, float, char, etc); collection types (sets, bags, lists); and the record type. Object identity gives identification of objects independent of value. Contrast this with the notion of a key in the relational model. Values with identity are called objects.

CIS550 Handout 410 Object-orientation, cont. Methods model the behavior of an object. For example, modifying the value of an object is often dangerous, and is encapsulated by methods (e.g. RaiseSalary and MovePoint). Types + Identity + Methods are Classes. Each of these new types gives rise to new operations on those types(as with nest and unnest)

CIS550 Handout 411 Classes, Types and Names Consider an schema representing persons, employees and consultants. class Person inherit Object public type tuple(name:string, male: boolean, spouse: Person, children: list(Person), dob: Date) public method age: integer end;

CIS550 Handout 412 Schema, cont. class Employee inherit Person public type tuple(salary: integer, subordinates: unique set(Employee)) end; class Consultant inherit Person public type tuple(phone: integer, rate: integer, num_hours:integer) public method earnings: integer end;

CIS550 Handout 413 Schema, cont. Note that Date is a user-defined type, and that Persons and Employees are the only entry-points into the database. type Date tuple(month: integer, day: integer, year: integer) name Persons: unique set(Person) name Employees: unique set(Employee)

CIS550 Handout 414 Select…from…where Print all females in the database. Print the values of all females in the database. select p from p in Persons where not(p.male) Result is of type set(Person) select *p from p in Persons where not(p.male) Result is of type set(tuple(name:string, male: boolean, spouse: Person, children: list(Person), dob: Date))

CIS550 Handout 415 Select…from…where, cont. Print the names of all females in the database. Result is of type set(string). select distinct p.name from p in Persons where not(p.male)

CIS550 Handout 416 More queries... Print the name and birth-date of all females in the database who were born in July. Result is of type set(tuple(name:string, dob: Date)) select struct(name: p.name, dob: p.dob) from p in Persons where not(p.male) and p.dob.month= 7

CIS550 Handout 417 Path expressions Print the names of all spouses. Print the names and dob of all spouses who were born in June. Result is of type set(tuple(name:string, dob:Date)). select p.spouse.name from p in Persons select struct(name: p.spouse.name, dob: p.spouse.dob) from p in Persons where p.spouse.dob.month=6 Result is of type set(string).

CIS550 Handout 418 Method Invocation Methods are functions which implicitly have as a parameter “self” and optional additional parameters. None of the example methods have any additional parameters. Print the names and age of all employees. select struct(name: e.name, age: e.age()) from e in Employees

CIS550 Handout 419 Aggregate Operators Aggregate operator count operates on collections of elements of any type, min and max operate on collections of ordered types, and sum operates on collections of numbers. Print the number of Employees. Note the difference from SQL: count(Employees) Result is of type integer. select count(*) from Employees

CIS550 Handout 420 Aggregate operators, cont. Print the maximum number of children of any person. Print the name and names of children of the persons with the maximum number of children. max(select count(p.children) from p in Persons) select struct(name: p. name, children: select c.name from c in p.children) from p in Persons where count(p.children)= max(select count(p1.children) from p1 in Person)

CIS550 Handout 421 Unnesting Print all pairs (manager, employee) of managers in Employees. Print the names of all subordinates of Joe Brown. select struct(manager: e.name, employee: s.name) from e in Employees, s in e.subordinates where count(e.subordinates) >0 select s.name from e in Employees, s in e.subordinates where e.name="Joe Brown"

CIS550 Handout 422 An incorrect version Compare the previous query with the following (incorrect) query: The incorrect query would cause a compile time error because subordinates is of type set(Employee), and you can only use projection over a record type. select e.subordinates.name from e in Employees

CIS550 Handout 423 Flatten Flatten gets rid of one level of set (collection) nesting, e.g. it takes something of type set(set(element)) and produces something of type set(element) by taking the union of all sets of elements. (This is not the same as the “unnest” operator we have discussed.) flatten({{1,2},{3,4},{1,5}}) = {1,2,3,4,5,1}

CIS550 Handout 424 An example... Print the names of employees who are supervised by someone. Note that is of type set(set(Employees)). select s.name from s in flatten(select e.supervises from e in Employees) (select e.supervises from e in Employees)

CIS550 Handout 425 Group by Group by introduces a level of set nesting, and produces something of type set(tuple(label:..., partition: set(...))). For each salary, print the employees earning that salary. Result is of type set(tuple(salary: integer, partition: set(struct(e:Employee)))). select * from e in Employees group by e.salary

CIS550 Handout 426 Example, cont. We could also have written the previous query as: select struct(salary: e.salary, partition:(select * from e1 in Employees where e.salary=e1.salary)) from e in Employees

CIS550 Handout 427 Group by … having “For each salary earned by more than 2 employees, print the set of names of employees earning that salary.” Result is of type set(tuple(salary:integer, name:set(string))). select struct(salary: e.salary, names: (select e1.name from e1 in partition)) from e in Employee group by e.salary having count(partition)>2

CIS550 Handout 428 Indexing into a list. Lists are ordered sets, and are treated as arrays indexed starting from 0. We cannot into sets. “Print all first-born children.” Result is of type set(Person). Note the explicit test that the list was non-empty. We could also have used count. select p.children[0] from p in Person where p.children<>list()

CIS550 Handout 429 Lists, cont. “Print the names of all second-born children.” (Recall that list indexing starts with 0.) Result is of type set(string). select p.children[1].name from p in Person where count(p.children)> 1

CIS550 Handout 430 Sort... in… by “select...from...where” creates a bag of elements from an input set, “select distinct...from...where” creates a set. To create a list of element as output from an input set, we use “sort...in...by”. “Print the names and ages of employees by increasing age.” Result type is list(tuple(name:string, age:integer)). sort x in (select struct(name:e.name, age:e.age()) from e in Employees) by x.age()

CIS550 Handout 431 Creating sets from lists A list can be converted to a set using listtoset. For example, suppose we want to print each person with children represented as a set rather than a list. Result type is set(tuple(name:string,children:set(Person)). select struct(name:p.name, children: listtoset(p.children)) from p in Person

CIS550 Handout 432 Set operations: difference “Print the employees who are supervised by noone.” Result type is set(Employee). select e from Employees where not(e in flatten(select e1.supervises from e1 in Employees)) OR (select e in Employees) -flatten(select e.supervises from e in Employees)

CIS550 Handout 433 Set operations: union “Print the names of all people who are either employees or consultants.” But we cannot do this because “Consultants” is not a named entry point into our database! select e.name from e in Employees + select c.name from c in Consultants

CIS550 Handout 434 Casting Casting is sometimes necessary to support type inferencing. For example, suppose we know that all people in our database are either Employees or Consultants: “Print the names of all consultants.” Result type is set(string). The type of the expression “ select (Person)e from e in Employees ” is set(Person). select c.name from c in (Persons - (select (Person)e from e in Employees))

CIS550 Handout 435 Casting, cont. We could also have said Since Employee inherits Person, the type of the expression would have been the most general type ( Person ), and Employee would be implicitly cast to a Person. Persons - Employees

CIS550 Handout 436 Casting, cont. “Print names and earnings of consultants.” Note that is of type set(Person), and that the Person type does not have the method earnings. select struct(name:p.name, earnings:((Consultant)p).earnings()) from p in (Persons - (select (Person)e from e in Employees)) Persons - (select (Person)e from e in Employees

CIS550 Handout 437 Quantifier Expressions Expressions “exists” and “for all” also exist in OQL. For example: “Print the names of people who have had at least one boy.” “Print the names of people who had all boys.” select struct(name:p.name) from p in Persons where exists c in p.children: c.male select struct(name: p.name) from p in Persons where forall c in p.children: c.male

CIS550 Handout 438 Element Sometimes we want to turn a collection containing one element into the element type. Note that this is not always safe, i.e. testing whether a collection has a single element is not something that can be checked at compile time, so a run-time error may occur.

CIS550 Handout 439 Element, an example “For all people with single-child families, print the person’s name and their child’s name.” Note that this is safe since we explicitly checked the number of children. select struct(name:p.name, cname: element(select c.name from c in p.children)) from p in Persons where count(p.children)=1

CIS550 Handout 440 Element, another example “Print the tuple of information about John Kramer.” If we know “name” is a key for Person, then the following query will be correct: However, we do not really have the ability to specify keys in so there is no way that this can be checked at compile time! element(select *p from p in Persons where p.name="John Kramer")

CIS550 Handout 441 Summary OQL is a language for complex object databases. The types include: –base types- integer, string, boolean –tuple type - tuple( ) –the collection types - unique set (set), set (bag) and list –objects (class types) For each type, basic operations (including constructor and destructor operations) are defined.

CIS550 Handout 442 Summary, cont For example, –For objects o, we can dereference (*o) and cast ((Person)o). – For tuples, we can project over attributes (e.g. p.name). –For sets, we can select elements, flatten, extract an element from a singleton set, take unions (+ or union), set difference (- or except) and intersection (* or intersect). –For lists, we can extract indexed elements and create lists by specifying an ordering on elements.