Changeset: 8ff2256bbdba for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8ff2256bbdba
Modified Files:
monetdb5/extras/rdf/common/rdfjgraph.c
monetdb5/extras/rdf/common/rdfjgraph.h
sql/backends/monet5/sql_rdf_jgraph.c
Branch: rdf
Log Message:
Fix the problems of computing inner join groups
diffs (truncated from 374 to 300 lines):
diff --git a/monetdb5/extras/rdf/common/rdfjgraph.c
b/monetdb5/extras/rdf/common/rdfjgraph.c
--- a/monetdb5/extras/rdf/common/rdfjgraph.c
+++ b/monetdb5/extras/rdf/common/rdfjgraph.c
@@ -52,7 +52,7 @@ jgraph* initJGraph(void){
return jg;
}
-void addJGnode(int *vid, jgraph *jg, void *data, int subjgId, JNodeT t){
+void addJGnode(int *vid, jgraph *jg, void *data, int subjgId, oid _soid,
JNodeT t){
jgnode *node = (jgnode *) malloc(sizeof(jgnode));
node->vid = jg->nNode;
@@ -64,6 +64,7 @@ void addJGnode(int *vid, jgraph *jg, voi
node->subjgId = subjgId;
node->patternId = -1;
node->ijpatternId = -1;
+ node->soid = _soid;
node->type = t;
jg->lstnodes[jg->nNode] = node;
@@ -204,7 +205,7 @@ void buildExampleJGraph(void){
jgraph *jg = initJGraph();
for (i = 0; i < 5; i++){
- addJGnode(&tmpid, jg, NULL, 0, JN_REQUIRED);
+ addJGnode(&tmpid, jg, NULL, 0, BUN_NONE, JN_REQUIRED);
}
add_undirectedJGedge(0, 1, op_join, jg, NULL, JP_NAV, -1, -1);
add_undirectedJGedge(0, 3, op_join, jg, NULL, JP_NAV, -1, -1);
diff --git a/monetdb5/extras/rdf/common/rdfjgraph.h
b/monetdb5/extras/rdf/common/rdfjgraph.h
--- a/monetdb5/extras/rdf/common/rdfjgraph.h
+++ b/monetdb5/extras/rdf/common/rdfjgraph.h
@@ -79,7 +79,8 @@ typedef struct jgnode {
int subjgId;
int patternId; //For star pattern
int ijpatternId; //Id of inner join subgraph for nodes
connected
- //only by inner join in the star pattern
+ //only by inner join in the star patter
+ oid soid; //Oid of the subject if it is already
known
JNodeT type; //This node can be optional, or
required in the pattern
} jgnode;
@@ -97,7 +98,7 @@ rdf_export
void freeJGraph(jgraph *jg); //Free join graph
rdf_export
-void addJGnode(int *vid, jgraph *jg, void *data, int subjgId, JNodeT type);
+void addJGnode(int *vid, jgraph *jg, void *data, int subjgId, oid soid, JNodeT
type);
rdf_export
void add_undirectedJGedge(int from, int to, operator_type op, jgraph *jg, void
*data, JP jp, int rel_id, int p_rel_id);
diff --git a/sql/backends/monet5/sql_rdf_jgraph.c
b/sql/backends/monet5/sql_rdf_jgraph.c
--- a/sql/backends/monet5/sql_rdf_jgraph.c
+++ b/sql/backends/monet5/sql_rdf_jgraph.c
@@ -154,6 +154,8 @@ void addRelationsToJG(mvc *sql, sql_rel
* Get the table from rdf schema
* */
+static void get_predicate_from_exps(mvc *c, list *tmpexps, char **prop, char
**subj, int get_subject_only);
+
static
sql_table* get_rdf_table(mvc *c, char *tblname){
sql_table *tbl = NULL;
@@ -467,6 +469,30 @@ int* get_crossedge_apply_orders(jgraph *
return orders;
}
+
+static
+void _add_jg_node(mvc *c, jgraph *jg, sql_rel *rel, int subjgId, JNodeT t){
+ int tmpvid = -1;
+ str subj = NULL;
+ oid soid = BUN_NONE;
+
+ //Set subject oid if it is there
+ if (rel->op==op_select){
+ //Check whether there is constrainst on s_oid
+ list *exps = rel->exps;
+
+ if (exps){
+ get_predicate_from_exps(c, exps, NULL, &subj, 1);
+ }
+ if (subj){
+ SQLrdfstrtoid(&soid, &subj);
+ assert (soid != BUN_NONE);
+ }
+ }
+
+ addJGnode(&tmpvid, jg, rel, subjgId, soid, t);
+}
+
/*
* Algorithm for adding sql rels to Join Graph
*
@@ -480,7 +506,6 @@ int* get_crossedge_apply_orders(jgraph *
* */
static
void addRelationsToJG(mvc *c, sql_rel *parent, sql_rel *rel, int depth, jgraph
*jg, int new_subjg, int *subjgId, int *level, int tmp_level, sql_rel
**node_root){
- int tmpvid =-1;
switch (rel->op) {
case op_right:
@@ -509,7 +534,7 @@ void addRelationsToJG(mvc *c, sql_rel *p
*level = tmp_level;
*node_root = parent;
}
- addJGnode(&tmpvid, jg, (sql_rel *) rel,
*subjgId, JN_REQUIRED);
+ _add_jg_node(c, jg, (sql_rel *) rel, *subjgId,
JN_REQUIRED);
}
else{ //This is the connect to a new join sg
addRelationsToJG(c, rel, rel->l, depth+1, jg,
1, subjgId, level, tmp_level + 1, node_root);
@@ -521,7 +546,7 @@ void addRelationsToJG(mvc *c, sql_rel *p
*level = tmp_level;
*node_root = parent;
}
- addJGnode(&tmpvid, jg, (sql_rel *) rel, *subjgId,
JN_REQUIRED);
+ _add_jg_node(c, jg, (sql_rel *) rel, *subjgId,
JN_REQUIRED);
break;
default:
printf("[%s]\n", op2string(rel->op));
@@ -697,6 +722,19 @@ void get_jp(str pred1, str pred2, JP *jp
}
+static
+int have_same_subj(jgraph *jg, int from, int to){
+
+ jgnode *fromnode, *tonode;
+
+ fromnode = jg->lstnodes[from];
+ tonode = jg->lstnodes[to];
+
+ if ((fromnode->soid != BUN_NONE) && (fromnode->soid == tonode->soid))
return 1;
+
+ else return 0;
+}
+
/*
* Input: sql_rel with op == op_join, op_left or op_right
* */
@@ -708,6 +746,11 @@ void _add_join_edges(jgraph *jg, sql_rel
assert(rel->op == op_join || rel->op == op_left || rel->op ==
op_right);
tmpexps = rel->exps;
+
+ if (rel->op == op_left){
+ printf("Add Join Edge via LEFT JOIN: \n");
+ }
+
if (tmpexps){
node *en;
@@ -751,6 +794,7 @@ void _add_join_edges(jgraph *jg, sql_rel
//TODO: Handle other cases
int tmpCond;
int from, to;
+ JP tmpjg = JP_NAV;
assert(tmpexp->l);
assert(atom_type(tmpexp->l)->type->localtype !=
TYPE_ptr);
tmpCond = (int) atom_get_int(tmpexp->l);
@@ -759,8 +803,11 @@ void _add_join_edges(jgraph *jg, sql_rel
printf("Join (condition 1) between %s
and %s\n", rel_name((sql_rel*) rel->l), rel_name((sql_rel *)rel->r));
from = rname_to_nodeId(nm,
rel_name((sql_rel*) rel->l));
to = rname_to_nodeId(nm,
rel_name((sql_rel*) rel->r));
- if (rel->op == op_join)
add_undirectedJGedge(from, to, rel->op, jg, rel, JP_NAV, rel_id, p_rel_id);
- else if (rel->op == op_left)
add_directedJGedge(from, to, op_left, jg, rel, JP_NAV, rel_id, p_rel_id);
+ if (have_same_subj(jg, from, to) == 1){
+ tmpjg = JP_S;
+ }
+ if (rel->op == op_join)
add_undirectedJGedge(from, to, rel->op, jg, rel, tmpjg, rel_id, p_rel_id);
+ else if (rel->op == op_left)
add_directedJGedge(from, to, op_left, jg, rel, tmpjg, rel_id, p_rel_id);
else assert(0); //Other case is not
handled yet
printf("From: %d To %d\n", from, to);
@@ -774,13 +821,33 @@ void _add_join_edges(jgraph *jg, sql_rel
}
printf("\n\n\n");
}
+ else{
+ str relname1;
+ str relname2;
+ int from, to;
+ JP tmpjp = JP_S;
+
+ relname1 = rel_name((sql_rel*) rel->l);
+ relname2 = rel_name((sql_rel*) rel->r);
+
+ printf("CROSS PRODUCT HERE between %s and %s\n", relname1,
relname2);
+
+ assert (rel->op == op_join);
+
+ from = rname_to_nodeId(nm, relname1);
+ to = rname_to_nodeId(nm, relname2);
+
+ if (have_same_subj(jg, from, to) == 1){
+ printf("Connect to nodes having known subjects\n");
+ add_undirectedJGedge(from, to, rel->op, jg, rel, tmpjp,
rel_id, p_rel_id);
+ }
+ }
}
static
void addJoinEdgesToJG(mvc *c, sql_rel *parent, sql_rel *rel, int depth, jgraph
*jg, int new_subjg, int *subjgId, nMap *nm, char **isConnect, int
*last_rel_join_id, int p_rel_id, int *level, int tmp_level, sql_rel
**edge_root){
- //int tmpvid =-1;
int tmp_r_id;
switch (rel->op) {
@@ -929,18 +996,14 @@ void _detect_star_pattern(jgraph *jg, jg
//and the to_node does not belong to
//any pattern, add to the current pattern
- //Khi kiem tra xem co cung pattern khong co the dua vao
- //subject trong truong hop subject biet roi.
- //Consider query 2
-
jgedge *tmpedge;
tmpedge = node->first;
while (tmpedge != NULL){
if (tmpedge->jp == JP_S){
int optm = _optm;
- int tonode_ijpatternId = node->ijpatternId;
jgnode *tonode = jg->lstnodes[tmpedge->to];
+ /*
if (tmpedge->op == op_left){ //left outer join
optm = 1;
tonode_ijpatternId++;
@@ -948,10 +1011,10 @@ void _detect_star_pattern(jgraph *jg, jg
else if (tmpedge->op == op_right){
assert(0); //Have not handle this case
}
+ */
if (tonode->patternId == -1){
tonode->patternId = pId;
- tonode->ijpatternId = tonode_ijpatternId;
if (optm == 1) setNodeType(tonode, JN_OPTIONAL);
@@ -1145,7 +1208,7 @@ void extractURI_from_exp(mvc *c, char **
*
* */
static
-void get_predicate_from_exps(mvc *c, list *tmpexps, char **prop, char **subj){
+void get_predicate_from_exps(mvc *c, list *tmpexps, char **prop, char **subj,
int get_subject_only){
node *en;
@@ -1167,8 +1230,8 @@ void get_predicate_from_exps(mvc *c, lis
//Check if the column name is p, then
//extract the input property name
if (strcmp(colexp->name, "p") == 0){
-
num_p_cond++;
+ if (get_subject_only) continue;
extractURI_from_exp(c, prop, (sql_exp *)tmpexp->r);
//In case the column name is not in the abstract table,
add it
if (0) add_abstract_column(c, *prop);
@@ -1182,7 +1245,8 @@ void get_predicate_from_exps(mvc *c, lis
}
- assert(num_p_cond == 1 && (*prop) != NULL); //Verify that there is only
one p in this op_select sql_rel
+ if (!get_subject_only)
+ assert(num_p_cond == 1 && (*prop) != NULL); //Verify that there
is only one p in this op_select sql_rel
}
@@ -1222,7 +1286,7 @@ void extract_prop_and_subj_from_exps(mvc
//Get the column name by checking exps of r
tmpexps = r->exps;
if (tmpexps){
- get_predicate_from_exps(c, tmpexps, prop, subj);
+ get_predicate_from_exps(c, tmpexps, prop, subj, 0);
}
}
@@ -1898,7 +1962,7 @@ sql_rel* transform_inner_join_subjg (mvc
tmpexps = tmprel->exps;
- if (tmpexps) get_predicate_from_exps(c, tmpexps, &prop, &subj);
+ if (tmpexps) get_predicate_from_exps(c, tmpexps, &prop, &subj,
0);
//After having prop, get the corresponding column name
@@ -2034,7 +2098,7 @@ sql_rel* build_rdfscan (mvc *c, jgraph *
tmpexps = tmprel->exps;
- if (tmpexps) get_predicate_from_exps(c, tmpexps, &prop,
&subj);
+ if (tmpexps) get_predicate_from_exps(c, tmpexps, &prop,
&subj, 0);
//After having prop, get the corresponding column name
@@ -2424,6 +2488,48 @@ void get_union_expr(mvc *c, sql_rel *r,
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list