Update of /cvsroot/monetdb/pathfinder/compiler/algebra
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv17783/compiler/algebra
Modified Files:
algebra.c builtins.c logical.c physical.c
Log Message:
* Algebra and MIL implementation of the XQuery update functions:
upd:delete
upd:insertAfter
upd:insertBefore
upd:insertIntoAsFirst
upd:insertIntoAsLast
upd:rename
upd:replaceElementContent
upd:replaceNode
upd:replaceValue
There is some things that must be still done in the algebra level, e.g.,
reverse the order of the sequence in the insertBefore/insertIntoASFirst
functions. Also the mil implementation of the serialize operator for
updates is not done yet. So basically updates wont work yet in the
algebra backend, but we are getting closer.
Index: physical.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/physical.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- physical.c 26 Oct 2007 13:03:13 -0000 1.42
+++ physical.c 20 Nov 2007 16:57:24 -0000 1.43
@@ -1574,7 +1574,7 @@
assert (n->schema.items[ix[0]].type == aat_str);
assert (n->schema.items[ix[1]].type == aat_int &&
n->schema.items[ix[2]].type == aat_int);
-
+
res_type = aat_str;
break;
@@ -1679,6 +1679,69 @@
res_type = n->schema.items[ix[0]].type;
break;
+
+ case alg_fun_upd_delete:
+ assert(refs.count == 1);
+ /* make sure that the attributes is a node */
+ assert(n->schema.items[ix[0]].type & aat_node);
+
+ /* the result type is aat_update bitwise OR the type of
+ the target node shifted 4 bits to the left */
+ assert((n->schema.items[ix[0]].type << 4) & aat_node1);
+ res_type = aat_update | (n->schema.items[ix[0]].type << 4);
+ break;
+
+ case alg_fun_upd_rename:
+ case alg_fun_upd_insert_into_as_first:
+ case alg_fun_upd_insert_into_as_last:
+ case alg_fun_upd_insert_before:
+ case alg_fun_upd_insert_after:
+ case alg_fun_upd_replace_value_att:
+ case alg_fun_upd_replace_value:
+ case alg_fun_upd_replace_element:
+ case alg_fun_upd_replace_node:
+ assert(refs.count == 2);
+
+ /* make some assertions according to the fun signature */
+ switch (kind) {
+ case alg_fun_upd_rename:
+ assert(n->schema.items[ix[0]].type & aat_node);
+ assert(n->schema.items[ix[1]].type & aat_qname);
+ assert((n->schema.items[ix[0]].type << 4) & aat_node1);
+ break;
+ case alg_fun_upd_insert_into_as_first:
+ case alg_fun_upd_insert_into_as_last:
+ case alg_fun_upd_insert_before:
+ case alg_fun_upd_insert_after:
+ case alg_fun_upd_replace_node:
+ assert(n->schema.items[ix[0]].type & aat_node);
+ assert(n->schema.items[ix[1]].type & aat_node);
+ assert((n->schema.items[ix[0]].type << 4) & aat_node1);
+ break;
+ case alg_fun_upd_replace_value_att:
+ assert(n->schema.items[ix[0]].type & aat_anode);
+ assert(n->schema.items[ix[1]].type & aat_uA);
+ assert((n->schema.items[ix[0]].type << 4) & aat_anode1);
+ break;
+ case alg_fun_upd_replace_value:
+ assert(n->schema.items[ix[0]].type & aat_pnode);
+ assert(n->schema.items[ix[1]].type & aat_uA);
+ assert((n->schema.items[ix[0]].type << 4) & aat_pnode1);
+ break;
+ case alg_fun_upd_replace_element:
+ assert(n->schema.items[ix[0]].type & aat_pnode);
+ assert(n->schema.items[ix[1]].type & aat_str);
+ assert((n->schema.items[ix[0]].type << 4) & aat_pnode1);
+ break;
+ default: assert(!"should never reach here"); break;
+ }
+
+ /* the result type is aat_update bitwise OR the type of
+ the target_node shifted 4 bits to the left bitwise OR
+ the type of the second argument */
+ res_type = aat_update | (n->schema.items[ix[0]].type << 4)
+ | n->schema.items[ix[1]].type;
+ break;
}
/* create new generic function operator node */
Index: algebra.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/algebra.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- algebra.c 5 Nov 2007 22:46:33 -0000 1.61
+++ algebra.c 20 Nov 2007 16:57:21 -0000 1.62
@@ -734,6 +734,13 @@
case aat_pnode: return "pnode";
case aat_pre: return "pre";
case aat_pfrag: return "pfrag";
+ case aat_node1: return "node1";
+ case aat_anode1:return "attr1";
+ case aat_attr1: return "attrID1";
+ case aat_afrag1:return "afrag1";
+ case aat_pnode1:return "pnode1";
+ case aat_pre1: return "pre1";
+ case aat_pfrag1:return "pfrag1";
default:
if (type & aat_update)
return "update";
@@ -747,13 +754,13 @@
* Checks whether a name is unique or not.
*/
bool
-PFalg_is_unq_name(PFalg_att_t att)
+PFalg_is_unq_name(PFalg_att_t att)
{
return ((1 << 3) & att) && (att & 7);
}
/**
- * Create an unique name based on an id @a id and
+ * Create an unique name based on an id @a id and
* an original name @a ori that retains the usage information
* of the new variable (iter, pos or item).
*/
@@ -857,6 +864,7 @@
if (free & att_item) return att_item;
if (free & att_item1) return att_item1;
if (free & att_item2) return att_item2;
+ if (free & att_item3) return att_item3;
if (free & att_subty) return att_subty;
if (free & att_itemty) return att_itemty;
if (free & att_notsub) return att_notsub;
@@ -998,6 +1006,16 @@
case alg_fun_fn_qname: return "fn:QName";
case alg_fun_pf_fragment: return "#pf:fragment";
case alg_fun_pf_supernode: return "#pf:supernode";
+ case alg_fun_upd_rename: return "upd:rename";
+ case alg_fun_upd_delete: return "upd:delete";
+ case alg_fun_upd_insert_into_as_first: return "upd:insertIntoAsFirst";
+ case alg_fun_upd_insert_into_as_last: return "upd:insertIntoAsLast";
+ case alg_fun_upd_insert_before: return "upd:insertBefore";
+ case alg_fun_upd_insert_after: return "upd:insertAfter";
+ case alg_fun_upd_replace_value_att: return "upd:replaceValue";
+ case alg_fun_upd_replace_value: return "upd:replaceValue";
+ case alg_fun_upd_replace_element: return "upd:replaceElementContent";
+ case alg_fun_upd_replace_node: return "upd:replaceNode";
}
PFoops (OOPS_FATAL, "unknown algebraic function name (%i)", fun);
return NULL;
Index: logical.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/logical.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- logical.c 7 Nov 2007 22:00:44 -0000 1.64
+++ logical.c 20 Nov 2007 16:57:22 -0000 1.65
@@ -1444,6 +1444,70 @@
res_type = n->schema.items[ix[0]].type;
break;
+
+ case alg_fun_upd_delete:
+ assert(refs.count == 1);
+
+ /* make sure that the attributes is a node */
+ assert(n->schema.items[ix[0]].type & aat_node);
+
+ /* the result type is aat_update bitwise OR the type of
+ the target_node shifted 4 bits to the left */
+ assert((n->schema.items[ix[0]].type << 4) & aat_node1);
+ res_type = aat_update | (n->schema.items[ix[0]].type << 4);
+ break;
+
+ case alg_fun_upd_rename:
+ case alg_fun_upd_insert_into_as_first:
+ case alg_fun_upd_insert_into_as_last:
+ case alg_fun_upd_insert_before:
+ case alg_fun_upd_insert_after:
+ case alg_fun_upd_replace_value_att:
+ case alg_fun_upd_replace_value:
+ case alg_fun_upd_replace_element:
+ case alg_fun_upd_replace_node:
+ assert(refs.count == 2);
+
+ /* make some assertions according to the fun signature */
+ switch (kind) {
+ case alg_fun_upd_rename:
+ assert(n->schema.items[ix[0]].type & aat_node);
+ assert(n->schema.items[ix[1]].type & aat_qname);
+ assert((n->schema.items[ix[0]].type << 4) & aat_node1);
+ break;
+ case alg_fun_upd_insert_into_as_first:
+ case alg_fun_upd_insert_into_as_last:
+ case alg_fun_upd_insert_before:
+ case alg_fun_upd_insert_after:
+ case alg_fun_upd_replace_node:
+ assert(n->schema.items[ix[0]].type & aat_node);
+ assert(n->schema.items[ix[1]].type & aat_node);
+ assert((n->schema.items[ix[0]].type << 4) & aat_node1);
+ break;
+ case alg_fun_upd_replace_value_att:
+ assert(n->schema.items[ix[0]].type & aat_anode);
+ assert(n->schema.items[ix[1]].type & aat_uA);
+ assert((n->schema.items[ix[0]].type << 4) & aat_anode1);
+ break;
+ case alg_fun_upd_replace_value:
+ assert(n->schema.items[ix[0]].type & aat_pnode);
+ assert(n->schema.items[ix[1]].type & aat_uA);
+ assert((n->schema.items[ix[0]].type << 4) & aat_pnode1);
+ break;
+ case alg_fun_upd_replace_element:
+ assert(n->schema.items[ix[0]].type & aat_pnode);
+ assert(n->schema.items[ix[1]].type & aat_str);
+ assert((n->schema.items[ix[0]].type << 4) & aat_pnode1);
+ break;
+ default: assert(!"should never reach here"); break;
+ }
+
+ /* the result type is aat_update bitwise OR the type of
+ the target_node shifted 4 bits to the left bitwise OR
+ the type of the second argument */
+ res_type = aat_update | (n->schema.items[ix[0]].type << 4)
+ | n->schema.items[ix[1]].type;
+ break;
}
/* create new generic function operator node */
@@ -3943,12 +4007,12 @@
case la_ref_tbl:
{
- return PFla_ref_tbl_
+ return PFla_ref_tbl_
(
n->sem.ref_tbl.name,
n->schema,
n->sem.ref_tbl.tatts,
- n->sem.ref_tbl.keys
+ n->sem.ref_tbl.keys
);
} break;
Index: builtins.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/builtins.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- builtins.c 26 Oct 2007 13:03:13 -0000 1.61
+++ builtins.c 20 Nov 2007 16:57:21 -0000 1.62
@@ -4385,4 +4385,291 @@
.frag = args[0].frag };
}
+/* -------------------- */
+/* #3. UPDATE FUNCTIONS */
+/* -------------------- */
+
+/**
+ * Algebra implementation of updates functions. An update can be represented by
+ * the same generic algebra operator (fun1to1) as any row based function
+ * (e.g., the string functions). The mapping of multiple nodes to a target node
+ * (e.g., the insert* functions) as well as the item reversal (needed for some
+ * insert* functions) is be done during the translation from core to logical
+ * algebra.
+ */
+
+/**
+ * Built-in function upd:rename(node, QName)
+ */
+struct PFla_pair_t
+PFbui_upd_rename (const PFla_op_t *loop, bool ordering,
+ struct PFla_pair_t *args)
+{
+ (void) loop; (void) ordering;
+
+ return (struct PFla_pair_t) {
+ .rel = project (
+ fun_1to1 (
+ eqjoin (args[0].rel,
+ project (args[1].rel,
+ proj (att_iter1, att_iter),
+ proj (att_item1, att_item)),
+ att_iter,
+ att_iter1),
+ alg_fun_upd_rename,
+ att_res,
+ attlist (att_item, att_item1)),
+ proj (att_iter, att_iter),
+ proj (att_pos, att_pos),
+ proj (att_item, att_res)),
+ .frag = args[0].frag };
+}
+
+/**
+ * Built-in function upd:delete(node)
+ */
+struct PFla_pair_t
+PFbui_upd_delete (const PFla_op_t *loop, bool ordering,
+ struct PFla_pair_t *args)
+{
+ (void) loop; (void) ordering;
+
+ return (struct PFla_pair_t) {
+ .rel = project ( fun_1to1 ( args[0].rel,
+ alg_fun_upd_delete,
+ att_res,
+ attlist (att_item)),
+ proj (att_iter, att_iter),
+ proj (att_pos, att_pos),
+ proj (att_item, att_res)),
+ .frag = args[0].frag };
+}
+
+/**
+ * Built-in function
+ * upd:insertIntoAsFirst(node, node*)
+ * this should be node+ ...
+ */
+struct PFla_pair_t
+PFbui_upd_insert_into_as_first (const PFla_op_t *loop,
+ bool ordering,
+ struct PFla_pair_t *args)
+{
+ (void) loop; (void) ordering;
+
+ /* FIXME: also have to reverse the order of the sequence*/
+ return (struct PFla_pair_t) {
+ .rel = project (
+ fun_1to1 (
+ eqjoin (args[0].rel,
+ project (args[1].rel,
+ proj (att_iter1, att_iter),
+ proj (att_item1, att_item)),
+ att_iter,
+ att_iter1),
+ alg_fun_upd_insert_into_as_first,
+ att_res,
+ attlist (att_item, att_item1)),
+ proj (att_iter, att_iter),
+ proj (att_pos, att_pos),
+ proj (att_item, att_res)),
+ .frag = args[0].frag };
+}
+
+/**
+ * Built-in function
+ * upd:insertIntoAsLast(node, node*)
+ * this should be node+ ...
+ */
+struct PFla_pair_t
+PFbui_upd_insert_into_as_last (const PFla_op_t *loop, bool ordering,
+ struct PFla_pair_t *args)
+{
+ (void) loop; (void) ordering;
+
+ return (struct PFla_pair_t) {
+ .rel = project (
+ fun_1to1 (
+ eqjoin (args[0].rel,
+ project (args[1].rel,
+ proj (att_iter1, att_iter),
+ proj (att_item1, att_item)),
+ att_iter,
+ att_iter1),
+ alg_fun_upd_insert_into_as_last,
+ att_res,
+ attlist (att_item, att_item1)),
+ proj (att_iter, att_iter),
+ proj (att_pos, att_pos),
+ proj (att_item, att_res)),
+ .frag = args[0].frag };
+}
+
+/**
+ * Built-in function upd:insertBefore(node, node*)
+ * this should be node+ ...
+ */
+struct PFla_pair_t
+PFbui_upd_insert_before (const PFla_op_t *loop, bool ordering,
+ struct PFla_pair_t *args)
+{
+ (void) loop; (void) ordering;
+
+ /* FIXME: also have to reverse the order of the sequence*/
+ return (struct PFla_pair_t) {
+ .rel = project (
+ fun_1to1 (
+ eqjoin (args[0].rel,
+ project (args[1].rel,
+ proj (att_iter1, att_iter),
+ proj (att_item1, att_item)),
+ att_iter,
+ att_iter1),
+ alg_fun_upd_insert_before,
+ att_res,
+ attlist (att_item, att_item1)),
+ proj (att_iter, att_iter),
+ proj (att_pos, att_pos),
+ proj (att_item, att_res)),
+ .frag = args[0].frag };
+}
+
+/**
+ * Built-in function upd:insertAfter(node, node*)
+ * this should be node+ ...
+ */
+struct PFla_pair_t
+PFbui_upd_insert_after (const PFla_op_t *loop, bool ordering,
+ struct PFla_pair_t *args)
+{
+ (void) loop; (void) ordering;
+
+ return (struct PFla_pair_t) {
+ .rel = project (
+ fun_1to1 (
+ eqjoin (args[0].rel,
+ project (args[1].rel,
+ proj (att_iter1, att_iter),
+ proj (att_item1, att_item)),
+ att_iter,
+ att_iter1),
+ alg_fun_upd_insert_after,
+ att_res,
+ attlist (att_item, att_item1)),
+ proj (att_iter, att_iter),
+ proj (att_pos, att_pos),
+ proj (att_item, att_res)),
+ .frag = args[0].frag };
+}
+
+/**
+ * Built-in function upd:replaceValue(anyAttribute, untypedAtomic)
+ */
+struct PFla_pair_t
+PFbui_upd_replace_value_att (const PFla_op_t *loop, bool ordering,
+ struct PFla_pair_t *args)
+{
+ (void) loop; (void) ordering;
+
+ return (struct PFla_pair_t) {
+ .rel = project (
+ fun_1to1 (
+ eqjoin (args[0].rel,
+ project (args[1].rel,
+ proj (att_iter1, att_iter),
+ proj (att_item1, att_item)),
+ att_iter,
+ att_iter1),
+ alg_fun_upd_replace_value_att,
+ att_res,
+ attlist (att_item, att_item1)),
+ proj (att_iter, att_iter),
+ proj (att_pos, att_pos),
+ proj (att_item, att_res)),
+ .frag = args[0].frag };
+}
+
+/**
+ * Built-in function upd:replaceValue(text(), untypedAtomic)
+ * Built-in function upd:replaceValue(processing-instr(), untypedAtomic)
+ * Built-in function upd:replaceValue(comment(), untypedAtomic)
+ */
+struct PFla_pair_t
+PFbui_upd_replace_value (const PFla_op_t *loop, bool ordering,
+ struct PFla_pair_t *args)
+{
+ (void) loop; (void) ordering;
+
+ return (struct PFla_pair_t) {
+ .rel = project (
+ fun_1to1 (
+ eqjoin (args[0].rel,
+ project (args[1].rel,
+ proj (att_iter1, att_iter),
+ proj (att_item1, att_item)),
+ att_iter,
+ att_iter1),
+ alg_fun_upd_replace_value,
+ att_res,
+ attlist (att_item, att_item1)),
+ proj (att_iter, att_iter),
+ proj (att_pos, att_pos),
+ proj (att_item, att_res)),
+ .frag = args[0].frag };
+}
+
+/**
+ * Built-in function upd:replaceElementContent(element(), text()?))
+ */
+struct PFla_pair_t
+PFbui_upd_replace_element (const PFla_op_t *loop, bool ordering,
+ struct PFla_pair_t *args)
+{
+ (void) loop; (void) ordering;
+
+ return (struct PFla_pair_t) {
+ .rel = project (
+ fun_1to1 (
+ eqjoin (args[0].rel,
+ project (args[1].rel,
+ proj (att_iter1, att_iter),
+ proj (att_item1, att_item)),
+ att_iter,
+ att_iter1),
+ alg_fun_upd_replace_element,
+ att_res,
+ attlist (att_item, att_item1)),
+ proj (att_iter, att_iter),
+ proj (att_pos, att_pos),
+ proj (att_item, att_res)),
+ .frag = args[0].frag };
+}
+
+/**
+ * Built-in function upd:replaceNode (node, node)
+ */
+struct PFla_pair_t
+PFbui_upd_replace_node (const PFla_op_t *loop, bool ordering,
+ struct PFla_pair_t *args)
+{
+ (void) loop; (void) ordering;
+
+ return (struct PFla_pair_t) {
+ .rel = project (
+ fun_1to1 (
+ eqjoin (args[0].rel,
+ project (args[1].rel,
+ proj (att_iter1, att_iter),
+ proj (att_item1, att_item)),
+ att_iter,
+ att_iter1),
+ alg_fun_upd_replace_node,
+ att_res,
+ attlist (att_item, att_item1)),
+ proj (att_iter, att_iter),
+ proj (att_pos, att_pos),
+ proj (att_item, att_res)),
+ .frag = args[0].frag };
+}
+
/* vim:set shiftwidth=4 expandtab: */
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins