Repository navigation
v2.0.0
autodb 2.0.0
The general theme for this version is classes for intermediate results: functional dependencies, schemas, and databases now have fleshed-out classes, with methods to keep them self-consistent. They all have their own constructors, for users to create their own, instead of having to generate them from a given data frame.
Breaking changes
- Renamed
dfdtodiscover, to reflect the generalisation to allow the use of other methods. At the moment, this just includes DFD. - Removed
flattenfrom exported functions, in favour of flattening the functional dependencies indfd/discoverinstead. Sinceflattenwas usually called anyway, and its output is more readable since adding aprintmethod for it, there was little reason to keep the olddfd/discoveroutput format, where functional dependencies were grouped by dependant. - Renamed
cross_referencetoautoref, to better reflect its purpose as generating foreign key references. - Renamed
normalisetosynthesise, to reflect its only creating relation schemas, not foreign key references. The new function namednormalisenow calls a wrapper for bothsynthesiseandautoref, since in most cases we don't need to do these steps separately. Additionally,ensure_losslessis now an argument forsynthesiserather thanautoref: this is a more nature place to put it, sincesynthesisecreates relations, andautorefadds foreign key references. - As noted in improvements, functional dependency objects now have their own subsetting methods. In particular, they have a
[[method, so code that used[[to extract determinant sets or dependants from functional dependencies will no longer work. These should be extracted with the newdetsetanddependantfunctions instead. - Similarly, the
databaseclass has its own subsetting methods, so components must be extracted withrecords,keys, and so on. - The
databaseclass no longer assigns aparentsattribute to each relation, since this duplicates the foreign key reference information given inreferences. - The
databaseclass no longer has anameattribute. This was only used to name the graph when using thegvfunction, so is now an argument for thedatabasemethod ofgvinstead, bringing its arguments into line with those of the other methods. relationshipsindatabase_schemaanddatabaseobjects are now calledreferences, to better reflect their being foreign key constraints, and they are stored in a format that better reflects this: instead of an element for each pair of attributes in a foreign key, there is one element for the whole foreign key, containing all of the involved attributes. Similarly, they are now printed in the format "child.{c1, c2, ...} -> parent.{p1, p2, ...}" instead of "child.c1 -> parent.p1; child.c2 -> parent.p2; ...".cross_reference/autorefnow defaults to generating more than one foreign key reference per parent-child relation pair, rather than keeping only the one with the first child key by priority order. This can result in some confusion on plots, since references are still plotted one attribute pair at a time.
Improvements
- Added classes and methods for important data structures:
- Added a
functional_dependencyclass for flattened functional dependency sets. The attributes vector is now stored as an attribute, so that the dependencies can be accessed as a simple list without list subsetting operators. There are alsodetset,dependant, andattrs_ordergeneric functions for extracting the relevant parts.detsetanddependant, in particular, should be useful for the purposes of filtering predicates. - Added a
relation_schemaclass for relational schema sets, as returned bysynthesise. The attributes and keys are now stored together in a named list, with theattrs_ordervector attribute order stored as an attribute. As with thefunctional_dependency, this lets the schemas be accessed like a vector. There is alsomerge_empty_keysfor combining schemas with an empty key, andattrs,keys, andattrs_ordergeneric functions for extracting the relevant parts. - Added a
database_schemaclass for database schemas, as returned bynormalise. This inherits fromrelation_schema, and has foreign key references as an additionalreferencesattribute. There is amerge_empty_keysmethod that conserves validity of the foreign key references. Additionally, when the names of the contained relation schemas are changed usingnames<-, the references are changed to use the new names. - Added a
relationclass for vectors of relations containing data. Since adatabase_schemais just arelation_schemavector with foreign key references added, therelationclass was added as the equivalent underlying vector for thedatabaseclass. A user of the package probably won't need to use it. databaseis now a wrapper class aroundrelation, that adds foreign key references, and handles them separately in its methods.- All of the above have their own methods for the
[,[[, and -- except forfunctional_dependency--$subsetting operators, along with their replacement equivalents,[<-etc., to allow treating them as vectors of relation schemas or relations. Subsetting also removes any foreign key references indatabase_schemaanddatabaseobjects that are no longer relevant. These methods prevent the subsetting operators from being used to access the object's internal components, so many of the generic functions mentioned above were written to allow access in a more principled manner, not requiring knowledge of how the structure is implemented. - All of the above have a
cmethod for vector-like concatenation. There are two non-trivial aspects to this. Firstly, when concatenating objects with differentattrs_orderattributes,cmerges the orders to keep them consistent, if possible. Secondly, fordatabase_schemaanddatabase, foreign key references are changed to reflect any changes made to relation names to keep them unique. - All of the above have a
uniquemethod for vector-like removal of duplicate schemas / relations. This conserves validity of foreign key references fordatabase_schemaanddatabaseobjects. Forrelationanddatabaseobjects, duplication doesn't require records to be kept in the same order.
- Added a
- Added some basic database creation/manipulation generic functions for the above data structures:
- All of the above have a
names<-method for consistently changing relation (schema) names. In particular, for databases and database schemas, this ensures the names are also changed in references. - All of the above, except
functional_dependency, have arename_attrsmethod for renaming the attributes across the whole object. This renames them in all schemas, relations, references, and so on. - Added a
creategeneric function, for creatingrelationanddatabaseobjects fromrelation_schemaanddatabase_schemaobjects, respectively. The created objects contain no data. This function is roughly the equivalent toCREATE TABLEin SQL, but the vectorised nature of the relation classes means that several tables are created at once. - Added an
insertgeneric function forrelationanddatabaseobjects, which takes a data frame of new data, and inserts it into any relation in the object whose attributes are all present in the new data. This is roughly equivalent to SQL'sINSERT, but works over multiple relations at once, and means there's now a way to put data into adatabaseoutside ofdecompose. Indeed,decomposeis now equivalent to callingcreate, then callinginsertwith all the relations.
- All of the above have a
- Adjusted
normaliseto prefer to remove dependencies with dependants and determinant sets later in table order, and with larger dependant sets. This brings it more in line with similar decisions made in other package functions. - Simplified some internals of
dfd/discoverto improve computation time. - Added a
skip_bijectionsoption todfd/discover, to speed up functional dependency searches where there are pairwise-equivalent attributes present.
Fixes
- Corrected vignette re: when to remove spurious dependencies before.
- Corrected
autodbdocumentation link to page with database format information. - Corrected
df_equivto work withdata.framecolumns that are lists. - Fixed several issues related to doubles / floating-point:
- Fixed
dfd/discovertreating similar numeric values as equal, resulting in data frames not being insertable into their own schema. - Fixed
databasechecks not handling doubles correctly. Specifically, foreign key reference checks involve merging tables together, and merge operates on doubles with a tolerance that's set within an internal method, so merges can create duplicates that need to be removed afterwards. - Similarly, fixed
rejoinin the case where merges are based on doubles, sometimes resulting in duplicates.
- Fixed
- Fixed
normalise's return output to be invariant to the given order of thefunctional_dependencyinput. - Fixed
normalisereturning relations with attributes in the wrong order in certain cases whereremove_avoidable = TRUE. - Fixed
gvgiving Graphviz code that could result in incorrect diagrams: relation and attribute names were converted to lower case, and not checked for uniqueness afterwards. This could result in incorrect foreign key references being drawn. The fix also accounts for a current bug in Graphviz, where edges between HTML-style node ports ignore case for the port labels.