|
5. Safe and Eager Migration
Now that we have a generic NoSQL database programming lan- guage, we can implement the declarative schema evolution opera- tions from Section 3. We believe the declarative operations cover common schema evolution tasks. For more complex migration sce- narios, we can always resort to a programmatic solution. This matches the situation with relational databases, where an “ALTER TABLE” statement covers the typical schema alterations, but where more complex transformations require an ETL-process to be set up,
(
or a custom migration script to be coded.
Let asθ be the result of evaluating query θ, i.e.
get(θ) (ds, ?) = (ds, asθ )
Figure 6 shows the implementation for the operations add, delete, and rename. A for-loop fetches all matching entities from
] the data store, modifies them, and updates their version property (as
and let K = {κ | (κ → π) ∈ asθ } be the keys of all entities in the
query result. We can then evaluate the for-loop as follows.
while (K != ?) do
there exists some key κ in K;
K := K \ {κ};
evaluate operation op for the binding of x to key κ:
(ds, as) := op[x/κ] (ds, as);
od ]
Above, op[x/κ] is obtained from operation op by first substituting each occurrence of x in op by κ, and next replacing all operands κ.n in query predicates by the value of “getProperty(κ, n)”.
Example 11. We add a new property “email” to all user entities in the data store, and initialize it with the empty string E.
foreach x in get(kind = “user”) do
setProperty(x, email, E); put(x)
od
introduced in Section 3). The updated entities are then persisted.
Figure 7 shows the implementation for copy and move. Again, entities are fetched from the NoSQL data store one by one, updated, and then persisted. This requires joins between entities. Since joins are not supported in most NoSQL data stores, they need to be encoded in the application logic.
This batch update corresponds to the recommendation of NoSQL data store providers on how to handle schema evolution (e.g. [23]).
Note that the create-or-replace semantics inherent in our NoSQL database programming language make for a well-defined behav- ior of operations. For instance, renaming the property “text” in blogposts to “content” (c.f. Example 4) effectively overwrites any existing property named content. |
|