Changeset: 0fef9fe5a950 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0fef9fe5a950 Modified Files: monetdb5/extras/rdf/rdftypes.c monetdb5/extras/rdf/rdftypes.h sql/backends/monet5/sql_rdf.c sql/backends/monet5/sql_rdf.h sql/backends/monet5/sql_rdf.mal sql/backends/monet5/sql_rdf_jgraph.c sql/scripts/30_rdf.sql Branch: rdf Log Message:
Handling comparision with datetime in the sparql query diffs (169 lines): diff --git a/monetdb5/extras/rdf/rdftypes.c b/monetdb5/extras/rdf/rdftypes.c --- a/monetdb5/extras/rdf/rdftypes.c +++ b/monetdb5/extras/rdf/rdftypes.c @@ -447,6 +447,34 @@ int convertDateTimeToTimeT(char *sDateTi return 0; } + +void convertTimestampToLong(timestamp *ts, lng *t){ + + int positiveDate = 0; + int sign = 0; + lng encodeLng = 0; + + //Encoding timestamp to lng. + //First 4 bits are not used, 5th bits for sign of number of days value + //(1, if the number of days is negative) + //27 bits for days, 32 bits for msecs + if (ts->days < 0){ + positiveDate = 0 - ts->days; + sign = 1; + } else { + positiveDate = ts->days; + sign = 0; + } + + encodeLng |= (lng) positiveDate; + encodeLng = encodeLng << (sizeof(ts->msecs) * 8); //Move 32 bits + encodeLng |= (lng)sign << (sizeof(lng) * 8 - 5); //Set the sign bit + encodeLng = encodeLng | (lng) ts->msecs; //Set 32 bits for msecs + + *t = encodeLng; + + +} /* * Using/extending monetdb mtime functions * */ @@ -455,9 +483,7 @@ int convertDateTimeToLong(char *sDateTim timestamp *ts = NULL; //tzone *tz; int len, pos = 0; - lng encodeLng = 0; - int positiveDate = 0; - int sign = 0; + char *p = NULL; @@ -501,24 +527,7 @@ int convertDateTimeToLong(char *sDateTim return 0; } - //Encoding timestamp to lng. - //First 4 bits are not used, 5th bits for sign of number of days value - //(1, if the number of days is negative) - //27 bits for days, 32 bits for msecs - if (ts->days < 0){ - positiveDate = 0 - ts->days; - sign = 1; - } else { - positiveDate = ts->days; - sign = 0; - } - - encodeLng |= (lng) positiveDate; - encodeLng = encodeLng << (sizeof(ts->msecs) * 8); //Move 32 bits - encodeLng |= (lng)sign << (sizeof(lng) * 8 - 5); //Set the sign bit - encodeLng = encodeLng | (lng) ts->msecs; //Set 32 bits for msecs - - *t = encodeLng; + convertTimestampToLong(ts, t); //printf("Encode string %s with days %d and msecs %d to lng %ld \n",sDateTime, ts->days, ts->msecs, *t); if (ts) GDKfree(ts); diff --git a/monetdb5/extras/rdf/rdftypes.h b/monetdb5/extras/rdf/rdftypes.h --- a/monetdb5/extras/rdf/rdftypes.h +++ b/monetdb5/extras/rdf/rdftypes.h @@ -90,6 +90,9 @@ get_encodedOid_from_atom(atom *at, oid * rdf_export int convertDateTimeToTimeT(char *sDateTime, int len, time_t *t); +rdf_export void +convertTimestampToLong(timestamp *ts, lng *t); + rdf_export int convertDateTimeToLong(char *sDateTime, lng *t); 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 @@ -1479,6 +1479,21 @@ SQLrdfstrtoid(oid *ret, str *s){ return msg; } +str +SQLrdftimetoid(oid *ret, str *datetime){ + + lng tmp = BUN_NONE; + ValRecord vrec; + + convertDateTimeToLong(*datetime, &tmp); + + VALset(&vrec,TYPE_lng, &tmp); + + encodeValueInOid(&vrec, DATETIME, ret); + + return MAL_SUCCEED; +} + #endif str 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 @@ -48,6 +48,10 @@ sql5_export str SQLrdfdeserialize(Client sql5_export str SQLrdfidtostr(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str SQLrdfidtostr_bat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export str SQLrdfstrtoid(oid *ret, str *s); + +sql5_export str SQLrdftimetoid(oid *ret, str *dt); + + //sql5_export str SQLrdfstrtoid(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); sql5_export void getTblSQLname(char *tmptbname, int tblIdx, int isExTbl, oid tblname, BATiter mapi, BAT *mbat); sql5_export void getColSQLname(char *tmpcolname, int colIdx, int colType, oid propid, BATiter mapi, BAT *mbat); diff --git a/sql/backends/monet5/sql_rdf.mal b/sql/backends/monet5/sql_rdf.mal --- a/sql/backends/monet5/sql_rdf.mal +++ b/sql/backends/monet5/sql_rdf.mal @@ -58,6 +58,10 @@ command rdfstrtoid(urlstr:str):oid address SQLrdfstrtoid comment "Convert from string to encoded id"; +command rdftimetoid(dt:str):oid +address SQLrdftimetoid +comment "Convert from date time to encoded id"; + #x:oid contains list of property, their lower bound, their upper bound (if these bounds exist) pattern rdfscan{unsafe}(nprop:int, nrqrop:int, x:oid...)(:bat[:oid,:any]...) address SQLrdfScan 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 @@ -885,6 +885,11 @@ void _add_join_edges(jgraph *jg, sql_rel l = tmpexp->l; r = tmpexp->r; + + //About the case "oid[s14_t4.o] < sys.sql_add(s14_t3.o, oid "120@0")" + //e.g., q5 bsbm, just ignore + if (l->type != e_column && r->type != e_column) continue; + assert(l->type == e_column); assert(r->type == e_column); printf("Join: [Table]%s.[Column]%s == [Table]%s.[Column]%s \n", l->rname, l->name, r->rname, r->name); diff --git a/sql/scripts/30_rdf.sql b/sql/scripts/30_rdf.sql --- a/sql/scripts/30_rdf.sql +++ b/sql/scripts/30_rdf.sql @@ -65,6 +65,9 @@ create function rdf_idtostr(id oid) create function rdf_strtoid(urlstr string) returns oid external name sql.rdfstrtoid; +create function rdf_timetoid(datetime string) + returns oid external name sql.rdftimetoid; + create function tkzr_strtoid(urlstr string) returns oid external name tokenizer.locate; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list