Πανεπιστήµιο Κρήτης Τµήµα Επιστήµης Υπολογιστών ΗΥ-561 ιαχείριση εδοµένων στο Παγκόσµιο Ιστό Βασίλης Χριστοφίδης Ονοµατεπώνυµο: Αριθµός Μητρώου: Άσκηση 1 (55 µονάδες) Τελική Εξέταση (3 ώρες) Ηµεροµηνία: Τρίτη 28 Ιουνίου 2005 Σας δίνεται το παρακάτω µοντέλο οντοτήτων-συσχετίσεων (ΟΣ) για την αναπαράσταση πληροφορίας σχετικής µε την εξυπηρέτηση πελατών από διαφορετικές εταιρίες κινητής τηλεφωνίας. Area Code Phone No. State Zip Phone Email Year of Birth City Address Customer Name Street Name SSN Street No. Uses Service Provider Name Service Plan Plan Id Plan Title Monthly fee Anytime minute Night weekend minute 1.(15 µονάδες) Μεταφράστε το παραπάνω µοντέλο ΟΣ σε σχήµα XML. Σχεδιάστε κατάλληλους τύπους στοιχείων XML για κάθε οντότητα λαµβάνοντας υπόψη τους περιορισµούς ακεραιότητας (κλειδιά, εξωτερικά κλειδιά) καθώς και ότι: Α) Για κάθε Πελάτη (Customer): SSN (1 occurrence, required) Name (1 occurrence, required) Year of Birth (CCYY-MM-DD) (0 or 1 occurrence, optional)
Phone (1 occurrence, required) Address (0 or 1 occurrence, optional) Email (0 or more occurrences, optional) Plan Id (1 occurrence, required) Β) Για κάθε προσφερόµενη Υπηρεσία (Service Plan): Plan Id (1 occurrence, required) Plan Title (1 occurrence, required) Service Provider Name (1 occurrence, required) Monthly fee (values from 10 to 115, required) Anytime minute (1 occurrence, required) Night & weekend minute (0 or 1 occurrence, optional) Για λόγους ευκολίας, υποθέστε ότι κάθε πελάτης έχει µόνο ένα κινητό τηλέφωνο. <?xml version="1.0" encoding="utf-8"?> <xs:schema elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xs:nonamespaceschemalocation="plans.xsd"> <xs:element name="customers"> <xs:element ref="customer" minoccurs="0" maxoccurs="unbounded" /> <xs:element name="customer"> <xs:element name="ssn" type="xs:string" <xs:key name="customerskey"> <xs:selector xpath=".//customer" /> <xs:field xpath="ssn" /> </xs:key> <xs:element name="name" type="xs:string" <xs:element name="year_of_birth" type="rsh_date" minoccurs="0" maxoccurs="1" nillable="true"/> <xs:element ref="phone" <xs:element ref="address" minoccurs="0" maxoccurs="1" nillable="true"/> <xs:element name="email" type="xs:string" minoccurs="0" maxoccurs="unbounded" nillable="true"/> <xs:element name="plan_id" type="xs:int"> <xs:keyref name="uses" msdata:refrencekey="true" refer="service_planskey"> <xs:selector xpath=".//customer" /> <xs:field xpath="plan_id" /> </xs:keyref> <xs:simpletype name="rsh_date"> <xs:restriction base="xs:string"> <xs:pattern value="\d{4-\d{2-\d{2" /> <!-- Normal date --> <xs:pattern value="\d{4-\d{1-\d{2" /> <xs:pattern value="\d{4-\d{2-\d{1" /> <xs:pattern value="\d{4-\d{1-\d{1" />
</xs:restriction> </xs:simpletype> <xs:element name="phone"> <xs:element name="area_code" type="xs:string" /> <xs:element name="phone_no" type="xs:string" /> <xs:element name="address"> <xs:element name="street_no" type="xs:string" /> <xs:element name="street_name" type="xs:string" /> <xs:element name="city" type="xs:string" /> <xs:element name="state" type="xs:string" /> <xs:element name="zip" type="xs:string" /> </xs:schema> <?xml version="1.0" encoding="utf-8"?> <xs:schema elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="serviceplans"> <xs:element ref="service_plan" minoccurs="0" maxoccurs="unbounded" /> <xs:element name="service_plan"> <xs:element name="plan_id" type="xs:int" <xs:key name="service_planskey" msdata:primarykey="true"> <xs:selector xpath=".//service_plan" /> <xs:field xpath="plan_id" /> </xs:key> <xs:element name="plan_title" type="xs:string" <xs:element name="service_provider_name" type="xs:string" <xs:element name="monthly_fee" type="fee_type" <xs:element name="anytime_minute" type="xs:int" <xs:element name="night_and_weekend_minutes" type="xs:nonnegativeinteger" minoccurs="0" maxoccurs="1"/> <xs:simpletype name="fee_type"> <xs:restriction base="xs:unsignedbyte"> <xs:mininclusive value="10" /> <xs:maxinclusive value="115" /> </xs:restriction> </xs:simpletype> </xs:schema>
2.(25 µονάδες) ώστε τις εκφράσεις XQuery καθώς και τον τύπο του αποτελέσµατος τους για τις παρακάτω επερωτήσεις, υποθέτοντας ότι σας δίνονται δύο σχετικά έγγραφα XML customers.xml και plans.xml: a) ώστε τις διευθύνσεις ηλεκτρονικού ταχυδροµείου για κάθε πελάτη. (Κάθε διεύθυνση ηλεκτρονικού ταχυδροµείου πρέπει να διαχωρίζεται από ","). Ταξινοµήστε το αποτέλεσµα σε αύξουσα σειρά ως προς το όνοµα των πελατών. for $customer in document("customers.xml")//customer order by $customer/name ascending return <email_info> { $customer/name, <emails> {for $em in $customer/email return ($em/text(), ", ") </emails> </email_info> element email_info { element Name {xsd:string, element emails {{text* * b) ώστε τον αριθµό πελατών για κάθε ταχυδροµικό κώδικα (zip). Ταξινοµήστε το αποτέλεσµα σε φθίνουσα σειρά ως προς τον αριθµό των πελατών. for $zip in (distinct-values(document("customers.xml")//zip)) let $customer_num := count(document("customers.xml")//customer [Address/Zip = $zip]) order by $customer_num descending return <customer_num> { $zip, if ($customer_num < 10) then <count>0{$customer_num</count> else <count>{$customer_num</count> </customer_num> element customer_num { element Zip {xsd:string, element count {xsd:integer * c) ώστε τη µέση µηνιαία χρέωση σύνδεσης για κάθε εταιρία παροχής κινητής τηλεφωνίας. (Η συνάρτηση avg της XQuery δέχεται ως είσοδο µια ακολουθία τιµών µε τύπο xdt:anyatomictype οι οποίες στην συνέχεια µετατρέπονται σε double για να τις χειριστεί η συνάρτηση. Τελικά ο επιστρεφόµενος τύπος είναι xdt:anyatomictype.)
for $sp in distinct-values(document("plans.xml") //Service_Provider_Name) let $monthly_fee := document("plans.xml")//service_plan [Service_Provider_Name = $sp]/monthly_fee return <Avg_Monthly_Fee> { $sp, <Average_Monthly_Fee>{avg($monthly_fee)</Average_Monthly_Fee> </Avg_Monthly_Fee> element Avg_Monthly_Fee { element Service_Provider_Name {xsd:string, element Average_monthly_Fee {xdt:anyatomictype * d) ώστε τον αριθµό πελατών για κάθε εταιρία παροχής κινητής τηλεφωνίας. Ταξινοµήστε το αποτέλεσµα σε φθίνουσα σειρά ως προς τον αριθµό των πελατών. let $sp := document("plans.xml")//service_plan for $spn in distinct-values($sp/service_provider_name) let $customer_num := count(document("customers.xml")//customer [Plan_ID = $sp[service_provider_name = $spn]/plan_id]/ssn) order by $customer_num descending return <Num_Customers> { $spn, if ($customer_num < 10) then <count>0{$customer_num</count> else <count>{$customer_num</count> </Num_Customers> element Num_Customers { element Service_Provider_Name {xsd:string, element count {xsd:integer * e) ώστε το όνοµα των πελατών που έχουν την υπηρεσία χαµηλής χρέωσης την νύχτα και τα Σαββατοκύριακα (Night and weekend minute service). for $customer in document("customers.xml")//customer, $sp in document("plans.xml")//service_plan where $sp/plan_id = $customer/plan_id and not(empty($sp/night_and_weekend_minutes)) return $customer/name element Name {xsd:string* 3. (15 µονάδες) Καθορίστε τη σχέση εγκλεισµού (περιέχει, περιέχεται, ισοδύναµη, ή κανένα από τα ανωτέρω) µεταξύ των παρακάτω XPath εκφράσεων E και E': 1. E = /a/b[.//a/b], E' = //a/b 2. E = /a[.//b[c/d]]/b/c/d, E' = /a/b/c/d 3. E = /a[b > 0]/c, E' = /a[b > 10]/c ικαιολογήστε σύντοµα την απάντησή σας.
1. E' contains E (i.e., The answers for the query E' is ALWAYS a superset of the results for E) 2. E' = E 3. E contains E' Άσκηση 2 (20 µονάδες) 1.(10 µονάδες) Είναι οι ακόλουθοι δύο γράφοι bisimilar; ικαιολογήστε σύντοµα την απάντησή σας. Για ευκολία υποθέστε ότι όλες οι ακµές έχουν την ίδια ετικέτα "L". X X Z W Y Y Z 17 17 Claim: These graphs are bisimilar. Proof: Let G1 and G2 be the graphs above, and let R be the following relation over the nodes of G1 and G2 (described as a set of pairs): (X, X ), (Y, Y ), (Z, Z ), (W, Z ) It is easy to check that the following three statements are true: (a) R is maximal (all nodes of G1 and G2 are involved in R) (b) For each pair (t,s) in R, and for each edge (t,a,t ) in G1, there exists an edge (s,a,s ) in G2 such that (t,s ) is in R (c) [reverse of (b)] For each pair (t,s) in R, and for each edge (s,a,s ) in G2, there exists an edge (t,a,t ) in G1 such that (t,s ) is in R. Therefore R is a desired relation that establishes bisimilarity of G1 and G2. 2.(5 µονάδες) Ποια είναι τα σηµαντικά κοινά χαρακτηριστικά του αντικειµενοστρεφούς µοντέλου δεδοµένων και του µοντέλου ηµι-δοµηµένων δεδοµένων που δεν υπάρχουν στο σχεσιακό µοντέλο δεδοµένων; 1) Values are not required to be atomic (like in relational model) but can be themselves sets, tuples or relations (sets of tuples) objects have identity 2) In both the complex object and semistructured data models the data can be viewed as a graph with an arbitrary structure whereas in the relational data model we have a tree of uniform structure DB is a set of relations, relation is a set of tuples, tuples have attributes that are atomic values. 3.(5 µονάδες) Ποιες είναι οι κύριες διαφορές του αντικειµενοστραφούς µοντέλου δεδοµένων και του µοντέλου ηµι-δοµηµένων δεδοµένων; Τι επιπτώσεις έχουν αυτές οι διαφορές στην αναπαράσταση και επερώτηση των δεδοµένων;
1) Unlike complex object data models, semistructured data are self-describing (the schema is described as part of data). This could complicate query formulation and optimization. 2) The complex object data model implies only an arbitrary nesting of the data. The values inserted have to conform to this nested structure. In the semistructured data model, we can cope with irregular structure. Elements may be missing, or different elements may have a different structure. Facilities like regular path expressions have to be provided in order to query uncertain or irregular structure. For example if we have defined a complex object consisting of a set of tuples with a certain tuple structure then all tuples inserted for this object are of the same structure. This is not the case in semistructured data. E.g., in a complex object data model, when we define a nested structure like Bibliography: { <Title, Authors: {<Firstname,Lastname>> then the values for all tuples <Title, Authors: {<Firstname,Lastname>> will have to fit into the same structure Title Authors First Last abc f1 l1 f2 l2 xyz f1 l1 f2 l2 with semistructured data, it is possible to define tuples of (title,author) that do not all have the same structure. Άσκηση 3 (25 µονάδες) α) (5 µονάδες) ώστε τις βασικές διαφορές ενός µπλοκ For-Let-Where- Return (FLWR) της ΧQuery µε το αντίστοιχο µπλοκ Select-From-Where (SFW) της SQL. (a) Variables are bound based on path expressions (which may require new query primitives); (b) Query block output should be a collection of trees with bound variables within tags, rather than a collection of tuples; (c) FLWR filter supports variables assignment which combined with conditionals and functions make XQyery a fully programming language rather than a query language like SQL β) (10 µονάδες) Προτείνετε µια γλώσσα προγραµµατισµού XML για το βασικό µπλοκ δηλώσεων (FLWR) της ΧQuery η οποία να βασίζεται στον Κατηγορηµατικό Λογισµό (πχ. όπως ο Σχεσιακός Λογισµός Πεδίων) The variables in our language are bound to trees or sets of trees. We allow XPath expressions as primitives in the language, which we interpret as functions from trees to sets of trees, in the usual way. We also take as a primitive the document function. For simplicity, we ignore order. A query result is a set of trees. The head of the expression in our language is a template corresponding to the XQuery return clause, composed of a variable or list of variables, possibly nested inside XML tags. For example, return <answer > $t </answer > would map to { <answer > $t </answer >... The body of the expression contains quantifiers and conditions corresponding to the quantifiers and conditions in the XQuery for, let, where clauses. For example, for $p in document( dbinproc.xml")/dblp/inproceedings translates to { ( p)(p document( db-inproc.xml")/dblp/inproceedings).
γ) (10 µονάδες) ώστε ένα παράδειγµα της προτεινόµενης λογικής γλώσσας, µεταφράζοντας την ακόλουθη επερώτηση ΧQuery: for $p in document(`dblp-inproc.xml')/dblp/inproceedings, $a in $p/author let $t := $p/title where $a = `Serge Abiteboul' return $t; {t ( p,a,t) (p document( dblp-inproc.xml )/dblp/inproceedings a p/author t = p/title a = Serge Abiteboul )