The present invention relates generally to data cleaning techniques, and more particularly, to methods and apparatus for detecting data inconsistencies.
Recent statistics reveals that “dirty” data costs businesses in the United States billions of dollars annually. It is also estimated that data cleaning, a labor-intensive and complex process, accounts fox 30%-80% of the development time in a typical data warehouse project. These statistics highlight the need for data-cleaning tools to automatically detect and effectively remove inconsistencies and errors in the data.
One of the most important questions in connection with data cleaning is how to model the consistency of the data, i.e., how to specify and determine whether the data is clean. This calls for appropriate application-specific integrity constraints to model the fundamental semantics of the data Commercially-available ETL (extraction, transformation, loading) tools typically have little built-in data cleaning capability, and a significant portion of the cleaning work has to still be done manually or by low-level programs that are difficult to write and maintain. A bulk of prior research has focused on the merge-purge problem for the elimination of approximate duplicates, or on detecting domain discrepancies and structural conflicts.
There has also been recent work on constraint repair that specifies the consistency of data in terms of constraints, and detects inconsistencies in the data as violations of the constraints. However, previous work on constraint repair is mostly based on traditional dependencies (e.g., functional and full dependencies), that were developed mainly for schema design, but are often insufficient to capture the semantics of the data.
A need exists for improved methods and apparatus for detecting data inconsistencies.
Generally, methods and apparatus are provided for detecting data inconsistencies. According to one aspect of the invention, a method is disclosed for determining whether a set of conditional functional dependencies are consistent. The conditional functional dependencies comprise one or more constraints that data in a database must satisfy including at least one pattern with data values. The method comprises the steps of obtaining a pattern tableau comprising a tableau tuple having a plurality of attributes including one or more finite domain attributes, wherein the one or mole finite domain attributes are instantiated with a value; applying one or more of the conditional functional dependencies in the set to the pattern tableau to instantiate an attribute of the tableau tuple with a constant; and determining that at least two conditional functional dependencies are inconsistent when an attribute is instantiated with two different constants. The method is generally repeated for possible values of the one or mole finite domain attributes in the tableau tuples and the applying step continues until no further changes are induced by the application of a conditional functional dependency to the pattern tableau.
According to another aspect of the invention, a method is disclosed for determining a minimal cover of a set of conditional functional dependencies. The method comprises the steps of determining whether the set of conditional functional dependencies is consistent; removing redundant attributes in the set of conditional functional dependencies; and removing redundant conditional functional dependencies from the set of conditional functional dependencies. The redundant attributes can be removed by of applying one or more chase rules based on a generalization of Armstrong's Axioms.
According to yet another aspect of the invention, a method is disclosed for detecting a violation of one or more conditional functional dependencies in a set of conditional functional dependencies. The method comprises the steps of representing the one or mole conditional functional dependencies in a pattern tableau; applying a first query to at least one of the conditional functional dependencies, wherein the first query detects one or more single-tuple violations, wherein a single-tuple violation comprises a tuple in the database that match a pattern tuple from the pattern tableau on a first set of attributes but does not match a second set of attributes due to a difference in one or more constant values; and applying a second query to at least one of the conditional functional dependencies, wherein the second query detects one or more multiple-tuple violations, wherein a multiple-tuple violation comprises at least two tuples in the database that agree on the first set of attributes and match a pattern tuple from a pattern tableau but the at least two tuples disagree on the second set of attributes. The first and second queries may be SQL queries.
A more complete understanding of the present invention, as well as further features and advantages of the present invention, will be obtained by reference to the following detailed description and drawings.
The present invention extends the notion of traditional functional dependencies (FDs), discussed below, to provide conditional functional dependencies (CFDs) that are capable of capturing the notion of “correct data.” According to one aspect of the invention, techniques are provided for analyzing the consistency of CFDs. An inference system is provided for the implication analysis of CFDs, which is analogous to Armstrong's Axioms for traditional FDs. Another aspect of the invention provides SQL techniques for detecting CFD violations.
Consider a relation schema cust(CC,AC,PN,NM,STR,CT,ZIP), that specifies a customer in terms of the customer's phone (country code (CC), area code (AC), phone number (PN)), name (NM), and address (street (STR), city (CT), zip code (ZIP)).
Traditional functional dependencies (FDs) on a cust relation may include:
ƒ1: [CC,AC,PN]→[STR,CT,ZIP]
ƒ2: [CC,AC]→[CT]
Recall the semantics of an FD: ƒ2 requires that customer records with the same country-code, area-code and phone number also have the same street, city and zip-code. Similarly, ƒ2 requires that two customer records with the same country- and area-codes also have the same city name. Traditional FDs are to hold on all the tuples in the relation. In contrast, the following constraint is supposed to hold only when the country code is 44. That is, for customers in the uk, ZIP determines STR:
φo: [CC=44,ZIP]→[STR]
In other words, φ0 is an FD that is to hold on the subset of tuples that satisfies the pattern “CC=44”, rather than on the entire cust relation. It is generally not considered an FD in the standard definition since φ0 includes a pattern with data values in its specification.
The following constraints are again not considered FDs:
φ1: [CC=01,AC,=908,PN]→[STR,CT=MH ZIP]
φ2: [CC=01,AC,=212,PN]→[STR,CT=NYC ZIP]
φ3: [CC=01,AC,=215]→[CT=PHI]
The first constraint φ1 assures that only in the US (country code 01) and for area code 908, if two tuples have the same PN, then they must have the same SIR and ZIP values and furthermore, the city must be MH. Similarly, φ2 assures that if the area code is 212 then the city must be NYC; and φ3 specifies that for all tuples in the US and with area code 215, their city must be PHI (irrespective of the values of the other attributes).
Observe that φ1 and φ2 refine the standard ƒ1 given above, while φ3 refines the FD ƒ2. This refinement essentially enforces a binding of semantically related data values. Note that while tuples t1 and t2 in
In this example, the constraints φ0, φ1, φ2 and φ3 capture a fundamental part of the semantics of the data. However, they cannot be expressed as standard FDs and are not considered in previous work on data cleaning. Constraints that hold conditionally may arise in a number of domains. For example, an employee's pay grade may determine his or her title in some parts of an organization but not in others; an individual's address may determine his or her tax late in some countries while in other's it may depend on his or her salary, etc. Further, dependencies that apply conditionally appear to be particularly needed when integrating data, since dependencies that hold only in a subset of sources will hold only conditionally in the integrated data.
In response to the practical need for such constraints, one aspect of the present invention provides an extension of traditional FDs, referred to herein as conditional functional dependencies (CFDs), that are capable of capturing the notion of “correct data” in these situations. A CFD extends an FD by incorporating a pattern tableau that enforce binding of semantically related values. Unlike its traditional counterpart, the CFD is required to hold only on tuples that satisfy a pattern in the pattern tableau, rather than on the entire relation. For example, all the constraints encountered so far can be expressed as CFDs. A formal framework for modeling CFDs is provided below.
Since CFDs are an extension of standard FDs, it is natural to ask whether or not CFDs can be reasoned about along the same lines as their FD counterpart. For example, does a set Σ of CFDs make sense, i.e., are the CFDs consistent (is there a nonempty database that satisfies Σ)? Is there an inference system, analogous to Armstrong's Axioms for FDs, to effectively determine whether or not a set of CFDs implies (entails) another CFDs? These are the classical consistency and implication problems typically associated with integrity constraints. These problems are not only fundamental to CFDs, but are also important for data cleaning Indeed, if an input set Σ of CFDs is found inconsistent, then there is no need to check (validate) the CFDs against the data at all. Further, it helps the user discover errors in CFD specification. When Σ is consistent, an effective implication analysis would allow finding a minimal cover Σmc of Σ that is equivalent to Σ but contains no redundant CFDs, patterns or attributes; it is typically more efficient to use Σmc instead of Σ when detecting and removing inconsistencies from the data.
According to another aspect of the present invention, techniques are provided for the consistency analysis of CFDs. The static analysis of CFDs introduces new challenges. Indeed, a set of CFDs may be inconsistent, i.e., there may not exist a nonempty database satisfying the CFDs, a problem not encountered when dealing with traditional FDs. The consistency problem for CFDs is NP-complete in general, but it is in PTIME when either the database schema is predefined or no attributes involved in the CFDs have a finite domain.
According to yet another aspect of the present invention, an inference system is provided for the implication analysis of CFDs, which is analogous to but is more involved than Armstrong's Axioms for FDs. Compared to standard FDs for which the implication problem is in linear-time, the implication analysis for CFDs is co NP-complete. A special case is identified when the implication problem is in PTIME. Based on these, a technique is provided for computing a minimal cover of a set of CFDs. These results are not only useful for data cleaning as an optimization technique by minimizing the input CFDs, but also yield a CFD theory analogous to the theory of FDs.
Yet another aspect of the present invention provides SQL techniques for detecting CFD violations. Since CFDs incorporate data values, they may in some cases be physically large, and straightforward techniques may lead to a very large number of detection queries. Techniques are disclosed for merging and efficiently checking a set of CFDs even with a very large number of conditions. These guarantee: (a) a single pair of SQL queries are generated, with a bounded size independent of the pattern tableaus in the CFDs, and (b) only two passes of the database are needed.
Furthermore, techniques are provided to incrementally detect CFD violations, as the underlying instance changes due to the insertions of deletions of tuples.
In this section, conditional functional dependencies (CFDs) are defined. Consider a relation schema R defined over a fixed set of attributes, denoted by attr(R).
Syntax. A CFD l on R is a pair (R:X→Y,Tp), where (1) X, Y are sets of attributes from attr(R), (2) R:X→Y is a standard FD, referred to as the FD embedded in l; and (3) Tp is a tableau with all attributes in X and Y, referred to as the pattern tableau of l, where each for each A in X or Y and each tuple tεTp,t[A] is either a constant ‘a’ in the domain dom(A) or A, or an unnamed variable ‘−’.
If A occurs in both X and Y, t└At┘ and t└tR┘ indicate the occurrence of A in X and Y, respectively, and the X and Y attributes are separated in a pattern tuple with ‘∥’. l is written as (X→Y,Tp) when R is clear from the context.
The constraints φ0, ƒ1, φ1, ƒ2, φ3 on the cust table given in Example 1.1 can be expressed as CFDs l1 (for φ0), l2 (for ƒ1, φ1 and φ2, one per line, respectively) and l3 for ƒ2, φ2 and an additional [CC=44, AC=141]→[CT=GLA] to be used below), as shown in
If both data and constraints in are represented a uniform tableau format, then at one end of the spectrum are relational tables which consist of data values without logic variables, and at the other end are traditional constraints which are defined in terms of logic variables but without data values, while CFDs are in the between.
Semantics. For a pattern tuple tc in Tp, an instantiation p is defined to be a mapping from tc to a data tuple with no variables, such that for each attribute A in X∪X, if tc[A] is ‘−’, p maps it to a constant in dom(A), and if tc[A] is a constant ‘a’, p maps it to the same value ‘a’. For example, for tc[A, B]=(a,−), one can define an instantiation p such that p(tc[A, B])=(a, b), which maps tc[A] to itself and tc[B] to a value b in dom(B).
A data tuple t is said to match a pattern tuple tc, denoted by t=tc, if there is an instantiation p such that p(tc)=t. For example, t[A, B]=(a, b)=(a, b)=tc[A, B] (a,−). It is noted that the “=” symbol should be replaced by the match symbol, as equality and match are different concepts, as would be apparent to a person of ordinary skill in the art.
A relation I of R satisfies the CFD l, denoted by I|=l, if for each pair of tuples t1, t2 in the relation I, and for each tuple tc in the pattern tableau tp of l, t1[X]=t2[X]=tc[X], then t1[Y]=t2[Y]=tc[Y]. That is, if t1[X] and t2[X] are equal and in addition, they both match the pattern tc[Y]. Moreover, if Σ is a set of CFDs, we write I|=l, Σ if |=l, for each CFD lεΣ.
The cust relation in
This example indicates that while violation of a standard FD requires two tuples, a single tuple may violate a CFD.
Two special cases of CFDs are worth mentioning. First, a standard FD X→Y can be expressed as a CFD (X→Y, Tp) in which Tp contains a single tuple consisting of ‘−’ only. For example, if we let T3 of l3 in
Any set of standard FDs can be specified, without worrying about consistency. This is no longer the case for CFDs, as illustrated by the example below.
Consider CFD ψ1=(R:[A]→[B],T1), where T1 consists of two pattern tuples (_∥b) and (_∥c). Then, no nonempty instance I of R can possibly satisfy ψ1. Indeed, for any tuple t in I, while the first pattern tuple says that t[B] must be b no matter what value t[A] has, the second pattern requires t[B] to be c.
Now assume that dom(A) is bool. Consider two CFDs ψ2=([A]→[B],T2) and ψ3=([B]→>[A],T3), where T2 has two patterns (true∥b1), (false∥b2), and T3 contains (b1∥false) and (b2∥true). While ψ2 and ψ3 can be separately satisfied by a nonempty instance, there exists no nonempty instance I such that I {ψ2,ψ3}. Indeed, for any tuple t in I, no matter what Boolean value t[A] has, ψ2 and ψ3 together force t[A] to take the other value from the finite domain bool. This indicates that attributes with a finite domain may complicate the consistency analysis. Indeed, suppose that dom(A) contains one extra constant, say maybe Then the instance I={(maybe, b3)}, for b3 different from both b1 and b2, clearly satisfies both ψ2 and ψ3.
A set Σ of CFDs on a schema R is said to be consistent if there exists a nonempty instance I of R such that I|=Σ. The consistency problem for CFDs is to determine, given a set Σ of CFDs defined on a relation schema R, whether Σ is consistent.
This is a nontrivial problem that was not encountered when dealing with standard FDs. Indeed, this problem is intractable if some attributes involved in the CFDs have a finite domain, which, as Example 3.1 shows, complicate the consistency analysis. The consistency problem for CFDs is NP-complete.
A stronger notion of consistency might be considered, as suggested by the following example. Consider a CFD ψ4=(R:[A]→[B],T4), where T4 consists of pattern tuples (aPb) and (aPc) and b≠c. There is obviously a nonempty instance I of R that satisfy ψ4. However, the conflict between the pattern tuples in ψ4 becomes evident if I contains a tuple t with t[A]=a. Indeed, the first pattern tuple forces t[B] to be b while the second pattern tuple requires t[B] to be c. In light of this, one might want to ensure that every CFD in Σ does not conflict with the rest of Σ no matter over what instances of R. This can be guaranteed by requiring for each CFD φ=(R:X→Y,tp)εΣ the existence of an instance Iφ Σ and moreover Iφ contains a tuple t such that t[X]=tp[X]. However, this stronger notion of consistency can be checked using the “classical” notion of consistency as follows. Suppose it is desired to check the strong consistency of Σ. Let φ=(X→A,tp)εΣ and let Xc⊃X be the set of attributes for which tp[Xc] consists of constants only. Then, for each φ=(X→A,tp)εΣ, the consistency of Σ∪{([C]→[C],(_∥tp[C]))|CεXc} is checked. If all these sets are consistent, then Σ is strongly consistent, otherwise it is not. For example, for Σ={ψ4} it is sufficient to check the consistency of Σ∪{([A]→[A],(_∥a))} to identify that Σ is not strongly consistent. From the above it follows that checking strong consistency is also NP-complete. Moreover, the consistency checking algorithm presented below can be easily modified to test strong consistency.
A Consistency Checking Algorithm
For data cleaning in practice, the relational schema is often fixed, and only CFDs vary and are treated as the input.
To simplify the discussion, CFDs of the form (R:X→A,Tp) are considered, where A is a single attribute and Tp consists of a single pattern tuple tp, written as (R:X→A,tp). This does not lose generality since a CFD of the general form φ=(R:X→Y,Tp) is equivalent to a set Σφ of CFDs of the form above such that for each AεY and tpεTp, (R:X→A,tp[X∥A]) is in Σφ. That is, for any instance I of R, I Σφ if and only if I φ. Note that each pattern tp indicates a CFD. For a set Σ of CFDs of this form, card(Σ) is the number of CFDs in Σ, which is the same as the number of pattern tuples in Σ.
Observe that inconsistencies can only be caused by the presence of CFDs that have a constant in their right hand side. Indeed, let Σ be a set of CFDs and denote by Σc the set of CFDs φ=(R:X→A,tp) in Σ such that tp[A]=a for some constant ‘a’ in dom(A). It is now verified that Σ is consistent iff Σc is consistent. Clearly, the consistency of Σ implies the consistency of Σc. For the other direction, let I be an instance such that I Σc. {t} Σc for any tuple tεI. Let ψ=(R:Y→B, sp)εΣ such that tp[B]‘_’. Note that such CFDs are trivially satisfied on single-tuple instances and therefore {t} Σz∪{ψ} for any such ψεΣ. As a result, {t} Σ and therefore can restrict to CFDs in Σx for checking the consistency of a set of CFDs Σ.
Without loss of generality, it is assumed that Σ=Σc. Denote by var an infinite set of (named) variables. Consider a “tuple tableau”
For each ρεVfinattr(R), the algorithm Consistency repeatedly applies all CFDs in Σ to ρ(
The Chase Procedure
Let t be a tuple tableau over the attributes in attr(R) that consists of constants in the respective domains of the attributes and variables in vat.
For each φεΣ, the operation FD(φ) is defined that transforms t into a (new) tuple tableau t′. Assume that φ=(X→A,tp) and recall that tp[A]=a for some constant a in dom(A). Let X1=X\finattr(R) and X2=X∩finattr(R). Consider the following cases:
(i) If X1≠Ø and there exists an attribute BεX1 such that tp[B]=b for some constant b, then let t′=t. Intuitively, since B is an attribute that has an infinite domain, t[B] can be set to be a constant that is different from ‘b’. In this way, the left hand side of φ is not satisfied and thus φ does not impose any constraint on t.
(ii) Otherwise, i.e., either X1=Ø for all attributes BεXt, tp[B]=‘_’, distinguish between two cases: (a) If X2=Ø, then FD (φ) instantiates t[A] with ‘a’. Let t′ be the result of this change. However, in case that t[A] is already given a constant different from a, then a conflict arises and t′ is undefined (b) If X2≠Ø, then t′=t if t[X2]{circle around (¢)}tp[X2]. Indeed, in this case the left hand side of φ will never be satisfied and φ does not cause any additional constraints on t. However, if t[X2]=tp[X2], then FD (φ) instantiates [A] with ‘a’. Let t′ be the result of this change. However, in case that t[A] is already a constant different from ‘a’, then a conflict arises and t′ is undefined.
As a result, the application of FD(φ) on a tuple tableau t either results in a change of a variable into a constant, no change at all, or is undefined.
A chase of t is a sequence of tuple tableaus to t0, t1, . . . , tn such that t0=t, t1≠ti+1, and such that ti+1 is the result of applying FD(φ) for some φεΣ on ti. A successful chase of t is a chase t0, t1, . . . , tn of t such that for any φεΣ, FD(φ)(tn)=tn; that is, no fluffier changes can be induced.
Given a set Σ of CFDs as input, Algorithm Consistency checks the consistency of Σ as follows. For each possible valuation of the finite domain attributes, i.e., ρεVfinattr(R), we first initialize t=ρ(
Given any set Σ of CFDs on a relation schema R, the consistency of Σ can be determined in O(|Σ|2) time, if either the schema R is predefined, or no attributes in Σ have a finite domain.
Correctness
Suppose that Consistency(Σ) returns true. Let ρεVfinattr(R) be the valuation for which this happens. Moreover, let t′ be the result of the chase on ρ(
If Σ is consistent, then Consistency(Σ) evaluates to true. Let I be a nonempty instance such that I Σ. Without loss of generality assume that I consists of a single tuple t. Let ρεVfinattr(R) be the valuation such that ρ(
Complexity Analysis
Algorithm Consistency basically consists of a nested loop: the outer loop over the set of valuations in Vfinattr(R), and the inner loop over the CFDs in Σ. Moreover, in each iteration, it applies a single FD rule to a single tuple tableau. Let from be the largest finite domain. Since |Vfinattr(R)|=O(|fdom||finattr(R)|), the application of an FD rule takes O(|attr(R)|) time, and the inner loop is executed at most |Σ|2 times in total, the overall time complexity is O(|fdom||finattr(R)||Σ|2|attr(R)|), where |fdom| is a constant. Observe that in case that all attributes have an infinite domain, the time complexity reduces to O(|Σ|2|attr(R)|). Indeed, this follows from the fact that in this case, Vfinattr(R) only consists of the identity valuation and the outer loop will be executed only once. Note that if the schema R is predefined, the set Vfinattr(R) is a constant. In this case, the algorithm also takes O(|Σ|2) time.
In this section, the implication problem for CFDs is considered. The implication problem for CFDs is to determine, given a set Σ of CFDs and a single CFD φ on a relation schema R, whether or not Σ entails φ, denoted by Σ φ, i.e., whether or not for all instances I of R, if I Σ then I φ.
Two sets Σ1 and Σ2 of CFDs are equivalent, denoted by Σ1≡Σ2, if for any instance I, I Σ1 if and only if I Σ2.
It can be shown that the richer semantics of CFDs complicates the implication analysis: as opposed to standard FDs, the implication problem for CFDs is co NP-complete in general. An inference system is provided for the implication analysis of CFDs, as a nontrivial extension of Armstrong's Axioms for FDs. Based on these, an algorithm is presented for computing a minimal cover of a set of CFDs.
An Inference System for Conditional Functional Dependencies
Armstrong's Axioms for FDs are found in almost every database textbook, and are fundamental to the implication analysis of FDs. Analogous to Armstrong's Axioms, an inference system is provided for CFDs, denoted by I, in
While the rules FD1, FD2 and FD3 in I are extensions of Armstrong's Axioms for FDs, FD4 and FD5 do not find a counterpart in Armstrong's Axioms. Below the inference rules in I are illustrated.
FD1 and FD2 extend Armstrong's Axioms reflexivity and augmentation, respectively. A subtle issue in FD2 arises when B=A, when B appears in both the left hand side and tight hand side of the embedded FD [X, B]→A. If so, tp[BI]=‘_’ is used instead of tp[B]=‘_’ to refer to the B attribute in [X, B] (recall that in a tuple tp, the occurrences of B in the left hand side and right hand side can be distinguished by using tp[BL] and tp[BR], respectively).
FD3 extends transitivity of Armstrong's Axioms. To cope with pattern tuples that are not found in FDs, it employs an order relation , defined as follows. For a pair η1,η2 of constants or ‘_’, η1η2 if either η1=η2=a where a is a constant, or η2=‘_’. The relation is naturally extended to pattern tuples. For instance, (a,b)(_,b). Intuitively, the use of in FD3 assures that (t1[A1], . . . , tk[Ak]) is in the “scope” of tp[A1, . . . , Ak], i.e., the pattern tp[A1, . . . , Ak] is applicable. In Example 4.1, FD3 can be applied because t1[B]=bt2[B]=_, where t1, t2 are the pattern tuples in ψ1,ψ2, respectively.
FD4 indicates that for a CF φ=([B, X]→A,tp), if tp[B]=‘_’ and tp[A] is a constant ‘a’, then it can be simplified by dropping the B attribute from the left hand side of the embedded FD. To see this, consider a relation I and any tuple t in I. Note that since tp[B]=‘_’, if t[X]=tp[X] then t[B,X]=tp[B,X] and t[A] has to be ‘a’ regardless of what value t[B] has. Thus, φ entails (X→A,tp).
FD5 says that for an attribute B of a finite domain and with respect to a given set Σ of CFDs, if Σ implies ([X,B]->A,ti) when ti[B] ranges over all b in dom(B) such that (Σ,B=b) is consistent, then ti[B] can be “upgraded” to ‘_’. That is, for any instance I, if I satisfies Σ, then I also satisfies ([X,B]->A,tp), where tp[B]=‘_’. This is because for all sensible values of dom(B) that ‘_’ in tp[B] may take, I satisfies ([X,B]->A,ti).
The inference system I is believed to be sound and complete for implication of CFDs.
It has been found that due to the richer semantics of CFDs, I is more complicated than Armstrong's Axioms. It is thus not surprising that the implication analysis of CFDs is mole intriguing than their standard FD counterpart. Indeed, the implication problem for CFDs is coNP-complete.
When the relation schema is predefined as commonly found in data cleaning applications, the implication analysis of CFDs can be conducted efficiently, as stated by the next result.
Given a set Σ of CFDs and a single CF φ defined on a schema R, whether or not Σφ can be decided in O((|Σ|+|φ|)2) time, if either the schema R is predefined, or no attributes in Σ have a finite domain.
Computing Minimal Covers of CFDs
As an application of consistency and implication analyses of CFDs, an algorithm is presented for computing a minimal cover Σmc of a set Σ of CFDs. The cover Σmc is equivalent to Σ but does not contain redundancies, and thus is often smaller than Σ. Since the costs of checking and repairing CFDs are dominated by the size of the CFDs to be checked along with the size of the relational data, a non-redundant and smaller Σmc typically leads to less validating and repairing costs. Thus finding a minimal cover of input CFDs serves as an optimization strategy for data cleaning.
A minimal cover Σmc of a set Σ of CFDs is a set of CFDs such that (1) each CFD in Σmc is of the form (R:X→A,tp) as mentioned above, (2) Σmc≡Σ, (3) no proper subset of Σmc implies Σmc, and (4) for each φ=(R:X→A,tp) in Σmc, there exists no φ=(R:X′→A,tp[X′∪A]) in Σmc such that X⊂X′. Intuitively, Σmc contains no redundant CFDs, attributes or patterns.
Let Σ consist of ψ1,ψ2 and φ given in Example 4.1. A minimal cover Σmc of Σ consists of ψ1′=(Ø→B,(b)) and ψ2′=(Ø→C,(c)). This is because (1) {ψ1,ψ2} φ ((Example 4.1), (2) ψ1 can be simplified to ψ1′ by removing the redundant attribute A (by the rule FD4 in I), and (3) similarly, ψ2 can be simplified to ψ2′.
A first step for data cleaning is the efficient detection of constraint violations in the data. In this section, techniques are provided to detect violations of CFDs. Given an instance I of a relation schema R and a set Σ of CFDs on R, it is to find all the violating tuples in I, i.e., the tuples that (perhaps together with other tuples in I) violate some CFD in Σ. An SQL technique is provided for finding violations of a single CFD, and then the initial SQL technique is generalized to validate multiple CFDs. Finally, an incremental technique is provided for validating CFDs. It is desirable to use just SQL to find violations: this makes detection feasible in any standard relational DBMS without requiring any additional functionality on its behalf.
Checking a Single CFD with SQL
Consider a CFD φ=(X→A,Tp). For simplicity, it is assumed that the right-hand side of a CFD consists of a single attribute only. The disclosed solutions can be trivially extended to multiple attributes, as it is illustrated in the various examples (where this assumption is not present). Given the CFD φ, the SQL queries in
Intuitively, detection is a two-step process, each conducted by a query. Initially, query QφC detects single-tuple violations, i.e., the tuples t in I that match some pattern tuple tpεTp on the X attributes, but t does not match tp in A since the constant value tp[A] is different from t[A]. That is, QφC finds violating tuples based on differences in the constants in the tuples and Tp patterns.
On the other hand, query QφV finds multi-tuple violations, i.e., tuples t in I for which there exists a tuple t′ in I such that t[X]=t′[X] and moreover, both t and t′ match a pattern tp on the X attributes, value tp[A] is a variable, but t[A]≠t′[A] Query QφV uses the group by clause to group tuples with the same value on X and it counts the number of distinct instantiations in tp[A]. If there is more than one instantiation, then there is a violation. Note that QφV returns only the X attributes of violating tuples. This has the advantage that the output is more concise than if the complete tuples are returned. Moreover, the complete tuples can be easily obtained using an additional SQL query.
Recall CFD φ2 given in
A salient feature of the disclosed SQL translation is that tableau Tp is treated an ordinary data table. Therefore, each query is bounded by the size of the embedded fd X→A in the CFD, and is independent of the size (and contents) of the (possibly large) tableau Tp.
Validating Multiple CFDs
A naive way to validate a set Σ of CFDs is to use one query pair for each CFD φ in Σ. This approach requires 2×|Σ| passes of the underlying relation. An alternative approach is presented that only requires two passes. The key idea is to generate a single query pair to check all the constrains in Σ. The proposed solution works in two phases. In its first phase, the algorithm performs a lineal scan of all the pattern tableaus belonging to CFDs in Σ and merges them, generating a single tableau called TΣ. Intuitively, tableau TΣ is such that it captures the constraints expressed by all the tableaus of the CFDs in Σ. Then, in its second phase, the algorithm generates a query pair that finds tuples violating CFDs in Σ.
Merging Multiple CFDs
Consider a set Σ which, without loss of generality, contains just two CFDs φ and φ′ on R, where φ=(X→A,T) and φ′=(X′→A′,T′). For now, assume that neither A nor A′ belong to X∪X′. This assumption is removed later. There are two main challenges for the generation of the merged tableau TΣ. The first challenge is that tableaus T and T′ may not be union-compatible, i.e., X≠X′ or A≠A′. Thus, tableau T (resp. T′) needs to be extended with all the attributes in (X∪A)−(X′∪A′) (resp. (X′∪A′)−(X∪A) for T′). For each attribute B in (X∪A)−(X′∪A′) and each tuple tp in the original tableau T, the value of tp[B] is set to be a special symbol denoted by ‘@’, which denotes intuitively a “don't care” value. After this extension, the resulted tableaus are union-compatible. Then, tableau TΣ is defined to be their union
Given the presence of ‘@’ CFD satisfaction needs to be reformulated. Let Z=X∪X′ and W=A∪A′. Consider a tuple tp[Z,W] in tableau TΣ which includes ‘@’. Use Zt
For the second challenge, consider the detection of violations of a single CFD using SQL. Note that while writing the SQL queries, it assumes implicit knowledge of whether an attribute is part of the left-hand or right-hand side of the CFD. Now, consider two simple CFDs on R, namely, φ=(A→B,T) and φ′=(B→A,T′). Suppose that the tableaus of the CFDs are union-compatible. One might want to take the union of these two tableaus to generate TΣ. How violations of tableau TΣ be detected using SQL? Note that the method given in the previous section cannot be directly used Attribute A is in the left-hand side, for tuples coming from φ, while it is part of the tight-hand side, for tuples coming from φ′. Thus, it seems that the two sets of tuples must be distinguished and each set treated separately, something that counters the benefits of CFD merging.
This is addressed by splitting the tableau T of each CFD φ=(R:X→A, T) into two parts, namely, TX and TA, one tableau for the X and one for A attributes of φ. Then, tableau TΣZ (and similarly TΣW) is generated by making all the TX tableaus in Σ union-compatible (similarly fox the TA tableau). Note that an attribute can appear in both TΣZ and TΣW. To be able to restore pattern tuples from TΣZ and TΣW, a distinct tuple id tp[id] is created for each pattern tuple tp, and associate it with the corresponding tuples in TΣZ and TΣW. For example, consider CFD φ3 shown in
It has been found the CFD merging is mainly beneficial for highly-related CFDs. The conversion to DNF is not an option when handling where clauses in CNF, because each disjunct in CNF consists of three terms, and thus the translation of CNF to DNF results in a where cluser with 3k conjuncts, where k is the number of attributes in the CFD. In practice, this is much worse then the 2k increase that results from translating the queries QφC and QφV into DNF.
Query Generation
During the second phase, a single pair of SQL queries are generated for TΣ. This query generation, however, introduces new challenges. Recall that query QφV, for some CFD φ=(R:X→A, T), requires a group by clause over all the X attributes. Now, consider tableau TΣZ in
Consider the merged tableaus TΣZ and TΣW from a set Σ of CFDs over a relation schema R and let I be an instance of R. Then, the two SQL queries in
Note that query QΣC is similar in spirit to the SQL query that checks for violations of constants between the relation and the tableau, for a single CFD. The only difference is that now the query has to account for the presence of the ‘@’ symbol in the tableau. Now, consider the relation Macro which is of the same sort as TΣZ and TΣW (attributes are renamed that appear in both tableaus so as not to appear twice). Relation Macro is essentially the join on Z of relation I with the result of the join on tuple id tp[id] of the two tableaus. The value of each attribute, for each tuple tM in Macro, is determined by the case clause. In more detail, for each attribute BεZ, tM[B] is set to be ‘@’ if tp2[B] is ‘@’, and is t[B] otherwise; similarly for each attribute CεW and tM[C]. Note that relation I is not joined on W with the tableaus. Thus, if for some tuple t with t[Z]©tpZ[Z], there exists an attribute C with tpW[C] a constant and t[C]≠tpW[C] (i.e., t is violating the merged tableau) then tM[C] is set to be [C]. This creates no problems to the process since this violating tuple is already detected by QΣC.
Intuitively, Macro considers each tuple in the tableau, and uses it as a mask over the tuples of the relation. If the tableau tuple indicates a don't care value for all attribute, all the (possibly different) attribute values in the relation tuples are masked and replaced by an ‘@ ’ in Macro.
In this way, a single pair of SQL queries are generated to validate a set Σ of CFDs, while guaranteeing that the queries are bounded by the size of the embedded. FDs in Σ, independent of the size of the tableaus in Σ. Furthermore, to validate Σ only two passes of the database is required.
Incremental CFD Detection
Consider an instance I of a relation schema R. For simplicity, consider a single CFD φ=(X→A, Tp) (the incremental technique presented below can be extended to deal with multiple CFDs). Given the methodology presented thus far, violations of φ can be checked by issuing the pair of queries QφC and QφV over I. An interesting question is then what happens if the instance I changes? As tuples are inserted or deleted from I, resulting in a new instance Inew, a naive solution would be a batch approach that re-issues queries QφC and QφV over Inew, starting from scratch in response to updates, something that requires two passes of the underlying instance each time the queries are re-issued.
Intuitively, however, one expects that a tuple insertion leaves a large portion of instance I unaffected when CFD violations are concerned. An inserted tuple t might introduce new violations, but only with tuples that are already in the instance and which match t in the X attributes. Therefore, it makes sense to only access these tuples and only detect the possible newly introduced violations due to the inserted tuple. Thus, incremental detection can potentially save a large number of disk accesses, since instead of performing two passes of the underlying data on each tuple insertion (naive method), only the tuples that match the inserted tuple t in the X attributes need to be accessed. Similarly, in the case of deletion, by deleting a tuple t, some of the violations in I that the deleted tuple was causing might be inadvertently repaired (again with tuples matching t in the X attributes). Therefore, it makes sense to only detect which of the existing violations concerning the deleted tuple are affected. The following example better illustrates the above.
Recall from Example 5.1 that tuples t1 to t4 in
Now, consider again the instance in
A method is presented to incrementally detect CFD violations, given a set of insertions and deletions to an instance I. Although the incremental method has the same worst-case performance as the naive method (two passes of the underlying instance), its expected performance is that only a small number of tuples are accessed, which will be verified in the next section by out experiments.
Logging of Violations
The incremental detection requires extension of the schema R of an instance relation I to record which tuples violate which CFDs in a given set Σ. In more detail, for each CFD φεΣ two Boolean attributes βφC and βφV are added to the schema of R. Rlog denotes the new schema. For each tuple tεI, a tuple t′ is created in Rlog such that t′[attr(R)]=t[attr(R)]. Furthermore, in attribute t′[βφC] (resp t′[βφV]) it is recorded whether or not the corresponding tuple t violates CFD φ due to QφC (resp, QφV). Note that the logging mechanism imposes minimum overhead, in terms of space, since for each tuple and each CFD only two additional bits are required.
It is assumed that, initially, queries QφC and QφV are executed and the result of the two queries is used to initialize the values of attributes βφC and βφV, through a simple. SQL update statement of the form for βφC (similarly for βφV) as shown in
One needs only to select all those tuples with both βφC and βφV equal to false, for each φεΣ, and then project on attr(R), in order to retrieve from Rlog the tuples that do not violate any of the CFDs.
Handling Tuple Deletions
SQL statements are used to detect violations, in an incremental fashion. Consider a CFD φ=(X→A, Tp) and an instance Ilog whose schema Rlog includes attributes βφC and βφV. In response to deletion of tuple t from Ilog, the incremental detection of violations has two steps.
In more detail, the SQL query in the first step simply deletes from Rlog the tuple corresponding to t. The second step checks for tuples that (a) violate φ (t′[βφV]=1), (b) have the same values on the X attributes with t, and (c) all these identified tuples have the same A attribute value. It is easy to see that if a set of tuples satisfies the above three conditions, then each of the tuples in the set violated φ only due to t. Since t is deleted, each of the tuples now satisfies φ. Therefore, t′[βφV] is set to false. Note that a tuple deletion only affects violations that are caused by the presence of ‘_’ in the tableau, hence the focus is only on the βφV attribute. Also note that the above procedure need not access the pattern tableau Tp of φ, resulting in additional savings in terms of execution time.
Consider the instance in
An interesting question is what happens for batch deletion, i.e., delete a set of tuples. Obviously, the above two steps could be executed once for each tuple in the set. It suffices to execute the above steps once for each distinct value of X attributes that is deleted. So, if, for example, both tuples t3 and t4 are deleted from the instance in
Handling Tuple Insertions
To insert a tuple t into Ilog. then, the incremental detection of violations has three steps, as shown in
Consider batch insertions involving a set of tuples, say ΔIlog. Obviously, one might consider executing the above steps once for each tuple in ΔIlog. An alternative strategy is to treat ΔIlog as an independent instance whose tuples must be merged with the ones in Ilog. Consider the five different steps shown in
The second step looks for tuples in Rlog that were clean before the insertion of tuples in ΔRlog but will now violate φ, once the tuples in ΔRlog are inserted. The tuples in Rlog that are affected by the insertion are such that they have the same values on the X attributes with some tuple in ΔRlog but their values differ on the A attribute.
The third step attempts to leverage the knowledge of violations in Rlog in order to detect violations in ΔRlog. In more detail, if a tuple t′ in ΔRlog has the same values on the X attributes with some tuple t″ in Rlog whose βφV is true, then t′ must also have βφV set to true. This is because for the tuples in Rlog with specific values on the X attributes it is known whether or not more than one values on the A attribute exist.
Finally, there is only one more case to consider, namely, whether there are any clean tuples in ΔRlog (with both βφC and βφV equal to false) that together with some other clean tuples in ΔRlog violate φ. The last step detects such tuples by checking whether any tuples have the same values on the X attributes but different values on the A attribute. For all the detected tuples, the value of βφV is set to true.
In last step, the tuples in ΔRlog are inserted into Rlog.
Consider the instance in
To clean data, an effective method should be in place for removing inconsistencies from the date, in addition to inconsistency detection. That is, if a data base I of a relation schema R violates a set Σ of CFDs on R, a minimal repair I′ of I should be found such that I′|=Σ and I′ minimally differs from the original database I, obtained by performing repair operations on I. Attribute-value modifications are allowed as repair operations.
Repairing CFDs is nontrivial. Indeed, consider the CFD repairing problem, which is to determine, given I, Σ and a positive integer k, whether or not there exists an instance I′ of R such that (1) I′|=Σ and (2) I′ is obtained from J by at most k repair operations. This problem is intractable. The repairing problem is NP-complete.
Repairing CFDs introduces challenges not encountered when repairing standard FDs. For example, it is known that if a pair t1, t2 of tuples violate an FD X→A, one can resolve the inconsistency by modifying t1[A] or t2[A] such that t1[A]=t2[A]. That is, FD violations can always be resolved by modifying values of some t1(ort2) attributes in the right hand side of FDs, without changing the left hand side such that at t1[X]≠t2 [X]. In contrast, this strategy no longer works for CFDs. To see this, consider a schema R with attr(R)=(A,B,C), an instance I of R consisting of (a1),(b1),(c1) and (a2),(b2),(c2), and a set Σ of CFDs including (A→B,(−,−)) and (C→B,{(c1,(b1),(c2,b2)}). Then I_ Σ and moreover, any repair I′ has to modify values of some attributes in the LHS of the FDs embedded in the CFDs.
A heuristic algorithm can be developed for finding a repair of a database, overcoming the new challenges.
System and Article of Manufacture Details
As is known in the art, the methods and apparatus discussed herein may be distributed as an article of manufacture that itself comprises a computer readable medium having computer readable code means embodied thereon. The computer readable program code means is operable, in conjunction with a computer system, to carry out all or some of the steps to perform the methods or create the apparatuses discussed herein. The computer readable medium may be a recordable medium (e.g., floppy disks, hard drives, compact disks, or memory cards) or may be a transmission medium (e.g., a network comprising fiber-optics, the world-wide web, cables, or a wireless channel using time-division multiple access, code-division multiple access, or other radio-frequency channel). Any medium known or developed that can stole information suitable for use with a computer system may be used. The computer-readable code means is any mechanism for allowing a computer to read instructions and data, such as magnetic variations on a magnetic media or height variations on the surface of a compact disk.
The computer systems and servers described herein each contain a memory that will configure associated processors to implement the methods, steps, and functions disclosed herein. The memories could be distributed or local and the processors could be distributed or singular. The memories could be implemented as an electrical, magnetic or optical memory, or any combination of these or other types of storage devices. Moreover, the term “memory” should be construed broadly enough to encompass any information able to be read from or written to an address in the addressable space accessed by an associated processor. With this definition, information on a network is still within a memory because the associated processor can retrieve the information from the network.
It is to be understood that the embodiments and variations shown and described herein are merely illustrative of the principles of this invention and that various modifications may be implemented by those skilled in the art without departing from the scope and spirit of the invention.
Number | Name | Date | Kind |
---|---|---|---|
20060155743 | Bohannon et al. | Jul 2006 | A1 |
Number | Date | Country | |
---|---|---|---|
20090006302 A1 | Jan 2009 | US |