• Aucun résultat trouvé

Synthesizing transformations from XML schema mappings

N/A
N/A
Protected

Academic year: 2022

Partager "Synthesizing transformations from XML schema mappings"

Copied!
12
0
0

Texte intégral

(1)

HAL Id: hal-01854501

https://hal-upec-upem.archives-ouvertes.fr/hal-01854501

Submitted on 6 Aug 2018

HAL is a multi-disciplinary open access archive for the deposit and dissemination of sci- entific research documents, whether they are pub- lished or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers.

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de recherche français ou étrangers, des laboratoires publics ou privés.

Synthesizing transformations from XML schema mappings

Claire David, Piotr Hofman, Filip Murlak, Michal Pilipczuk

To cite this version:

Claire David, Piotr Hofman, Filip Murlak, Michal Pilipczuk. Synthesizing transformations from

XML schema mappings. 17th International Conference on Database Theory (ICDT 2014), Mar 2014,

Athènes, Greece. pp.61-71, �10.5441/002/icdt.2014.10�. �hal-01854501�

(2)

Synthesizing transformations from XML schema mappings

Claire David

University Paris-Est Marne Claire.David@univ-mlv.fr

Piotr Hofman

University of Warsaw ph209519@mimuw.edu.pl

Filip Murlak

University of Warsaw fmurlak@mimuw.edu.pl

Michał Pilipczuk

University of Bergen michal.pilipczuk@ii.uib.no

ABSTRACT

XML schema mappings have been developed and studied in the context of XML data exchange, where a source document has to be restructured under the target schema according to certain rules.

The rules are specified with a mapping, which consists of a set of source-to-target dependencies based on tree patterns. The problem of building a target document for a given source document and a mapping has polynomial data complexity, but is still intractable due to high combined complexity.

We consider a two layer architecture for building target in- stances, inspired by the Church synthesis problem. We view the mapping as a specification of a document transformation, for which an implementation must be found. The static layer inputs a map- ping and synthesizes a single XML-to-XML query implementing a valid transformation. The data layer amounts to evaluating this query on a given source document, which can be done by a special- ized query engine, optimized to handle large documents.

We show that for a given mapping one can synthesize a query expressed in an XQuery-like language, which can be evaluated in time proportional to the evaluation time of the patterns used in the mapping. In general the involved constant is high, but it can be improved under additional assumptions. In terms of overall com- plexity, if the arity of patterns is considered constant, we obtain a fixed-parameter tractable procedure with respect to the mapping size, which improves previously known upper bounds.

Categories and Subject Descriptors

H.2.5 [Database Management]: Heterogeneous Databases—Data translation; I.7.2 [Document and Text Processing]: Document Preparation—XML

General Terms

Theory, Languages, Algorithms

Keywords

data exchange, building solutions, document transformations, queries returning trees

(c) 2014, Copyright is with the authors. Published in Proc. 17th Interna- tional Conference on Database Theory (ICDT), March 24-28, 2014, Athens, Greece: ISBN 978-3-89318066-1, on OpenProceedings.org. Distribution of this paper is permitted under the terms of the Creative Commons license CC-by-nc-nd 4.0.

1. INTRODUCTION

One of the challenges of data management is dealing with het- erogeneous data. A typical scenario is that of data exchange, in which the source instance of a database has to be restructured under the target schema according to certain rules. The rules are speci- fied in a declarative fashion, as source-to-target dependencies that express properties of the target instance, based on properties of the source instance.

Mapping between relational schemas are well understood (see recent surveys [3, 5, 6, 18]). Prototypes of tools for specifying and managing mappings have been developed and some have been in- corporated into commercial ETL (extract-transform-load) systems [14, 20, 23]. In the XML context, while commercial ETL tools often claim to provide support for XML schema mappings, this is typically done by means of dependencies that essentially establish connections between attributes in two schemas of a restricted form.

In research literature, a more expressive formalism of XML schema mappings was developed using tree patterns in order to specify complex transformations exploiting the tree structure of XML doc- uments [1, 4].

For such mappings, the problem of constructing a valid target instance for a given source instance is highly non-trivial due to the subtle interplay between the properties imposed by the dependen- cies and the structural constraints of the target schema. For a fixed mapping the target instance can be constructed in polynomial time, but in terms of combined complexity the problem isNEXPTIME- hard [8]. In this work we analyze the problem in the spirit of parametrized complexity: we cannot beat theNEXPTIMElower bound, but we can still hope for polynomial data complexity with the degree of the polynomial independent of the mapping. More- over, from the practical point of view it is desirable to separate the static part of the computation, dealing only with the mapping, from the data-dependent part. Ideally, the data stage should rely as much as possible on a specialized query engine, optimized to handle large data.

We consider a generic two-layer architecture for building tar- get instances. Inspired by the Church synthesis problem [10], and later work on schema mappings [17, 21], we view the mapping as a declarative specification of a document transformation, for which a working implementation must be synthesized. The static layer inputs a mapping and synthesizes an XML-to-XML query (in an XQuery-like language) implementing a valid transformation. The data layer amounts to evaluating the query on a given source doc- ument. The challenge is to synthesize a query whose data com- plexity does not exceed drastically the data complexity of queries involved in the dependencies.

(3)

Our contributions.

We show that given a mappingMone can synthesize an implementing queryqMthat can be evaluated on the source treeT in timeCM· |T|O(r), whereris the maximal num- ber of variables in the patterns used inM. That is, the complexity is fixed-parameter tractable wrt. the size of the mapping, ifris considered a fixed constant; we refer to the books of Downey and Fellows [13] or Flum and Grohe [15] for an introduction to the parametrized complexity. ConstantCMmay be large in general, but we identify a class of tractable mappings, whereCMis poly- nomial in the size ofMand minimal target documents.

Our approach relies on the idea of splitting the target schema into several templates, which are later filled with data values and multiple instances of generic small fragments of trees in such a way that all the dependencies are satisfied. The most costly part is choosing the constants to fill in the attributes in the fixed part of the template. The brute-force method of trying all possible values from the source tree has unacceptable data complexity. We give three different methods to solve this problem more efficiently:

• a branching algorithm that fixes the attributes iteratively us- ing tuples extracted from the source tree by source-side pat- terns, and backtracks in case of failure;

• a method exploiting the concept of kernelization, which amounts here to finding a small subset of tuples, sufficient to determine the attributes of the template;

• an algorithm that splits the source schema into templates and uses the fact that forabsolutely consistentmappings (admit- ting a valid target instance for each source instance) the at- tributes of the target template depend only on the attributes of the source template.

The three methods give similar complexity bounds, but the ideas behind them are very different. We believe that together they offer deeper understanding of the problem, as well as a broader spectrum of techniques to be used in solutions tailored for real-life scenarios.

Our algorithm for tractable mappings refines the brute-force solu- tion, using ideas similar to the ones behind the third approach.

Related work.

In the classical setting of relational data ex- change with mappings given by source-to-target tuple-generating dependencies, there is no reason for a two layer architecture since the mapping itself can be used to construct target solutions by means of the chase procedure. A two layer architecture has been considered for a different kind of mappings, describing two-way data flows between databases and applications [21]. These map- pings are compiled into Entity SQL views defining the application’s data model in terms of the database instance, andvice versa.

Most research on the synthesis of XML transformations fo- cuses on building complex transformations from existing ones by means of high level operations [6, 20]. Synthesizing transforma- tions from a declarative specification is considered in [17], but the setting allows only simple schemas in which elements contain sev- eral subelements and several collections of subelements of the same type. The dependencies are expressed in terms of child relation and element types. The solution amounts to producing small XML doc- uments which are then merged into a single document conforming to the schema; the focus is on performing the merge efficiently. In our approach there is no merging involved; the structural condi- tions of the schema are analyzed beforehand and reflected in the templates.

Organization.

After recalling the basic notions (Sect. 2) and in- troducing the transformation language (Sect. 3), we describe a sim- ple approach which essentially casts the solution building algorithm

from [8] in our two layer setting. Next we describe the branching algorithm (Sect. 5), the kernelization method (Sect. 6), and the al- gorithm for absolutely consistent mappings (Sect. 7). Finally, we discuss the tractable case (Sect. 8) and conclude with ideas for fu- ture work (Sect. 9). Missing arguments can be found in the full version of this article.

2. PRELIMINARIES

Data trees.

The abstraction of XML documents we use isdata trees: unranked labelled trees storing in each node adata value, i.e., an element of a countable infinite data domainD. For concreteness, we will assume thatDcontains the set of natural numbersN. For- mally, adata treeover a finite labelling alphabetΓis a structure T =hT,↓,↓+,→,→+,labT, ρTi, where

• the setT is an unranked tree domain, i.e., a prefix-closed subset ofNsuch thatn·i∈ T impliesn·j ∈ T for all j < i;

• the binary relations↓and→are the child relation (n↓n·i) and the next-sibling relation (n·i→n·(i+ 1));

• ↓+and→+are the transitive closures of↓and→;

• labT:T →Γis the labelling function;

• ρT:T →Dassigns data values to nodes. We say that a node s∈Tstores the valuedwhenρT(s) =d.

When the interpretations of ↓,→,labT, ρT are understood, we write justTinstead ofT. We use the terms “tree” and “data tree”

interchangeably.1We write|T|for the number of nodes ofT.

Forests and contexts.

Aforest is a sequence of trees. We writeF+Gfor the concatenation of forestsF,GandL+Mfor {F+G

F ∈L, G∈M}for sets of forestsL,M. IfL={F} we write simplyF+M.

AmulticontextCover an alphabetΓis a tree overΓ∪ {◦}such that◦-labelled nodes have at most one child. The nodes labelled with◦are calledports. Acontextis a multicontext with a single port, which is additionally required to be a leaf. A leaf portucan besubstitutedwith a forestF, which means that in the sequence of the children ofu’s parent,uis replaced by the roots ofF. An internal portucan be substituted with a contextC0with one port u0: first the subtree rooted atu’s only child is substituted atu0, then the obtained tree is substituted atu. Formally, the ports of a multicontext store data values just like ordinary nodes, but these data values play no role and we will leave them unspecified.

For a contextCand a forestFwe writeC·Fto denote the tree obtained by substituting the unique port ofCwithF. If we use a contextDinstead of the forestF, the result of the substitution is a context as well. Again, we extend the operation·to two sets of contexts in the natural way.

Schemas.

Adocument type definition(DTD) over a labelling al- phabetΓis a pairD=hrD, PDi, where

• rD∈Γis a distinguished root symbol;

• PDis a function assigning regular expressions overΓto the elements ofΓ, usually written asσ→e, ifPD(σ) =e.

1A different abstraction allows severalattributesin each node, each attribute storing a data value [1, 4]. Attributes can be modelled easily with additional children, without influencing the complexity of the problems we consider.

(4)

A data treeTconforms toa DTDD, if its root is labelled withrD

and for each nodes∈T the sequence of labels of children ofsis in the language ofPD(labT(s)). The set of data trees conforming toDis denotedL(D). Unless stated otherwise, we assumerDis a fixed labelr.

Aforest DTDis defined like a DTD, only instead of a single root symbol it has a regular expression. For a forest DTDD = he, PDi,L(D)is the set of forests of the formT1T2. . . Tpwhose sequence of root labelsσ1σ2. . . σpis a word in the language ofe andTi∈L(hσi, PDi).

Acontext DTDoverΓis a DTDDoverΓ∪ {◦}such that each tree overΓ∪ {◦}conforming toDhas exactly one node (a leaf) labelled with◦.

Patterns.

Patterns were originally invented as convenient syntax for conjunctive queries on trees [9, 16]. While XML schema map- pings literature mostly concentrates on tree-shaped patterns, defin- able in XPath-like syntax [1, 4], without disjunction the full ex- pressive power of conjunctive queries is only guaranteed by DAG- shaped patterns. Following [8] we base our mappings on DAG- shaped patterns.

A(pure) patternπoverΓcan be presented as π=hV, Ec, Ed, En, Ef,labπ, ξπi

wherehV, Ec∪Ed∪En∪Efiis a finite DAG whose edges are split into child edgesEc, descendant edgesEd, next sibling edgesEn, and following sibling edgesEf;labπis a partial function fromV toΓ;ξπis a partial function fromV to some set of variables. The range ofξπ, denotedRgξπ, is the set of variables used byπ; the arityofπis|Rgξπ|; andkπkis the size of the underlying DAG.

For a set∆of patterns,k∆kis the sum ofkπkforπ∈∆.

A data treeT =hT,↓,↓+,→,→+,labT, ρTisatisfiesa pat- tern π = hV, Ec, Ed, En, Ef,labπ, ξπi under a valuationθ : Rgξπ → D, denotedT |= πθ, if there exists a homomorphism fromπtoT i.e., a functionµ:V →T such that

• µ :hV, Ec, Ed, En, Efi → hT,↓,↓+,→,→+iis a homo- morphism of relational structures;

• labT(µ(v)) =labπ(v)for allv∈Domlabπ; and

• ρT(µ(u)) =θ(ξπ(u))for allu∈Domξπ.

We writeπ(¯x)to express thatRgξπ⊆x. For¯ π(¯x), instead ofπθ we usually writeπ(¯a), wherea¯= θ(¯x). We say thatT satisfies π, denotedT |= π, ifT |= πθfor someθ. Figure 1 shows an example of a pattern and a homomorphism.

Figure 1: Homomorphisms witness satisfaction (solid and dashed arrows are child and descendant relations).

Note that we use the usual non-injective semantics, where dif- ferent vertices of the pattern can be witnessed by the same tree

node, as opposed to injective semantics, where each vertex is mapped to a different tree node [11]. Under the adopted semantics patterns are closed under conjunction:π1∧π2can be expressed by the disjoint union ofπ1andπ2.

We enrich pure patterns with explicit equalities and inequalities between data variables, i.e., ifπ(¯x)is a pure pattern andη(¯x)is a conjunction of equalities and inequalities overx, then¯ π0(¯x) = (π, η)(¯x)is a (non-pure) pattern. We writeT |= π0(¯a)ifT |= π(¯a)andη(¯a)holds.

Schema mappings.

A schema mapping M = hDs,Dt,Σi consists of a source DTDDs, a target DTDDt, and a set Σof (source-to-target) dependencies that relate source and target in- stances. Dependencies are expressions of the form:

π(¯x) −→ π0(¯x,y)¯ ,

whereπ, π0are patterns and each variable inx¯is used in the pure pattern underlyingπ(the usual safety condition).

A pair of trees(T, T0)satisfies the dependency above if for all

¯

a,T |=π(¯a)impliesT0 |=π0(¯a,¯b)for some¯b. Given a source T ∈ L(Ds), a targetT0 ∈ L(Dt)is asolutionforT underMif (T, T0)satisfies each dependency inΣ. We letM(T)stand for the set of all solutions forT.

Figure 2: Dependencies are expressed with patterns.

EXAMPLE1. LetM=hDs,Dt,Σi, whereDsisr→c; c→ ab,Dtisr → (c|d)a; a→ b, andΣconsists of the single dependency in Fig. 2. UnderMeach source tree has a solution. On the other hand, if we replace the target DTD withr→(c|d)a; a→ b, only trees that store the same data value in alla-nodes have solutions.

3. TRANSFORMATION LANGUAGE

For the transformation language we choose a fragment of XQuery, extended with an additional construct for manipulating contexts. We use the following streamlined syntax:

q(¯x) ::= σ(xi) q0(¯x)

q0(¯x), q00(¯x)

first(q0(¯x))

e(¯x)

ρ(e(¯x))

ifb(¯x)thenq0(¯x)elseq00(¯x)

lety:=q0(¯x)returnq00(¯x, y)

foryinq0(¯x)whereb(¯x, y)returnq00(¯x, y) b(¯x) ::= q(¯x) =q0(¯x)

empty(q(¯x))

¬b0(¯x)

b0(¯x)∨b00(¯x)

b0(¯x)∧b00(¯x) e(¯x) ::= (xi

.) step [f]

step::= ↓ ↓+

↑ ↑+

→ →+

← ←+ f::= σ

e ¬f0

f0∨f00 f0∧f00

(5)

whereq’s are the queries,b’s are the Boolean tests, e’s are the CoreXPath expressions (starting in a nodexi or in the root). We adopt the standard XQuery semantics. The queries return se- quences of trees or values (or nodes, identified with subtrees), and variables can store all of these as well. The expression σ(xi)

q0(¯x)

returns the tree obtained by plugging the forest re- turned by q0 below a root node labelled withσ ∈ Γand stor- ing the data valuexi; q0(¯x), q00(¯x)returns the concatenation of the results of q0(¯x) and q00(¯x); first(q(¯x)) gives the first ele- ment of the sequence returned byq;ρ(e(¯x))returns the sequence of data values stored in the sequence of nodes returned bye(¯x);

lety := q0(¯x)returnq00(¯x, y)returns the sequence returned by q00(¯x, y)whereyis evaluated to the sequence returned byq0(¯x);

for yinq0(¯x)whereb(¯x, y)returnq00(¯x, y)returns the concate- nation of the sequences returned byq00(¯x, y) for all values ofy returned byq0(¯x)that satisfyb(¯x, y). In Sect. 6 and Sect. 7 we use additional standard features of XQuery; we explain them there.

Consider the mappingMdefined in Example 1. In order to implement it with a query, we need to assume that a function freshnull()returning a fresh null value at each call is available. An implementing query can be written as

r

letz:=freshnull()return c(z), forvin.↓[c]return

forxinρ(v↓[a])return

foryinρ(v↓[b])return a(x)[b(y)]

In queries implementing mappings patterns must be expressed as queries. For this, it is convenient to assume that queries can return tuples of data values, e.g., the source side pattern ofM(see Fig. 2) could be expressed with queryqsrc:

forvin.↓[c]return forxinρ(v↓[a])return

foryinρ(v↓[b])return(x, y) and the implementing queryqMcan be written as

r

letz:=freshnull()return c(z), for(x, y)inqsrcreturn a(x)[b(y)]

This can be simulated in XQuery by returning flat trees with as many children as the tuples have entries, and selecting the data val- ues from the children with path expressions.

Since each DAG pattern can be expressed as a disjunction of exponentially many tree patterns [16], each DAG pattern can be expressed as a query returning tuples of data values.

LEMMA1 ([16]). For each patternπ(¯x)there exists a query qπthat returns exactly those tuples¯afor whichπ(¯a)is satisfied in the tree. The query can be synthesized in time2poly(||π||)

and evaluated overTin time2poly(||π||)

· |T|rwhereris the number of variables in the pattern. Ifπis a tree-shaped pattern, the synthesis time ispoly(||π||)and the evaluation time ispoly(||π||)· |T|r.

Finally, in order to construct trees conforming to arbitrary re- cursive DTDs, we need a way to produce and concatenate contexts, not just forests. For instance, if the target DTD inMis changed tor→a;a→ab|dbthen the only way to obtain a solution is to go deeper and deeper in the tree, as shown in the right hand tree in Fig. 3. To enable this, we extend the transformation language with context expressions

Figure 3: Combining trees horizontally and vertically.

c(¯x) ::= ◦

σ(xi)[◦] c0(¯x)

c00(¯x)

q(¯x), c0(¯x), q0(¯x)

lety:=q0(¯x)returnCc0(¯x, y)

foryinq0(¯x)whereb(¯x, y)returnCc0(¯x, y) and replaceσ(xi)[q0(¯x)]in the productions forqas follows:

q(¯x) ::= . . .

c(¯x)[q0(¯x)]

. . .

The semantics of foryinq0(¯x)whereb(¯x, y)returnCc0(¯x, y)is a context obtained by combining all results ofc0(¯x, y)vertically, plugging one in another. Using this construct, the modified map- ping can be implemented with the query

r

for(x1, x2)inqsrcreturnC a(x1)[◦,b(x2)]

[qd] , whereqdislety:=freshnull()return d(y).

4. SIMPLE SOLUTION

In this section we show how the general solution building al- gorithm from [8] can be used to synthesize a query implementing a given mappingM = hDs,Dt,Σi, i.e., a queryqMsuch that qM(T) ∈ M(T)for each source tree T that admits a solution.

Building a solution forT amounts to producing a treeT0 |= Dt

that satisfies each pattern from

∆ = ψ(¯a,y)¯

ϕ(¯x)−→ψ(¯x,y)¯ ∈Σ, T |=ϕ(¯a) , which is an instance of the satisfiability problem for patterns. Sat- isfiability is well-known to beNP-complete, so this gives an algo- rithm exponential ink∆k, which can be as large as|T|r, wherer is the maximal arity of patterns inM. We are aiming at an algo- rithm polynomial in|T|r. We shall exploit the fact that patterns in

∆have size independent ofT.

The algorithm from [8] essentially works as follows:

1. for eachδ∈∆buildTδ∈L(Dt)such thatTδ|=δ, 2. combine theTδ’s intoT0∈L(Dt)such thatT0|= ∆.

Step (1) can be done in time independent fromTfor eachδ, but (2) is not obvious: how do we combine theTδ’s into a solution? While some parts ofDtmay be flexible enough to accommodate corre- sponding fragments from allTδ’s, some other parts require that all theTδ’s agree. For instance, according to the modified target DTD r →(c|d)a;a→bin Example 1, in each solutionT0the root, thea-node, and its sibling are unique, and if theTδ’s are to be com- bined, they need to agree on the data values stored in these nodes and on the label of thea-node’s sibling. On the other hand,T0can contain multipleb-nodes with different data values.

The idea of the algorithm is to split the target schema Dt

into so-calledkinds, in which the fixed and the flexible parts are

(6)

clearly identified, and try to findTδ’s consistent with a single kind.

The only requirement for the flexible parts is that they allow easy combination of smaller fragments. A natural condition would be closure under concatenation, but for complexity reasons we use weaker conditions that allow additional padding between the com- bined fragments.

DEFINITION1 (KIND). A kind K is a multicontext whose each portuis equipped with a languageLuof compatible forests or contexts that can be substituted atu. Ifuis a leaf, then one of the following holds:

(1) Luis a DTD-definable set of forests and for allF∈Lu, F+F0+Lu⊆Lu

for some forestF0; or

(2) Luis DTD-definable set of trees and for allT ∈Lu, C0(T, Lu)⊆Lu

for some multicontext C0 with two ports u1, u2, where C0(T, Lu)is the set of trees obtained by substitutingT at u1and someT0∈Luinu2.

Ifuis an internal node, then

(3) Luis a DTD-definable set of contexts and for allC∈Lu, C·C0·Lu⊆Lu

for some contextC0.

Depending on the type, we distinguish forest (1), tree (2) and con- text ports (3). We assume that the root ofKis not a forest port, i.e., a single forest port is not a kind.

We writeL(K)for the set of treesT obtained fromKby substitut- ing at each portua compatible forest, tree, or contextTuaccording to the type ofu. We call sequence(Tu)uawitnessing substitution forK. Awitnessing decompositionofT is a sequence of disjoint sets(Zu)uof nodes ofT such thatT restricted toZuis a copy of Tuand the context obtained by replacing each treeZuby a port is a copy ofK. We shall identifyTuandKwith their copies inT (thecomponentsof the decomposition) and speak of the witnessing decomposition(Tu)u.

As we have seen, the idea is to find, for each dependency δ∈ ∆, a target treeTδconsistent with a single kingK. The data values in the copy ofKhave to agree in allTδ’s, so they have to be determined in advance. By filling in the data values we obtain a data kind. We writeK(¯c)to denote the data kind obtained fromK by assigning¯cto the ordinary nodes ofK, assuming some implicit order on them. EachK(¯c)defines languageL(K(¯c))of data trees.

Figure 4 shows a data kindK(¯c)and some trees inL(K(¯c)).

Definition 1 ensures that sequences of compatible forests or contexts can be combined into one compatible forest or con- text: for compatible forests F1, F2, . . . , Fn there are forests I1, I2, . . . , In−1such thatF1+I1+F2+I2+. . .+Fnis compat- ible; for compatible treesS1, S2, . . . , Snthere are multicontexts I1, I2, . . . , In−1with two ports such thatI1(S1,◦)·I2(S2,◦)· . . .·In−1(Sn−1, Sn)is compatible, whereIj(Sj,◦)is a context obtained by substitutingSjat the first port ofIj; and for compat- ible contextsC1, C2, . . . , Cn there are contextsI1, I2, . . . , In−1

such thatC1·I1·C2·I2·. . .·Cnis compatible. This gives a natural way to combine trees fromL(K(¯c)): acombinationof T1, T2, . . . , Tn ∈ L(K(¯c))with decompositions(Tuj)uis a tree fromL(K(¯c))obtained by substituting at each portua compatible

K(¯c) Lu1=L(hb,{b→(b|◦)c;c→ε}i) Lu2=L(hc,{c→ε}i)

Figure 4: A data kindK(¯c)and three trees inL(K(¯c)).

forest or context combiningTu1, Tu2, . . . , Tun. In general there is no guarantee that a combination of theTδ’s satisfies eachδ, but we can ensure it by assuming thatδis matched inTδin a special way defined below.

DEFINITION2 (NEAT MATCHING). LetT ∈ L(K) and let (Tu)ube a witnessing decomposition ofT. A patternπis matched neatly inT (with respect to(Tu)u) if there exists aneat homo- morphismµ:π(¯a) →T, i.e., a homomorphism such that for all verticesx, yofπ

• ifEn(x, y)thenµ(x)andµ(y)are in the same component;

• ifEc(x, y)then eitherµ(x)andµ(y)are in the same com- ponent, orµ(x)is in the copy ofKinT andµ(y)is a root of a forest component;

• ifEf(x, y)then eitherµ(x)andµ(y)are in the same com- ponent, or each is a root of a forest component or a node in the copy ofKinT.

It is easy to see that neat matchings guarantee that each combi- nation of allTδ’s satisfies eachδ

LEMMA 2. IfT0 is a combination ofTδ ∈ L(K(¯c))with de- composition(Tuδ)uforδ ∈∆and eachδis matched neatly inT0 with respect to(Tuδ)u, thenT0|= ∆.

As we shall see later, it suffices to consider kinds for which neat matchings always exist. A kindKis atarget kindforMif L(K) ⊆L(Dt), and for each target-side patternπinMifπ(¯a) can be matched in a tree fromL(K(¯c)), then it can also be matched neatlyin some tree fromL(K(¯c)). For a target kind K, the two step algorithm discussed above computes a solution inL(K(¯c)), if there is one. The following lemma shows that one can synthesize a query that implements this algorithm. We write|K|for the number of nodes ofKandkKkfor the maximal size of DTDs inK.

LEMMA 3. For each mapping M and target kind K there is a query solK(¯z) such that for each tree T that ad- mits a solution in L(K(¯c)), solK(¯c)(T) is a solution for T.

The synthesis time forsolKis2poly(kKk,kMk)

· |K|O(p+r)and the evaluation time is2poly(kMk,kKk)· |K|r+1· |T|rwhererandpare the maximal arity and size of patterns inM.

The proof can be found in the full version . Here we give an example for a relatively generic mapping.

(7)

Figure 5: A generic mapping.

EXAMPLE2. LetMbe a mapping with source DTDDs:r→ a;a → b c;b → c, target DTDDt:r → a;a → b c;b → (b|d)c, and dependenciesπ1(¯x)−→π01(¯x),π2(¯x)−→π20(¯x, y) shown in Fig. 5. The kindK(¯c)with¯c=c1, c2, c3, c4, c5, shown in Fig. 4, is a target kind forM.

First we needTπ0

1a) ∈ L(K(¯c))for all¯a = a1, a2, a3 such thatπ1(¯a)holds in the source tree, and similarly forπ02. When we synthesize the query we have no access to the source tree; we pro- vide generic trees that depend only on the equality type of the en- tries of¯a. There are two essentially different ways to match neatly π01(¯a)in a tree fromK(¯c): match the vertex without label to one of theb-nodes outsideKand bothc-vertices to its onlyc-child (left tree in Fig. 4), or match the vertex without label to the uniquea- node and thec-vertices to some of itsc-children (middle tree in Fig. 4; nodes storing nulls⊥1,⊥2are required byLu1). The first matching allows arbitrarya1, buta2anda3 have to be equal, the second one allows arbitrarya2anda3, buta1has to be equal toc2. Forπ20(¯a)the only choice is where to match theb-nodes: inside or outside ofK. In a neat matching both have to be mapped outside ofK(right tree in Fig. 4; null value⊥realises the variabley).

The querysolK(¯z)computes tuples for whichπ1andπ2hold in the input tree and returns a combination of the appropriate instances of the generic trees. It generates fresh nullsy¯ = y1, y2, y3 and returnsK(¯c)with¯creplaced by¯zand portsu1,u2 replaced by a context expressionqu1(¯y)and a subqueryqu2:

lety1:=freshnull()return lety2:=freshnull()return

lety3:=freshnull()return r(z1)

a(z2) b(z3)

qu1(¯y)[d(z5)],c(z4) , qu2

. Inqu1(¯y) = q1u1[qu21(y1, y2)[qu31(y3)]], expressionqu11 combines substitutions at portu1coming from the first way of matchingπ01,

forx¯inqπ1wherex2=x3returnC b(x1)

◦,c(x2) , q2u1(y1, y2)combines those coming from the second way,

forx¯inqπ1wherex1=z2 returnC b(y1)

◦,c(y2) , andq3u1(y3)combines those coming from matchingπ20,

forx¯inqπ2returnC b(x1) b(x2)

◦,c(y3) ,c(y3)

. Note thatqu21(y1, y2) can be optimized to b(y1)

◦,c(y2) . In qu2 = q1u2, qu22

, subqueryq1u2combines substitutions at portu2

coming from the second way of matchingπ01,

for¯xinqπ1 wherex1=z2return c(x2),c(x3), andq1u2combines substitutions coming from matchingπ02,

forx¯inqπ2return c(x3).

Clearly, solK(¯c)(T)is a solution for T, unlessT |= π1(¯a)for some¯asuch that neithera1=c2nora2=a3. But thenT admits no solution inL(K(¯c))at all.

It remains to compute the data values¯cto be put in the ordinary nodes ofK. Tuple¯cdepends on the input treeT: in Example 2,¯c is good ifT |=π1(¯a)implies that eithera1 =c2ora2 =a3. A similar characterisation is always a by-product ofsolK(¯z).

LEMMA 4. LetMbe a mapping with dependenciesπi(¯xi)→ πi0(¯xi,y¯i)fori = 1,2, . . . , nand letKbe a target kind. There exist formulaeαi(¯xi,¯z)such that

• αi(¯xi,¯z)is a disjunction of at most|K|rrr conjunctions of O(|πi0|)equalities and inequalities amongx¯iandz, where¯ r is the maximal arity of patterns inM;

• for each¯c, each source treeTadmits a solution inL(K(¯c)) iffT |=πi(¯a)impliesαi(¯a,¯c)for alli.

Theαi’s can be computed fromsolKin polynomial time.

We shall call theαi’s thepotential expressionsforK. Note thatz¯ are common for allαi; we refer to them as theconstantsofK. In the symbols of Lemma 4 we can write the following simple query constK, computing a suitable valuation of the constants ofK, if it exists:

first forz¯invaluesz|where

empty forx¯1inqπ1where¬α1(¯x1,z)¯ returnx¯1

...

∧empty for¯xninqπnwhere¬αn(¯xn,z)¯ returnx¯n

return¯z

wherevaluesz|is a query that returns all possible tuples of length

|¯z|with entries from the set of data values used in the input tree or a fixed set of nulls of size|¯z|. The nulls are needed, since inequalities may enforce some constants to be different from any data value used in the source document.

The evaluation time ofconstK onT is proportional to|T||K|, which is highly impractical; in the following sections we shall op- timize it so that the evaluation time does not drastically exceed that ofsolK. For now, let us finish the construction of the implementing queryqM.

We say that K1,K2, . . . ,Kk cover a language L if L ⊆ Sk

i=1L(Ki). The following lemma shows that the target domain of any mapping can be covered with small target kinds. For a DTD D, thebranchingis the maximal size of regular expressions used inD, and theheightis the maximal number of different labels on a branch in any tree fromL(D).

LEMMA 5. For each mapping M there exist target kinds K1,K2, . . . ,Kk coveringL(Dt)such that|Ki| ≤ K, kKik ≤ kDtk, and the whole sequence of kinds can be computed in time 2K·poly(||M||)

; hereK = (2pb+b)2ph+h, wherebandhare the branching and height ofDt, andpis the maximal size of target side patterns inM.

IfK1,K2, . . . ,Kkare the target kinds guaranteed by Lemma 5, the queryqMcan be defined as:

if¬empty(constK1)then letz¯:=constK1returnsolK1(¯z)else ...

if¬empty(constKk)then letz¯:=constKkreturnsolKk(¯z).

(8)

Using the bounds of Lemmas 3–5, we have that the synthesis time forqM is 2K·poly(kMk)

and the evaluation time over T is 2K·poly(kMk)· |T|K+r.

5. OPTIMIZING VIA BRANCHING

In this section we show an optimization of the solution given in the previous section. The queryqMpresented there runs through all valuations of the constants of target kindKwith data values from the input document and nulls. This can be highly inefficient if Kis large: the resulting number of valuations can be much larger than the space of tuples considered in the dependencies. We present a simple branching strategy that avoids enumeration of all valua- tions.

Our algorithm executes some queries, whose number depends only onM, such that each query has linear data complexity and runs over the set of tuples selected by a single source-side pattern, instead of all valuations of the constants ofK. This gives running timef(|K|)· |T|r, rather thanO(|T|O(|K|)), for some functionf, whereTis the source tree andris the maximal arity of patterns in M. Thus, the presented solution isfixed-parameter tractablein the sense of Downey and Fellows [13], whenris treated as a constant andkMkis treated as a parameter (the solution in Sect. 4 is not fixed-parameter tractable). Rigorous bounds on functionfwill be still quite intractable (double exponential inkMk); in Sect. 8 we improve them under additional assumptions.

By Lemma 4, finding the constants of kindKamounts to solv- ing the following more general tuple covering problem: given potential expressions αi(¯xi,¯z) and sets Di ⊆ Dxi| for i = 1,2, . . . , n, find a tuple¯csuch that αi(¯a,c)¯ holds for all iand

¯

a ∈ Di, or assert that such¯cdoes not exist (Di plays the role of the set of tuples selected by patternπi(¯xi)).

LEMMA 6. The tuple covering problem for potential expres- sions α1(¯x1,¯z), . . . , αn(¯xn,z)¯ and sets D1, . . . , Dn can be solved by an algorithm executing at most

n·(1 + max

i=1,...,nki)O(|¯z|2)

linear queries over single sets Di, where ki is the number of clauses in expressionαi. Moreover, if expressionsαi use no in- equalities overz, the number of queries is bounded by¯

n·(1 + max

i=1,...,nki)2|¯z|. PROOF. Let αi(¯xi,z) =¯ Wki

j=1Pji(¯xi,z), where each clause¯ Pjiis a conjunction of equalities and inequalities. We implement a simple branching strategy. The algorithm maintains the following information: (i) a tuple¯c∈(D∪ {⊥})z|valuatingz, where¯ ci=

⊥means thatzihas not been assigned a value yet; (ii) a consistent setE of constraints enforced on variableszi that have not been valuated so far: these constraints may be of the fromzi=zj,zi6=

zj, orzi6=dford∈D. We assume that information propagates, e.g., ifc16=⊥andz1=z2is present inE, we havec2=c1.

A tuple¯a ∈ Diiscoveredby clausePji under(¯c,E), if the conjuncts ofPji(¯a,c)¯ satisfy the following conditions:

1. conjuncts of the formx`=x`0orx`6=x`0hold;

2. conjuncts of the formx`=z`0hold, i.e.,c`0 =a`∈D; 3. conjuncts of the formx` 6=z`0 hold, i.e.,z`0 is valuated to

something different froma`, or is not valuated yet;

4. conjuncts of formz` = z`0 orz` 6=z`0 hold ifz`, z`0 are valuated, and if not, they are implied byE.

Note that conjunctsx`6=z`0 do not impose any conditions on the future values of not yet valuatedz`0. Hence, some tuples may cease to be covered whenz`0finally gets its value.

The algorithm begins with empty partial valuation ¯c = (⊥, . . . ,⊥)andE = ∅, and refines them iteratively so that some uncovered tuple gets covered at each step. While there are uncov- ered tuples, pick one of them, say¯a ∈ Di, and branch into ki

subcases, choosing a clausePjito cover¯a. TryfixingPjiat¯aby extending(¯c,E)so that¯ais covered byPji: fix the values of all z`0 considered in condition 2, add toE all the equalities and in- equalities considered in condition 4, propagate information fromE and remove all the constraints referring to valuated variables only.

Note that fixingPjiata¯may be impossible due to inconsistency with(¯c,E). In that case, we discard the sub-branch. If noPjican be fixed at¯a, we discard the whole branch. When all tuples are covered, it remains to valuate the missingz`0 so that each tuple actually satisfies the covering clause. In particular, we need to sat- isfy all the constraints of the formx` 6=z`0 that were ignored so far. This is achieved by valuating all not yet valuated variablesz`0

to fresh nulls (respecting the equalities inE). The obtained¯cis a correct answer to the tuple covering problem.

To see that the algorithm is complete, assume that αi(¯a,c)¯ holds for all¯a ∈ Diand alli. Then, the branch where for each picked tuple¯a ∈Diwe fix a clausePjisuch thatPji(¯a,¯c)holds, is never discarded. Hence, it outputs a correct valuation (possibly different from¯c).

Finally, let us analyze the complexity. Observe that fixing clausePjiat a picked ¯athat is not covered so far results in one of the following: either (i) one of the constants ofz¯is assigned a value, or (ii) an equality is added to the setE, or (iii) an inequality is added to the setE. If expressionsαicontain no inequalities over

¯

z, then (iii) actually never happens. On a single branch of the algo- rithm, (i) happens at most|¯z|times, (ii) happens at most|¯z|times since equalities are propagated in a transitive manner, and (iii) hap- pens at most z|2

times. Hence, the depth of the branching tree is bounded by|¯z|+|¯z|+ |z|2¯

=O(|¯z|2), and by2|¯z|in case there are no inequalities overz¯in expressionsαi.

Since at each step the algorithm branches to at mostmaxni=1ki

subcases, the total size of the branching tree is at most (1 + maxni=1ki)O(|¯z|)2, or(1 + maxni=1ki)2|z|¯ if there are no in- equalities over¯z. In each node we executenlinear queries identi- fying uncovered tuples, one for eachαi. The bounds on the total number of queries follow.

This algorithm can be easily encoded in XQuery. The resulting query can be plugged in instead ofconstKin the queryqMfrom Section 4, withDireplaced by the results of queriesqπi. Moreover, if we assume that there are no inequalities involving variables intro- duced on the target side ofM, then the potential expressions given by Lemma 4 do not contain any inequalities between constants, and thus the algorithm of Lemma 6 uses less queries. Hence, by apply- ing the bounds of Lemma 4 we obtain the following (note here that logK=poly(kMk)).

THEOREM 1. For each mappingMone can compute in time 2K·poly(kMk)

an implementing query qMwhose evaluation time overT is

2K2·poly(kMk)· |T|r,

where K = (2pb+b)2ph+h, b and h are the branching and height of Dt, whilep and r are the maximal size and arity of patterns inM. Moreover, the evaluation time may be reduced to 2K·poly(kMk)

·|T|rin case when there are no inequalities involving variables introduced on the target side.

(9)

6. OPTIMIZING VIA KERNELIZATION

In this section we present yet another approach of optimizing the brute-force approach of Sect. 4, which can turn out to be more efficient than the one presented in Sect. 5. Unfortunately, our solu- tion does not cope with the full generality of mappings considered in the previous sections, as we have to exclude some inequality constraints.

Our idea is to shrink the set of interesting data values from the input document. We prove that one can find a small, that is of cardinality independent of the size of the input document, subset of data values, about which we can safely assume that constants in the kind can be valuated only to elements of this subset. The original motivation of our approach is the concept ofkernelization, a notion widely used in the parameterized complexity. Although our framework is not exactly compatible with the notion of kernel used there, the technique is very similar in principles. Again, we refer to the textbooks by Downey and Fellows [13] and by Flum and Grohe [15] for a more extensive introduction to kernelization;

a direct inspiration is the work of Langerman and Morin [19]. The crucial concept is the notion of akernel.

DEFINITION 3. Letα(¯x,z)¯ be a potential expression and let D⊆Dx|. We say thatD0⊆Dis akernel forDwith respect toα if for every¯c,∀¯a∈Dα(¯a,c)¯ ⇐⇒ ∀¯a∈D0α(¯a,¯c).

Intuitively, a kernel is therefore a small subset of tuples that can replace the whole database for the purpose of solving the tuple cov- ering problem. The following simple claim follows directly from the definition.

LEMMA 7. IfD0is a kernel forDw.r.t.αandD00is a kernel forD0wr.t.α, thenD00is a kernel forDw.r.t.α.

We now prove that if the potential expressions use no inequality, we can obtain a surprisingly small kernel. As we will later see, applying the brute-force method of Sect. 4 on this kernel gives an algorithm with comparable performance as the branching algorithm of Theorem 1.

THEOREM 2. Let α(¯x,¯z) be a potential expression with k clauses, using only equality, and letD ⊆ Dr, r = |¯x|. Then there exists a kernelD0 forDwith respect to αof size at most 2·(2k)r. Moreover, D0 can be found by an algorithm making O(kr(2k)r·log|D|)quadratic calls toD, deleting some tuples fromDuntilD0is obtained.

PROOF. We begin by reformulating the tuple covering problem in terms of linear algebra. By identifying data values with natural numbers we may treatDas a subset of ther-dimensional real space Rr. Recall that anaffinesubset ofRris a subset of the formΠ = ¯a∈Rr

A¯a= ¯b whereAis and×rreal matrix and¯b∈Rd; the dimension ofΠisr−dfor the minimaldsuch thatΠcan be presented this way. Assumeα(¯x,z) =¯ Wk

i=1Pi(¯x,z). Observe¯ that the set

Pi¯c=

¯ a∈Rr

Pi(¯a,c)¯

is affine for each¯candi; indeed, it is defined by a conjunction of linear equations. We say that a setS⊆Rrcoversa setS0∈Rrif S⊇S0. Thus we can restate the tuple covering problem as follows:

givenD⊆Rr, findc¯such thatS

i≤kPic¯coversD.

We are now ready to present the algorithm. Owing to Lemma 7, we can refine the kernel iteratively, starting fromD: as long as the current kernel is not small enough, we identify a subset that can

be removed to obtain a smaller kernel. The final size of the kernel is the minimal size for which we can still find points to remove.

In each iteration, the algorithm identifies a large subsetXof the current kernel, such that a constant fraction ofXcan be removed.

We claim that if

for alli, for all¯c, X⊆Pi¯c or |X∩Pi¯c|<|X| 2k (1) then any subsetY ofXwith at most|X|2 elements can be removed.

Indeed, assume thatD\Y is covered for somec. If¯ X ⊆Pi¯cfor somei, thenY is covered, and we are done. Assume this is not the case. Then, by (1), eachPi¯ccovers strictly less then |X|2k elements ofX. Hence,S

i≤kPi¯ccovers strictly less then|X|2 elements ofX.

This contradicts the fact thatS

i≤kPi¯ccoversX\Y (andD\Y).

We identify an appropriate setX by means of the following iterative procedure, which refines a candidate forX. We begin withX0 = D. In iterationj, we input candidateXjand test if satisfies property (1). If so, we returnX =Xj. If not, we find a new (smaller) candidateXj+1: since (1) does not hold, some affine subsetPi¯ccovers at least |X2kj|elements ofXj, but not all of them;

letXj+1=Xj∩Pi¯c.

We claim that after at mostriterations the procedure outputs someX of size at least (2k)|D|r. Note that|Xj+1| ≥ |X2kj| for allj.

The claim follows immediately from the fact thatXjis contained in an affine subset of dimensionr−j. To prove this fact, we pro- ceed by induction. The base casej = 0is trivial. AssumeXj

is contained in an affine subsetΠjof dimensionr−j. Note that Xj+1is the intersection ofXjand some affine subsetPi¯cthat does not containXj. Consequently,Πjis not contained inPic¯. Hence, the intersectionΠj∩Pic¯is an affine subset of dimension smaller than the dimension ofΠj, i.e., at mostr−(j+ 1).

To make sure that we can actually delete a nonempty set of pointsY, we need to assume that|X| > 2. This is guaranteed as long as |D| > 2(2k)r. How many times do we need to ap- ply the kernelization procedure to obtain a kernel of size at most 2(2k)r? After eachO((2k)r)iterations the cardinality of the set D is halved, which means that we need onlyO((2k)r·log|D|) iterations.

It remains to computeXwithO(rk)quadratic queries overD.

For a clausePiand a tuple¯a∈Dr, definePˆi¯aas Pˆia¯=¯b∈Rr

∃¯z Pi(¯b,¯z)∧Pi(¯a,z)¯ = [

¯ c: ¯a∈Pi¯c

Pi¯c.

It follows from the definition that affine subsetsPi¯c, Pid¯are either disjoint or equal for all¯c,d. Consequently,¯ Pˆi¯a = Pi¯cwhenever

¯

a∈Pi¯c. Hence, condition (1) is equivalent to:

for alli, for all¯a∈D, X⊆Pˆi¯aor|X∩Pˆi¯a|< |X| 2k (2) and we can usePˆia¯instead ofPi¯cin the search ofX. Crucially,Pˆi¯a can be defined by a quantifier free formula:∃¯z Pi(¯x,¯z)∧Pi(¯a,z)¯ is equivalent to the conjunctionCia¯(¯x)of all equalities overx¯and

¯

aentailed byPi(¯x,¯z)∧Pi(¯a,z). Consequently, set¯ Xj =D∩ Tj

`=0i¯a`

` can be represented by the conjunction Vj

`=0Ci¯a`

`(¯x).

Hence, using at most k quadratic queries over D, we can test whether condition (2) holds forXj, and if not, compute the rep- resentation ofXj+1. Since this is repeated at mostr times, the total number of queries isO(rk).

Theorem 2 can be used to show that also some inequality con- straints can be incorporated into the framework, at a cost of inflat-

Références

Documents relatifs

I consider three classes of values related to mobile PINC technologies: values necessarily implicated by the PINC approach, values implicated by particular

Finally, we define rNaVar to be r with all variable identifiers (identifiers with var signatures) eliminated as above. The Russell signature correctness rules

For such mappings and purely navigational queries based on RPQs and some extensions, query answering is decidable, with coNP data complexity [8,12]; to achieve tractability,

(The degree of the extension is 3, hence the group is cyclic of order 3, hence we just need to find one nontrivial automorphism to

Data generation allows us to both break the bottleneck of too few data sets (or data sets with a too narrow range of characteristics), and to understand how found patterns relate to

introduced another variant of ECM, called the Median Evidential c-means (MECM), which is an evidential counterpart to the median c-means and median fuzzy c-means algorithms. MECM can

• even taking into account the right to be forgotten as it is defined in the GDPR, the decision does not seem to be applying it, because under Article 17 of the GDPR the data

ICPSR). Institutions interested in understanding their output in terms of data thus face a challenging proposition: they need to be able to discover datasets across all