Changeset: 88a8b34c0b5e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=88a8b34c0b5e
Modified Files:
monetdb5/extras/rdf/rdfschema.c
sql/backends/monet5/sql.mx
Branch: rdf
Log Message:
Fix the bug in assigning new Id for each subject
diffs (159 lines):
diff --git a/monetdb5/extras/rdf/rdfschema.c b/monetdb5/extras/rdf/rdfschema.c
--- a/monetdb5/extras/rdf/rdfschema.c
+++ b/monetdb5/extras/rdf/rdfschema.c
@@ -3034,12 +3034,14 @@ BAT* getOriginalOBat(BAT *obat){
}
static
-int getTblidFromSoid(oid Soid){
- int freqCSid;
+void getTblidFromSoid(oid Soid, int *tbidx, oid *baseSoid){
+ //int freqCSid;
- freqCSid = (int) ((Soid >> (sizeof(BUN)*8 - NBITS_FOR_CSID)) & ((1 <<
(NBITS_FOR_CSID-1)) - 1)) ;
+ *tbidx = (int) ((Soid >> (sizeof(BUN)*8 - NBITS_FOR_CSID)) & ((1 <<
(NBITS_FOR_CSID-1)) - 1)) ;
+
+ *baseSoid = Soid - ((oid) (*tbidx) << (sizeof(BUN)*8 - NBITS_FOR_CSID));
- return freqCSid;
+ //return freqCSid;
}
static
@@ -3219,7 +3221,8 @@ str RDFdistTriplesToCSs(int *ret, bat *s
BUN p,q;
oid *pbt, *sbt, *obt;
oid lastP, lastS;
- int tblIdx;
+ int tblIdx = -1;
+ oid tmpSoid = BUN_NONE;
BUN ppos;
int* tmpTblIdxPropIdxMap; //For each property, this maps the
table Idx (in the posting list
// of that property to the position of
that property in the
@@ -3228,7 +3231,8 @@ str RDFdistTriplesToCSs(int *ret, bat *s
int tmpColIdx = -1;
BUN bun;
int i,j;
-
+ BAT *curBat;
+
(void) bun;
//BAT** setofBats = NULL;
@@ -3292,15 +3296,17 @@ str RDFdistTriplesToCSs(int *ret, bat *s
}
}
- tblIdx = getTblidFromSoid(*sbt);
+ getTblidFromSoid(*sbt, &tblIdx, &tmpSoid);
tmpColIdx = tmpTblIdxPropIdxMap[tblIdx];
printf(BUNFMT": Table %d | column %d for prop " BUNFMT " | sub
" BUNFMT " | obj " BUNFMT "\n",p, tblIdx,
- tmpColIdx, *pbt, *sbt,
*obt);
+ tmpColIdx, *pbt,
tmpSoid, *obt);
//TODO: Check last subjectId for this prop. If the subjectId is
not continuous, insert NIL
- BUNappend(cstablestat->lstcstable[tblIdx].colBats[tmpColIdx],
obt, TRUE);
+ curBat = cstablestat->lstcstable[tblIdx].colBats[tmpColIdx];
+
+ BUNappend(curBat, obt, TRUE);
}
//Keep the batCacheId
@@ -3365,7 +3371,7 @@ RDFreorganize(int *ret, CStableStat *cst
initCStablesAndIdxMapping(cstablestat, freqCSset, csTblIdxMapping,
mfreqIdxTblIdxMapping, mTblIdxFreqIdxMapping);
lastSubjId = (oid *) malloc (sizeof(oid) * cstablestat->numTables);
- initArray(lastSubjId, cstablestat->numTables, 0);
+ initArray(lastSubjId, cstablestat->numTables, -1);
if ((sbat = BATdescriptor(*sbatid)) == NULL) {
throw(MAL, "rdf.RDFreorganize", RUNTIME_OBJECT_MISSING);
@@ -3417,22 +3423,23 @@ RDFreorganize(int *ret, CStableStat *cst
if (tblIdx != BUN_NONE){
- newId = lastSubjId[tblIdx];
- newId |= (BUN)tblIdx << (sizeof(BUN)*8 -
NBITS_FOR_CSID);
-
if (lastS != *sbt){ //new subject
lastS = *sbt;
+ newId = lastSubjId[tblIdx] + 1;
+ newId |= (BUN)tblIdx << (sizeof(BUN)*8 -
NBITS_FOR_CSID);
+
l = *sbt;
r = newId;
lmap = BUNappend(lmap, &l, TRUE);
rmap = BUNappend(rmap, &r, TRUE);
- lastSubjId[tblIdx]++;
+
+ lastSubjId[tblIdx] = newId;
}
}
- else{ // Use original subject Id
+ else{ // Does not belong to a freqCS. Use original subject Id
newId = *sbt;
}
diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -7595,6 +7595,11 @@ SQLrdfreorganize(Client cntxt, MalBlkPtr
sql_schema *sch;
int ret = 0;
CStableStat *cstablestat;
+ char tmptbname[100];
+ char tmpcolname[100];
+ sql_subtype tpe;
+ sql_table **cstables;
+ int i, j;
str msg;
BAT *sbat, *pbat, *obat, *mbat;
@@ -7615,6 +7620,34 @@ SQLrdfreorganize(Client cntxt, MalBlkPtr
&obat->batCacheid, &mbat->batCacheid,
threshold));
+ cstables = (sql_table **)malloc(sizeof(sql_table*) *
cstablestat->numTables);
+
+ // Put to SQL tables
+ sql_find_subtype(&tpe, "oid", 31, 0);
+
+ for (i = 0; i < cstablestat->numTables; i++){
+ sprintf(tmptbname, "cstable%d",i);
+ cstables[i] = mvc_create_table(m, sch, tmptbname, tt_table, 0,
+ SQL_PERSIST, 0, 3);
+
+ for (j = 0; j < cstablestat->numPropPerTable[i]; j++){
+ //TODO: Use propertyId from Propstat
+ sprintf(tmpcolname, "col%d",j);
+ mvc_create_column(m, cstables[i], tmpcolname, &tpe);
+ printf("Create column for %d for table %d \n", j, i);
+ }
+
+ //Add data
+ for (j = 0; j < cstablestat->numPropPerTable[i]; j++){
+ sprintf(tmpcolname, "col%d",j);
+ store_funcs.append_col(m->session->tr,
+ mvc_bind_column(m,
cstables[i],tmpcolname ),
+ cstablestat->lstcstable[i].colBats[j],
TYPE_bat);
+
+ printf("Create column for %d for table %d - sizeofbat "
BUNFMT " \n", j, i, BATcount(cstablestat->lstcstable[i].colBats[j]));
+ }
+ }
+
BBPunfix(sbat->batCacheid);
BBPunfix(pbat->batCacheid);
@@ -7622,6 +7655,7 @@ SQLrdfreorganize(Client cntxt, MalBlkPtr
BBPunfix(mbat->batCacheid);
freeCStableStat(cstablestat);
+ free(cstables);
return MAL_SUCCEED;
}
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list