Changeset: 8ec91dfb1c38 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8ec91dfb1c38
Modified Files:
monetdb5/extras/rdf/rdf.h
monetdb5/extras/rdf/rdfalgebra.c
monetdb5/extras/rdf/rdfalgebra.mal
monetdb5/modules/mal/tokenizer.c
monetdb5/modules/mal/tokenizer.h
monetdb5/modules/mal/tokenizer.mal
Branch: Feb2013
Log Message:
Move the function TKNZRrdf2str from tokenizer to RDF module
This function is only used for RDF thus it is moved to RDF module.
diffs (223 lines):
diff --git a/monetdb5/extras/rdf/rdf.h b/monetdb5/extras/rdf/rdf.h
--- a/monetdb5/extras/rdf/rdf.h
+++ b/monetdb5/extras/rdf/rdf.h
@@ -50,6 +50,10 @@ RDFleftfetchjoin_sortedestimate(int *res
rdf_export str
RDFleftfetchjoin_sorted(int *result, int* lid, int *rid);
+rdf_export str
+TKNZRrdf2str (bat *res, bat *bid, bat *map);
+
+#define RDF_MIN_LITERAL (((oid) 1) << ((sizeof(oid)==8)?62:30))
#define TRIPLE_STORE 1
#define MLA_STORE 2
diff --git a/monetdb5/extras/rdf/rdfalgebra.c b/monetdb5/extras/rdf/rdfalgebra.c
--- a/monetdb5/extras/rdf/rdfalgebra.c
+++ b/monetdb5/extras/rdf/rdfalgebra.c
@@ -23,6 +23,7 @@
#include "rdf.h"
#include "algebra.h"
#include <gdk.h>
+#include "tokenizer.h"
str
RDFleftfetchjoin_sorted(bat *result, bat *lid, bat *rid)
@@ -50,3 +51,66 @@ RDFleftfetchjoin_sorted(bat *result, bat
BBPkeepref(*result);
return MAL_SUCCEED;
}
+
+
+str
+TKNZRrdf2str(bat *res, bat *bid, bat *map)
+{
+ BAT *r, *b, *m;
+ BATiter bi, mi;
+ BUN p, q;
+ str s = NULL;
+
+ b = BATdescriptor(*bid);
+ if (b == NULL) {
+ throw(MAL, "rdf.rdf2str", RUNTIME_OBJECT_MISSING " null bat b");
+ }
+ m = BATdescriptor(*map);
+ if (m == NULL) {
+ BBPunfix(*bid);
+ throw(MAL, "rdf.rdf2str", RUNTIME_OBJECT_MISSING "null bat m");
+ }
+ if (!BAThdense(b)) {
+ BBPunfix(*bid);
+ BBPunfix(*map);
+ throw(MAL, "rdf.rdf2str", SEMANTIC_TYPE_ERROR " semantic
error");
+ }
+ r = BATnew(TYPE_void, TYPE_str, BATcount(b));
+ if (r == NULL) {
+ BBPunfix(*bid);
+ BBPunfix(*map);
+ throw(MAL, "rdf.rdf2str", RUNTIME_OBJECT_MISSING "null bat r");
+ }
+ *res = r->batCacheid;
+ BATseqbase(r, b->hseqbase);
+ bi = bat_iterator(b);
+ mi = bat_iterator(m);
+
+ BATloop(b, p, q)
+ {
+ oid id = *(oid *) BUNtloc(bi, p);
+ if (id >= RDF_MIN_LITERAL) {
+ BUN pos = BUNfirst(m) + (id - RDF_MIN_LITERAL);
+ if (pos < BUNfirst(m) || pos >= BUNlast(m)) {
+ BBPunfix(*bid);
+ BBPunfix(*map);
+ BBPunfix(*res);
+ throw(MAL, "rdf.rdf2str", OPERATION_FAILED "
illegal oid");
+ }
+ s = (str) BUNtail(mi, pos);
+ } else {
+ str ret = takeOid(id, &s);
+ if (ret != MAL_SUCCEED) {
+ BBPunfix(*bid);
+ BBPunfix(*map);
+ BBPunfix(*res);
+ return ret;
+ }
+ }
+ BUNappend(r, s, FALSE);
+ }
+ BBPunfix(*bid);
+ BBPunfix(*map);
+ BBPkeepref(*res);
+ return MAL_SUCCEED;
+}
diff --git a/monetdb5/extras/rdf/rdfalgebra.mal
b/monetdb5/extras/rdf/rdfalgebra.mal
--- a/monetdb5/extras/rdf/rdfalgebra.mal
+++ b/monetdb5/extras/rdf/rdfalgebra.mal
@@ -20,3 +20,7 @@ module rdf;
command leftfetchjoin_sorted ( left:bat[:any_1,:oid], right:bat[:oid,:any_3] )
:bat[:any_1,:any_3]
address RDFleftfetchjoin_sorted
comment "like algebra_leftfetchjoin(), but asserts that the resulting tail
column is sorted -- ONLY USE IF YOU ARE SURE OF THIS!!! also requires sorted
tail left input"
+
+command rdf2str(i:bat[:oid,:oid],map:bat[:oid,:str]):bat[:oid,:str]
+address TKNZRrdf2str
+comment "converts id's into strings using the dictionary, but if (id >=
RDF_MIN_LITERAL) look it up in a literal map bat";
diff --git a/monetdb5/modules/mal/tokenizer.c b/monetdb5/modules/mal/tokenizer.c
--- a/monetdb5/modules/mal/tokenizer.c
+++ b/monetdb5/modules/mal/tokenizer.c
@@ -448,7 +448,7 @@ TKNZRlocate(Client cntxt, MalBlkPtr mb,
return MAL_SUCCEED;
}
-static str
+str
takeOid(oid id, str *val)
{
int i, depth;
@@ -505,68 +505,6 @@ TKNZRtakeOid(Client cntxt, MalBlkPtr mb,
}
str
-TKNZRrdf2str(bat *res, bat *bid, bat *map)
-{
- BAT *r, *b, *m;
- BATiter bi, mi;
- BUN p, q;
- str s = NULL;
-
- b = BATdescriptor(*bid);
- if (b == NULL) {
- throw(MAL, "tokenizer.rdf2str", RUNTIME_OBJECT_MISSING " null
bat b");
- }
- m = BATdescriptor(*map);
- if (m == NULL) {
- BBPunfix(*bid);
- throw(MAL, "tokenizer.rdf2str", RUNTIME_OBJECT_MISSING "null
bat m");
- }
- if (!BAThdense(b)) {
- BBPunfix(*bid);
- BBPunfix(*map);
- throw(MAL, "tokenizer.rdf2str", SEMANTIC_TYPE_ERROR " semantic
error");
- }
- r = BATnew(TYPE_void, TYPE_str, BATcount(b));
- if (r == NULL) {
- BBPunfix(*bid);
- BBPunfix(*map);
- throw(MAL, "tokenizer.rdf2str", RUNTIME_OBJECT_MISSING "null
bat r");
- }
- *res = r->batCacheid;
- BATseqbase(r, b->hseqbase);
- bi = bat_iterator(b);
- mi = bat_iterator(m);
-
- BATloop(b, p, q)
- {
- oid id = *(oid *) BUNtloc(bi, p);
- if (id >= RDF_MIN_LITERAL) {
- BUN pos = BUNfirst(m) + (id - RDF_MIN_LITERAL);
- if (pos < BUNfirst(m) || pos >= BUNlast(m)) {
- BBPunfix(*bid);
- BBPunfix(*map);
- BBPunfix(*res);
- throw(MAL, "tokenizer.rdf2str",
OPERATION_FAILED " illegal oid");
- }
- s = (str) BUNtail(mi, pos);
- } else {
- str ret = takeOid(id, &s);
- if (ret != MAL_SUCCEED) {
- BBPunfix(*bid);
- BBPunfix(*map);
- BBPunfix(*res);
- return ret;
- }
- }
- BUNappend(r, s, FALSE);
- }
- BBPunfix(*bid);
- BBPunfix(*map);
- BBPkeepref(*res);
- return MAL_SUCCEED;
-}
-
-str
TKNZRgetIndex(int *r)
{
if (TRANS == NULL)
diff --git a/monetdb5/modules/mal/tokenizer.h b/monetdb5/modules/mal/tokenizer.h
--- a/monetdb5/modules/mal/tokenizer.h
+++ b/monetdb5/modules/mal/tokenizer.h
@@ -22,8 +22,6 @@
#include "mal_client.h"
#include "mal_interpreter.h"
-#define RDF_MIN_LITERAL (((oid) 1) << ((sizeof(oid)==8)?62:30))
-
#ifdef WIN32
#if !defined(LIBMAL) && !defined(LIBATOMS) && !defined(LIBKERNEL) &&
!defined(LIBMAL) && !defined(LIBOPTIMIZER) && !defined(LIBSCHEDULER) &&
!defined(LIBMONETDB5)
#define tokenizer_export extern __declspec(dllimport)
@@ -39,11 +37,11 @@ tokenizer_export str TKNZRclose
tokenizer_export str TKNZRappend (oid *pos, str *tuple);
tokenizer_export str TKNZRlocate (Client cntxt, MalBlkPtr mb,
MalStkPtr stk, InstrPtr pci);
tokenizer_export str TKNZRtakeOid (Client cntxt, MalBlkPtr mb,
MalStkPtr stk, InstrPtr pci);
-tokenizer_export str TKNZRrdf2str (bat *res, bat *bid, bat *map);
tokenizer_export str TKNZRdepositFile (int *r, str *fnme);
tokenizer_export str TKNZRgetLevel (int *r, int *level);
tokenizer_export str TKNZRgetIndex (int *r);
tokenizer_export str TKNZRgetCount (int *r);
tokenizer_export str TKNZRgetCardinality (int *r);
+tokenizer_export str takeOid (oid id, str *val);
#endif /* _TKNZR_H */
diff --git a/monetdb5/modules/mal/tokenizer.mal
b/monetdb5/modules/mal/tokenizer.mal
--- a/monetdb5/modules/mal/tokenizer.mal
+++ b/monetdb5/modules/mal/tokenizer.mal
@@ -14,10 +14,6 @@ pattern take(i:oid):str
address TKNZRtakeOid
comment "reconstruct and returns the i-th string";
-command rdf2str(i:bat[:oid,:oid],map:bat[:oid,:str]):bat[:oid,:str]
-address TKNZRrdf2str
-comment "converts id's into strings using the dictionary, but if (id >=
RDF_MIN_LITERAL) look it up in a literal map bat";
-
pattern locate(s:str):oid
address TKNZRlocate
comment "if the given string is in the store returns its oid, otherwise
oid_nil";
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list