Vous êtes sur la page 1sur 70

Bases de Donnes

Avances
Enseignant / charg de TD : Dario COLAZZO
www.lri.fr/~colazzo
Charge de TP : Jess CAMACHO-RODRIGUEZ
www.lri.fr/~camacho
Tuesday, January 29, 2013
Plan

Tuning dindex

Concurrence

Reprise sur panne

Donnes semi-structure et XML,


programmation Web

Gestion de donnes via MapReduce


Tuesday, January 29, 2013
Plan

Tuning dindex

Concurrence

Reprise sur panne

Donnes semi-structure et XML,


programmation Web

Gestion de donnes via MapReduce


Tuesday, January 29, 2013
Modalits de Contrle

Des mini contrles

QCM mardi 5 fvrier (dure 45 minutes)

TP not jeudi 7 fvrier (dure 1h)

QCM n de semaine en n fvrier

Devoir sur table en n de cours


Tuesday, January 29, 2013
XML et programmation WEB

Intro Web & XML

Requte XML : XPath

Transformation XML : XSLT

Programmation Web via XML : DOM


Tuesday, January 29, 2013
Intro Web & XML
Tuesday, January 29, 2013
XML
XML (eXStensible Markup Language):
format de reprsentation de donnes semi-structures
standardis par le W3C (http://www.w3.org)
indpendant de la plateforme utilis
Souvent prsent comme le successeur de HTML, en ralit
HTML est un langage pour dterminer l'afchage
dinformation via des pages Web
XML est un meta-langage, permettant de dnir des
nouveaux langages (dialectes XML), HTML en particulier.
Tuesday, January 29, 2013
Web : de HTML XML
HTML dcrit le format de prsentation via browser
Tuesday, January 29, 2013
HTML
<h1> Bibliography </h1>
<p> <i> Foundations of Databases </i>
Abiteboul, Hull, Vianu
<br> Addison Wesley, 1995
<p> <i> Data on the Web </i>
Abiteboul, Buneman, Suciu
<br> Morgan Kaufmann, 1999
Tuesday, January 29, 2013
XML
<bibliography>
<book>
<title> Foundations of Databases </title>
<author> Abiteboul </author>
<author> Hull </author>
<author> Vianu </author>
<publisher> Addison Wesley </publisher>
<year> 1995 </year>
</book>
<book>
<title> Data on the Web </title>
<author> Abiteboul </author>
<author> Buneman </author>
<author> Suciu </author>
<publisher> Morgan Kaufmann </publisher>
<year> 1999</year>
</book>
<bibliography>
Tuesday, January 29, 2013
Avantages
Format standard de reprsentation et partage de donnes sur le Web
Il est bas sur une reprsentation textuelle et balise (comme HTML)
==> facilement transfrable sur le Web via HTTP
Plusieurs systmes disponibles pour la cration, analyse et gestion de
documents XML
Largement utilise pour lexchange de donnes entre applications
Reprsentation de donne dans plusieurs contextes hors du Web
MS World, Excel, etc.
donnes scientique
chiers de log
Tuesday, January 29, 2013
Elements
<bibliography>
<book> <title> Foundations </title>
<author> Abiteboul </author>
<author> Hull </author>
<author> Vianu </author>
<publisher> Addison Wesley </publisher>
<year> 1995 </year>
</book>

</bibliography>
Tuesday, January 29, 2013
Attributs
<bibliography>
<book price=`120 label=fds>
<title> Foundations </title>
<author> Abiteboul </author>
<author> Hull </author>
<author> Vianu </author>
<publisher> Addison Wesley </publisher>
<year> 1995 </year>
</book>
<book price=`110 label=dw>
<title> Data on the Web </title>
<author> Abiteboul </author>
<author> Buneman </author>
<author> Suciu </author>
<publisher> Morgan Kaufmann </publisher>
<year> 1999</year>
<cite ref=fds ></cite>
</book>
<bibliography>
Tuesday, January 29, 2013
Documents bien forms
Un document XML est bien form sil respecte des proprits
syntaxiques. En particulier :
Il contient les composantes ncessaires:
-
un prambule, par ex. <?xml version="1.0" encoding="ISO-8859-1"?>
-
un seul lment racine
Les tags sont balancs :
-
tout tag ouvert doit avoir un tag ferm correspondant
-
les tags sont correctement imbriqus le dernier tag ouvert est le
premier tre ferm

<TAG1><TAG2><TAG3>...</TAG3></TAG2></TAG1> OUI
<TAG1><TAG2><TAG3>...</TAG2></TAG3></TAG1> NON
Tuesday, January 29, 2013
Document BF
<?xml version="1.0" encoding="ISO-8859-1"?>
<bibliography>
<book price=`120 label=fds>
<title> Foundations </title>
<author> Abiteboul </author>
<author> Hull </author>
<author> Vianu </author>
<publisher> Addison Wesley </publisher>
<year> 1995 </year>
</book>
<book price=`110 label=dw>
<title> Data on the Web </title>
<author> Abiteboul </author>
<author> Buneman </author>
<author> Suciu </author>
<publisher> Morgan Kaufmann </publisher>
<year> 1995 </year>
<cite ref=fds ></cite>
</book>
<bibliography>
Tuesday, January 29, 2013
Sous forme darbre
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
/
racine document
lment
attribut
texte
Tuesday, January 29, 2013
DTD
Nous pouvons donner la spcication de notre langage de
reprsentation de donnes bibliographique.
Via une DTD (Document Type Dnition)
Un document D est valide par rapport une DTD si la structure de
D respecte la DTD
Plusieurs programmes existent pour vrier la validation
DTD : ensemble de declarations spciant la structure dun type
d'lment ou dattribut.
Type lment : tag + structure contenu (expression rgulire)
Type attribut : tag + type valeur + contrainte
Tuesday, January 29, 2013
Type element
Type dlment : tag + structure contenu (expression rgulire)
<!ELEMENT tag structure>
La structure dcrit le contenu via une expression rgulire, par exemple :
A, B : un A suivi dun B
A, B* : un A suivi de 0 ou plusieurs B
A, B?, C+ : un A, suivi de 0 ou 1 B, suivi dau moins un C
A, (B|C)* : un A suivi de plusieurs B ou C dans nimporte quel ordre
Le type #PCDATA (chaine de caractres) peut tre utilis dans la
structure :
(#PCDATA | A | B)* : contenu mixte, texte simple mlang avec des
lments avec tag A ou B, dans nimporte quel ordre
Aussi, la structure peut tre soit EMPTY soit ANY
Tuesday, January 29, 2013
DTD pour bibliography
<!ELEMENT bibliography (book* )>
<!ELEMENT book (title, (author+ | editor+ ), publisher, year?, cite* )>
<!ELEMENT author (#PCDATA)>
<!ELEMENT editor (#PCDATA)>
<!ELEMENT title (#PCDATA )>
<!ELEMENT cite EMPTY>
Dclaration des types lment
Tuesday, January 29, 2013
Type attribut
CDATA
ID
IDREF
{s1,....,sn}
#REQUIRED
#IMPLIED
...........
<!ELEMENT book (title, (author+ | editor+ ), publisher, year?, cite* )>
<!ATTLIST book price CDATA #IMPLIED>
<!ATTLIST book label ID #REQUIRED>
.........
<!ELEMENT cite EMPTY>
<!ATTLIST cite ref IDREF #IMPLIED>
.........
Type dattribut : tag + type contenu + contrainte
Tuesday, January 29, 2013
DTD pour bibliography
<!ELEMENT bibliography (book* )>
<!ELEMENT book (title, (author+ | editor+ ), publisher, year?, cite* )>
<!ATTLIST book price CDATA #IMPLIED>
<!ATTLIST book label ID #REQUIRED>
<!ELEMENT author (#PCDATA)>
<!ELEMENT editor (#PCDATA)>
<!ELEMENT title (#PCDATA )>
<!ELEMENT cite EMPTY>
<!ATTLIST cite ref IDREF #IMPLIED>
Tuesday, January 29, 2013
Lier une DTD un document
DTD externe
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE bibliography SYSTEM "biblio.dtd">
<bibliography>
........
<bibliography>
DTD interne
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE bibliography [
<!ELEMENT bibliography (book* )>
<!ELEMENT book (title, (author+ | editor+ ), publisher, year?, cite* )>
.............
]>
<bibliography>.......
........
<bibliography>
Tuesday, January 29, 2013
XPath
Tuesday, January 29, 2013
XPath
Le langage permet de dsigner un ou plusieurs nuds dans un
document XML, laide dexpressions de chemin.
XPath est un sous langage de XSLT (et XQuery)
Exemples :
XSLT
<xsl:value-of select="/bibliography/book[1]/@price">
XQuery
for $x in $doc/bibliography//title/text()
return
<titre>$x</titre>

Tuesday, January 29, 2013
Expressions XPath
Une expression XPath :

svalue en fonction dun nud contexte

dsigne un ou plusieurs chemins dans larbre partir du nud


contexte

a pour rsultat :

un ensemble de nuds

ou une valeur, numrique, booleenne ou alphanumrique


Tuesday, January 29, 2013
Exemple de reference
<?xml version="1.0" encoding="ISO-8859-1"?>
<bibliography>
<book price=`120 label=fds>
<title> Foundations </title>
<author> Abiteboul </author>
<author> Hull </author>
<author> Vianu </author>
<publisher> Addison Wesley </publisher>
<year> 1995 </year>
</book>
<book price=`110 label=dw>
<title> Data on the Web </title>
<author> Abiteboul </author>
<author> Buneman </author>
<author> Suciu </author>
<publisher> Morgan Kaufmann </publisher>
<year> 1995 </year>
<cite ref=fds ></cite>
</book>
<bibliography>
Tuesday, January 29, 2013
Exemple de reference
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
/
racine document
lment
attribut
texte
Tuesday, January 29, 2013
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Requtes XPath
Une requte XPath est une suite dtapes :
[/]tape /tape /.../tape
chemin absolu /bibliography/book
chemin relatif book/title
Deux types de requtes:
Tuesday, January 29, 2013
Une tape XPath
Une tape : trois composants
axe::ltre[prdicat1][prdicat2]
laxe : sens de parcours des nuds
le ltre : type des nuds qui seront retenus
le(s) prdicat(s) : proprits que doivent satisfaire les nuds
retenus par axe::ltre
On peut faire une union de chemins : //title | book/@price
Tuesday, January 29, 2013
Evaluation dune requte XPath
etape1 /etape2 /..... /etapeN
A partir du nud contexte, on value ltape 1 ; on obtient un
ensemble de nuds ;
on prend alors, un par un, les nuds de cet ensemble, et on les
considre chacun leur tour comme nud contexte pour
lvaluation de ltape 2 ;
chaque tape, on prend successivement comme nud contexte
chacun des nuds faisant partie du rsultat de ltape prcdente.
Tuesday, January 29, 2013
/child::bibliography/child::book
Syntaxe abrge : /bibliography/book
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
/child::bibliography/child::book/child::title
Syntaxe abrge : /bibliography/book/title
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
/child::bibliography/child::book/attribute::price
Syntaxe abrge : /bibliography/book/title/@price
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Contexte devaluation
etape1 /etape2 /..... /etapeN
Une tape svalue en tenant compte dun contexte constitu de
un nud contexte, position initiale de ltape ;
ce nud fait lui-mme partie dun ensemble obtenu par valuation
de ltape prcdente ;
- on connat la taille de cet ensemble (fonction last())
- on connat la position du nud contexte dans cet ensemble
(fonction position())
Tuesday, January 29, 2013
Les axes XPath
axe::ltre[predicat1]...[predicatN]
Un axe XPath slectionne un ensemble de nuds :
en effectuant une navigation partir du nud contexte, selon la
direction de laxe ;
Par exemple, laxe child effectue une navigation vers le bas partir
du nud contexte, et slectionne les ls de celui-ci.
Les axes XPath permettent de naviguer verticalement et
horizontalement dans larbre XML.
Tuesday, January 29, 2013
Les ltres XPath
axe::ltre
Un ltre rafne lensemble de nuds retourns par laxe
child::book les ls de nud contexte ayant tag book
child::node() tout les ls lments du nud contexte
child::* tout les ls lment du nud contexte
child::text() tout les ls texte du nud contexte
Tuesday, January 29, 2013
Nud contexte
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Laxe child
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
L'tape child::node()
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
L'tape child::author
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
L'tape child::text()
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Laxe parent
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
L'tape parent::bibliograpgy
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
L'axe parent::year
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Laxe descendant
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
L'tape descendant::text()
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Laxe descendant-or-self
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Notation //A
Abrviation de /descendant-or-self::node()/child::A
Tuesday, January 29, 2013
//book
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
L'axe ancestor-or-self
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
On change de nud contexte
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Laxe following-sibling
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Ltape following-siblings::year
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Laxe preceding-sibling
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Laxe following
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Laxe preceding
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
/descendant::node()/child::cite/parent::node() ?
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
/descendant::node()/child::cite/parent::node()
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Predicats
axe::ltre[predicat1]...[predicatN]
Prdicat : expression boolenne constitue dun ou plusieurs tests,
composs avec les connecteurs logiques habituels and et or
Types de test :
- toute expression XPath, dont le rsultat est convertie en boolen*
- une comparaison ou un appel de fonction.
* il faut connatre les rgles de conversion
Tuesday, January 29, 2013
Exemples
/A/B[@att1] : les nuds /A/B qui ont un attribut @att1
/A/B[@att1=a1] : les nuds /A/B qui ont un attribut @att1 valant
a1
/A/B/descendant::text()[position()=1]
Le premier nud de type texte descendant dun /A/B.
Sabrge : /A/B/descendant::text()[1]
Tuesday, January 29, 2013
Conversion dans /A/B[@att1]
On sintresse aux nuds de type B ls de llment racine A.
Parmi ces nuds on ne prend que ceux pour lesquels le prdicat
[@att1] svalue true
Cette expression svalue avec pour nud contexte un lment B
[@att1] vaut true ssi @att1 renvoie un ensemble de nuds non
vide
Tuesday, January 29, 2013
Types dans XPath
On peut effectuer des comparaisons, des oprations.
Cela implique un typage et des conversions de type.
Types XPath :
les numriques
les chanes de caractres
les boolens (true et false)
les ensembles de nuds
Tuesday, January 29, 2013
Conversions
Deux conversions sont toujours possibles :
Vers une chane de caractres : utile pour la production de texte en
XSLT
Ex. (xsl:value-of)
Vers un boolen : utile pour les tests effectus dans XSLT
Ex. (xsl:if, xsl:when)
Tuesday, January 29, 2013
Conversion boolennes automatiques
Numriques : 0 ou NaN sont false, tout le reste est true
Chanes : une chane vide est false, tout le reste est true
Ensembles de nuds : un ensemble vide est false, tout le reste est
true
Tuesday, January 29, 2013
Conversion boolennes automatiques
Numriques : 0 ou NaN sont false, tout le reste est true
Chanes : une chane vide est false, tout le reste est true
Ensembles de nuds : un ensemble vide est false, tout le reste est
true
Tuesday, January 29, 2013
Fonctions
concat(chane1, chane2, ...) : pour concatner des chanes
contains(chane1, chane2) : teste si chane1 contient chane2
count (expression) : renvoie le nombre de nuds dsigns par
expression
name() : renvoie le nom du nud contexte
not(expression) : permet dexprimer la ngation
Tuesday, January 29, 2013
Exemples au tableau
bibliography
book book
price title author author author publisher year
/
price title author author author publisher year label cite
120
label
fds Found.... Abitebul Hull Vianu Addison... 1995 110 dw Data .... Abitebul Buneman Vianu Morgan... 1999
ref
fds
Tuesday, January 29, 2013
Tuesday, January 29, 2013
Tuesday, January 29, 2013