Changeset: 069413ef63e2 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=069413ef63e2
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:
More code refinement
diffs (truncated from 494 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, oid _soid,
JNodeT t){
+void addJGnode(int *vid, jgraph *jg, void *data, int subjgId, oid _soid, oid
_poid, char *prop, JNodeT t){
jgnode *node = (jgnode *) malloc(sizeof(jgnode));
node->vid = jg->nNode;
@@ -65,6 +65,10 @@ void addJGnode(int *vid, jgraph *jg, voi
node->patternId = -1;
node->ijpatternId = -1;
node->soid = _soid;
+ node->poid = _poid;
+ if (prop) node->prop = GDKstrdup(prop);
+ else node->prop = NULL;
+
node->type = t;
jg->lstnodes[jg->nNode] = node;
@@ -205,7 +209,7 @@ void buildExampleJGraph(void){
jgraph *jg = initJGraph();
for (i = 0; i < 5; i++){
- addJGnode(&tmpid, jg, NULL, 0, BUN_NONE, JN_REQUIRED);
+ addJGnode(&tmpid, jg, NULL, 0, BUN_NONE, BUN_NONE, NULL,
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
@@ -81,6 +81,8 @@ typedef struct jgnode {
int ijpatternId; //Id of inner join subgraph for nodes
connected
//only by inner join in the star patter
oid soid; //Oid of the subject if it is already
known
+ oid poid; //Oid of the predicate if it is already
known (usually Yes)
+ str prop; //Store the original name of the prop
JNodeT type; //This node can be optional, or
required in the pattern
} jgnode;
@@ -98,7 +100,7 @@ rdf_export
void freeJGraph(jgraph *jg); //Free join graph
rdf_export
-void addJGnode(int *vid, jgraph *jg, void *data, int subjgId, oid soid, JNodeT
type);
+void addJGnode(int *vid, jgraph *jg, void *data, int subjgId, oid soid, oid
poid, char *prop, 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
@@ -474,7 +474,9 @@ static
void _add_jg_node(mvc *c, jgraph *jg, sql_rel *rel, int subjgId, JNodeT t){
int tmpvid = -1;
str subj = NULL;
+ str prop = NULL;
oid soid = BUN_NONE;
+ oid poid = BUN_NONE;
//Set subject oid if it is there
if (rel->op==op_select){
@@ -482,15 +484,24 @@ void _add_jg_node(mvc *c, jgraph *jg, sq
list *exps = rel->exps;
if (exps){
- get_predicate_from_exps(c, exps, NULL, &subj, 1);
+ get_predicate_from_exps(c, exps, &prop , &subj, 0);
}
if (subj){
SQLrdfstrtoid(&soid, &subj);
assert (soid != BUN_NONE);
}
+ if (prop){
+
+ //Get propId, assuming the tokenizer is open already
+ //Note that, the prop oid is the original one (before
+ //running structural recognition process) so that
+ //we can directly get its oid from TKNR
+ TKNRstringToOid(&poid, &prop);
+ assert (poid != BUN_NONE);
+ }
}
- addJGnode(&tmpvid, jg, rel, subjgId, soid, t);
+ addJGnode(&tmpvid, jg, rel, subjgId, soid, poid, prop, t);
}
/*
@@ -1051,37 +1062,29 @@ spProps *init_sp_props(int num){
}
static
-void add_props_to_spprops(spProps *spprops, int idx, sp_po po, char *col){
- oid id;
-
- spprops->lstProps[idx] = GDKstrdup(col);
-
- //Get propId, assuming the tokenizer is open already
- //Note that, the prop oid is the original one (before
- //running structural recognition process) so that
- //we can directly get its oid from TKNR
- TKNRstringToOid(&id, & (spprops->lstProps[idx]));
- spprops->lstPropIds[idx] = id;
+void add_props_and_subj_to_spprops(spProps *spprops, int idx, sp_po po, jgnode
*node){
+
+ if (node->prop){
+ spprops->lstProps[idx] = GDKstrdup(node->prop);
+ assert(node->poid != BUN_NONE);
+ spprops->lstPropIds[idx] = node->poid;
+ spprops->lstPOs[idx] = po;
+
+ //without any information, assuming that the column is
single-valued col
+ spprops->lstctype[idx] = CTYPE_SG;
+ }
- spprops->lstPOs[idx] = po;
+ //For subject
+ if (node->soid){
+ if (spprops->subj == BUN_NONE){
+ spprops->subj = node->soid;
+ }
+ else
+ assert(spprops->subj == node->soid);
+ }
+}
+
- //without any information, assuming that the column is single-valued col
- spprops->lstctype[idx] = CTYPE_SG;
-}
-
-static
-void add_subj_to_spprops(spProps *spprops, char *subj){
- oid soid = BUN_NONE;
-
- SQLrdfstrtoid(&soid, &subj);
-
- if (spprops->subj == BUN_NONE){
- spprops->subj = soid;
- }
- else
- assert(spprops->subj == soid);
-
-}
static
void print_spprops(spProps *spprops){
@@ -1257,7 +1260,7 @@ void get_predicate_from_exps(mvc *c, lis
*
* */
static
-void extract_prop_and_subj_from_exps(mvc *c, sql_rel *r, char **prop, char
**subj){
+void verify_rel(sql_rel *r){
list *tmpexps = NULL;
char select_s = 0, select_p = 0, select_o = 0;
@@ -1282,12 +1285,6 @@ void extract_prop_and_subj_from_exps(mvc
}
assert(select_s && select_p && select_o);
-
- //Get the column name by checking exps of r
- tmpexps = r->exps;
- if (tmpexps){
- get_predicate_from_exps(c, tmpexps, prop, subj, 0);
- }
}
@@ -1949,25 +1946,19 @@ sql_rel* transform_inner_join_subjg (mvc
for (i = 0; i < nnode; i++){
- sql_rel *tmprel = (sql_rel*) (jg->lstnodes[jsg[i]]->data);
+ jgnode *tmpnode = jg->lstnodes[jsg[i]];
+ sql_rel *tmprel = (sql_rel*) (tmpnode->data);
int colIdx;
int isMVcol = 0;
- list *tmpexps = NULL;
- str prop;
- str subj;
oid tmpPropId;
assert(tmprel->op == op_select);
assert(((sql_rel*)tmprel->l)->op == op_basetable);
-
- tmpexps = tmprel->exps;
-
- if (tmpexps) get_predicate_from_exps(c, tmpexps, &prop, &subj,
0);
-
- //After having prop, get the corresponding column name
-
- TKNRstringToOid(&tmpPropId, &prop);
-
+
+ tmpPropId = tmpnode->poid;
+
+ assert(tmpPropId != BUN_NONE);
+
colIdx = getColIdx_from_oid(tId, global_csset, tmpPropId);
//Check whether the column is multi-valued prop
@@ -2049,7 +2040,7 @@ sql_rel* transform_inner_join_subjg (mvc
* - sp_prj_exps stores all the columns should be selected in the "original
order"
* */
static
-sql_rel* build_rdfscan (mvc *c, jgraph *jg, int tId, int ncol, int nijgroup,
int **ijgroup, int *nnodes_per_ijgroup){
+sql_rel* build_rdfexception (mvc *c, jgraph *jg, int tId, int ncol, int
nijgroup, int **ijgroup, int *nnodes_per_ijgroup){
sql_rel *rel_rdfscan = NULL;
str tblname;
@@ -2085,24 +2076,115 @@ sql_rel* build_rdfscan (mvc *c, jgraph *
for (gr = 0; gr < nijgroup; gr++){
for (i = 0; i < nnodes_per_ijgroup[gr]; i++){
int nodeid = ijgroup[gr][i];
- sql_rel *tmprel = (sql_rel*)
(jg->lstnodes[nodeid]->data);
+ jgnode *tmpnode = jg->lstnodes[nodeid];
+ sql_rel *tmprel = (sql_rel*) (tmpnode->data);
int colIdx;
int isMVcol = 0;
- list *tmpexps = NULL;
- str prop;
- str subj;
oid tmpPropId;
assert(tmprel->op == op_select);
assert(((sql_rel*)tmprel->l)->op == op_basetable);
- tmpexps = tmprel->exps;
-
- if (tmpexps) get_predicate_from_exps(c, tmpexps, &prop,
&subj, 0);
-
- //After having prop, get the corresponding column name
-
- TKNRstringToOid(&tmpPropId, &prop);
+ tmpPropId = tmpnode->poid;
+
+ colIdx = getColIdx_from_oid(tId, global_csset,
tmpPropId);
+
+ //Check whether the column is multi-valued prop
+ isMVcol = isMVCol(tId, colIdx, global_csset);
+
+ //Only for RDFscan, otherwise we need to handle
Multi-valued prop
+ tranforms_exps(c, tmprel, trans_select_exps,
trans_table_exps, tblname, colIdx, tmpPropId, &atblname, &asubjcolname, NULL,
NULL, 0);
+
+ if (isMVcol == 0){
+ num_nonMV_col++;
+ }
+ else{
+ num_mv_col++;
+ }
+ }
+ }
+
+ sprintf(tmp, "[RDFscan] select exprs: ");
+ exps_print_ext(c, trans_select_exps, 0, tmp);
+ sprintf(tmp, " base table expression: \n");
+ exps_print_ext(c, trans_table_exps, 0, tmp);
+
+
+
+ rel_basetbl = rel_basetable(c, get_rdf_table(c,tblname), tblname);
+
+ rel_basetbl->exps = trans_table_exps;
+
+ if (num_mv_col > 0) r_r_prop->containMV = 1;
+
+ rel_rdfscan = rel_rdfscan_create(c->sa, rel_basetbl, trans_select_exps,
r_r_prop);
+
+
+ list_destroy(trans_select_exps);
+
+ return rel_rdfscan;
+
+}
+
+
+/*
+ * Input:
+ * - A sub-join graph (jsg) that all nodes are connected by using inner join
+ * - The table (tId) that the node belongs to has been identified
+ * (The table corresponding to the star pattern is known)
+ *
+ * Output:
+ * - A select from a relational table with list of columns. Or a join between
+ * select from a table and mv_table if there is mv prop.
+ * - sp_prj_exps stores all the columns should be selected in the "original
order"
+ * */
+static
+sql_rel* build_rdfscan (mvc *c, jgraph *jg, int tId, int ncol, int nijgroup,
int **ijgroup, int *nnodes_per_ijgroup){
+
+ sql_rel *rel_rdfscan = NULL;
+ str tblname;
+ oid tblnameoid;
+ str atblname = NULL; //alias for table of sp
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list