Changeset: 92fc4509f26d for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=92fc4509f26d Modified Files: sql/backends/monet5/sql_rdf.c sql/backends/monet5/sql_rdf.h sql/backends/monet5/sql_rdf_jgraph.c sql/backends/monet5/sql_rdf_jgraph.h Branch: rdf Log Message:
Get constraint values on o diffs (truncated from 417 to 300 lines): diff --git a/sql/backends/monet5/sql_rdf.c b/sql/backends/monet5/sql_rdf.c --- a/sql/backends/monet5/sql_rdf.c +++ b/sql/backends/monet5/sql_rdf.c @@ -1631,6 +1631,10 @@ void combine_exception_and_regular_table oid **regular_obat_cursors = NULL; oid **regular_obat_mv_cursors = NULL; //If this column is MV col, then store the point to its MV BAT int accept = 0; + #if RDF_HANDLING_EXCEPTION_MISSINGPROP_OPT + int *lst_missing_props = NULL; //Index of missing prop in the lstProp + int num_mp = 0; //Number of missing prop + #endif (void) r_sbat; (void) r_obats; @@ -1645,6 +1649,11 @@ void combine_exception_and_regular_table setBasicProps((*r_obats)[i]); } + #if RDF_HANDLING_EXCEPTION_MISSINGPROP_OPT + lst_missing_props = (int *) malloc(sizeof(int) * nP); + num_mp = 0; + #endif + sbatCursor = (oid *) Tloc(sbat, BUNfirst(sbat)); obatCursors = (oid **) malloc(sizeof(oid*) * nP); @@ -1674,6 +1683,9 @@ void combine_exception_and_regular_table oid tmpS = BUN_NONE; getTblIdxFromS(sbt, &tid, &tmpS); if (tid != curtid){ + #if RDF_HANDLING_EXCEPTION_MISSINGPROP_OPT + num_mp = 0; + #endif //reload BATs for that table for (j = 0; j < nP; j++){ str tmpColname, tmptblname, tmpmvtblname, tmpmvdefcolname; @@ -1683,6 +1695,10 @@ void combine_exception_and_regular_table regular_obat_mv[j] = NULL; regular_obat_cursors[j] = NULL; regular_obat_mv_cursors[j] = NULL; + #if RDF_HANDLING_EXCEPTION_MISSINGPROP_OPT + lst_missing_props[num_mp] = j; + num_mp++; + #endif continue; } @@ -1716,6 +1732,15 @@ void combine_exception_and_regular_table //printf("At row "BUNFMT" of table %d for sbt "BUNFMT"...", tmpS, tid, sbt); accept = 1; + #if RDF_HANDLING_EXCEPTION_MISSINGPROP_OPT + for (j = 0; j < num_mp; j++){ + if (obatCursors[lst_missing_props[j]][pos] == oid_nil){ + accept = 0; + break; + } + } + if (accept == 0) continue; + #endif for (j = 0; j < nP; j++){ if (obatCursors[j][pos] == oid_nil){ if (regular_obat_cursors[j] == NULL){ //No corresponding regular column @@ -1778,20 +1803,22 @@ SQLrdfScan(Client cntxt, MalBlkPtr mb, M oid *lstProps = NULL; int i; //int *lstbattypes = NULL; - + clock_t sT; + clock_t eT; (void) cntxt; (void) mb; (void) stk; (void) pci; - + sT = clock(); + nP = (int *) getArgReference(stk, pci, pci->retc + 0); nRP = (int *) getArgReference(stk, pci, pci->retc + 1); nRet = 2 * (*nP); (void) nRP; - + assert (pci->retc == nRet); b = (BAT **) GDKmalloc (sizeof (BAT*) * pci->retc); @@ -1825,17 +1852,21 @@ SQLrdfScan(Client cntxt, MalBlkPtr mb, M mvc *m = NULL; str msg; BAT *pso_fullSbat = NULL, *pso_fullObat = NULL; - - + clock_t sT1, eT1; + + sT1 = clock(); rethrow("sql.rdfShred", msg, getSQLContext(cntxt, mb, &m, NULL)); pso_fullSbat = mvc_bind(m, schema, "pso", "s",0); pso_fullObat = mvc_bind(m, schema, "pso", "o",0); get_full_outerjoin_p_slices(lstProps, *nP, pso_fullObat, pso_fullSbat, &r_sbat, &r_obats); - + + eT1 = clock(); + printf("Step 1 in Handling exception took %f seconds.\n", ((float)(eT1 - sT1))/CLOCKS_PER_SEC); //Step 2. Merge exceptions with Tables + sT1 = clock(); combine_exception_and_regular_tables(m, &m_sbat, &m_obats, r_sbat, r_obats, lstProps, *nP, *nRP); @@ -1846,12 +1877,19 @@ SQLrdfScan(Client cntxt, MalBlkPtr mb, M b[2*i] = BATcopy(m_sbat, m_sbat->htype, m_sbat->ttype, FALSE, TRANSIENT); b[2*i+1] = BATcopy(m_obats[i], m_obats[i]->htype, m_obats[i]->ttype, FALSE, TRANSIENT); } + + eT1 = clock(); + printf("Step 2 in Handling exception took %f seconds.\n", ((float)(eT1 - sT1))/CLOCKS_PER_SEC); + } printf("Return the resusting BATs..."); bat2return(stk, pci, b); printf("... done\n"); GDKfree(b); + eT = clock(); + printf("RDFscan for handling exception took %f seconds.\n", ((float)(eT - sT))/CLOCKS_PER_SEC); + return MAL_SUCCEED; } diff --git a/sql/backends/monet5/sql_rdf.h b/sql/backends/monet5/sql_rdf.h --- a/sql/backends/monet5/sql_rdf.h +++ b/sql/backends/monet5/sql_rdf.h @@ -70,4 +70,6 @@ extern PsoPropStat *pso_propstat; #define HANDLING_EXCEPTION 1 +#define RDF_HANDLING_EXCEPTION_MISSINGPROP_OPT 1 + #endif /*_SQL_RDF_H */ 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 @@ -1093,12 +1093,18 @@ spProps *init_sp_props(int num){ spprops->subj = BUN_NONE; spprops->lstProps = (char **) GDKmalloc(sizeof(char *) * num); spprops->lstPropIds = (oid *) GDKmalloc(sizeof(oid) * num); + spprops->lst_o_constraints = (o_constraint *) GDKmalloc(sizeof(o_constraint) * num); + spprops->lstPOs = (sp_po *) GDKmalloc(sizeof(sp_po) * num); for (i = 0; i < num; i++){ spprops->lstProps[i] = NULL; spprops->lstPropIds[i] = BUN_NONE; + spprops->lst_o_constraints[i].cmp_type = -1; + spprops->lst_o_constraints[i].low = BUN_NONE; + spprops->lst_o_constraints[i].hi = BUN_NONE; + + spprops->lstPOs[i] = NAV; } - spprops->lstPOs = (sp_po *) GDKmalloc(sizeof(sp_po) * num); spprops->lstctype = (ctype *) GDKmalloc(sizeof(ctype) * num); return spprops; @@ -1133,9 +1139,17 @@ static void print_spprops(spProps *spprops){ int i; - printf("List of properties: \n"); + printf("List of properties from spProps: \n"); for (i = 0; i < spprops->num; i++){ - printf("%s (Id: "BUNFMT ")\n" ,spprops->lstProps[i], spprops->lstPropIds[i]); + printf("%s (Id: "BUNFMT "): " ,spprops->lstProps[i], spprops->lstPropIds[i]); + if (spprops->lstPOs[i] == REQUIRED) printf("[REQUIRED]"); + else printf("[NAV]"); + + if (spprops->lst_o_constraints[i].low != BUN_NONE) printf(" [low = "BUNFMT"]", spprops->lst_o_constraints[i].low); + if (spprops->lst_o_constraints[i].hi != BUN_NONE) printf(" [hi = "BUNFMT"]", spprops->lst_o_constraints[i].hi); + + printf("\n"); + } printf("\n"); } @@ -1150,6 +1164,7 @@ void free_sp_props(spProps *spprops){ GDKfree(spprops->lstPropIds); GDKfree(spprops->lstPOs); GDKfree(spprops->lstctype); + GDKfree(spprops->lst_o_constraints); GDKfree(spprops); } @@ -1180,6 +1195,7 @@ void get_col_name_from_p (char **col, ch * * */ + static void modify_exp_col(mvc *c, sql_exp *m_exp, char *_rname, char *_name, char *_arname, char *_aname, int update_e_convert, int dummy_exps){ sql_exp *tmpe = NULL; @@ -1245,6 +1261,7 @@ void modify_exp_col(mvc *c, sql_exp *m_e } + /* * oid[sys.rdf_strtoid(char(67) "<http://www/product>")] * UPDATE: sys.rdf_strtoid(char(67) "<http://www/product>") @@ -1257,9 +1274,14 @@ void extractURI_from_exp(mvc *c, char ** node *tmpen; str s; list *lst = NULL; + char *funcname; assert(exp->type == e_func); + funcname = ((sql_subfunc *)exp->f)->func->base.name; + + assert(strcmp(funcname, "rdf_strtoid") == 0); + lst = exp->l; //There should be only one parameter for the function which is the property name @@ -1274,6 +1296,42 @@ void extractURI_from_exp(mvc *c, char ** } +static +void get_o_constraint_value(mvc *c, sql_exp *m_exp, oid *tmpvalue){ + oid newoid; + sql_exp *re = m_exp->r; + + assert(m_exp->type == e_cmp); + + //first: Convert the compared value into oid + newoid = BUN_NONE; + if (re->type == e_atom){ + atom *at = re->l; + assert(at != NULL); + + get_encodedOid_from_atom(at, &newoid); + } else if (re->type == e_func) { + //Check whether this is the function of rdf_strtoid + char *funcname = ((sql_subfunc *)re->f)->func->base.name; + str uri = NULL; + + if (strcmp(funcname, "rdf_strtoid") == 0){ + extractURI_from_exp(c, &uri, re); + TKNRstringToOid(&newoid, &uri); + assert (newoid != BUN_NONE); + + } else { + printf("TODO: The function %s is not handled yet\n", funcname); + } + } else { + printf("TODO: This is not handled yet\n"); + } + + *tmpvalue = newoid; +} + + + /* * //Example: [s12_t0.p = oid[sys.rdf_strtoid(char(67) "<http://www/product>")], s12_t0.o = oid[sys.rdf_strtoid(char(85) "<http://www/Product9>"] * // UPDATED: Example: [oid[s12_t0.p] = sys.rdf_strtoid(char(67) "<http://www/product>"), oid[s12_t0.o] = sys.rdf_strtoid(char(85) "<http://www/Product9>" @@ -1356,6 +1414,59 @@ void verify_rel(sql_rel *r){ assert(select_s && select_p && select_o); } +static +void get_o_constraint(mvc *c, o_constraint *o_cst, list *exps){ + node *en; + for (en = exps->h; en; en = en->next){ + sql_exp *tmpexp = (sql_exp *) en->data; + sql_exp *e = (sql_exp *)tmpexp->l; + + assert(tmpexp->type == e_cmp); //TODO: Handle other exps for op_select + assert(e->type == e_convert); + + e = e->l; + + assert(e->type == e_column); + + if (strcmp(e->name, "o") == 0){ + int cmp = get_cmp(tmpexp); + oid tmp_o_value = BUN_NONE; + get_o_constraint_value(c, tmpexp, &tmp_o_value); + + o_cst->cmp_type = cmp; + + switch(cmp) { + case cmp_equal: + o_cst->low = tmp_o_value; + o_cst->hi = tmp_o_value; + break; + case cmp_gt: _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list