Changeset: 75d54ddf0ec2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/75d54ddf0ec2
Modified Files:
gdk/gdk.h
gdk/gdk_atoms.c
gdk/gdk_atoms.h
monetdb5/modules/kernel/vss.c
sql/backends/monet5/vaults/netcdf/netcdf.c
sql/common/sql_types.c
sql/scripts/40_json.sql
sql/server/sql_parser.y
sql/server/sql_scan.c
sql/server/sql_tokens.h
sql/storage/store.c
Branch: nested
Log Message:
WIP fix block type
diffs (truncated from 566 to 300 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -163,6 +163,7 @@ enum {
TYPE_inet6,
TYPE_str,
TYPE_blob,
+ TYPE_fblock,
TYPE_any = 255, /* limit types to <255! */
};
@@ -185,6 +186,19 @@ typedef union {
uint8_t hex[16];
} inet6;
+typedef union {
+ uint32_t align; /* force alignment, only used for equality */
+ uint8_t nrows;
+ uint8_t ncols;
+ uint8_t base;
+} fblock_header;
+
+typedef union {
+ fblock_header header;
+ // only 8 pages will fit in twidth for now
+ uint8_t data[8*1024*4] __attribute__((__nonstring__));
+} fblock;
+
#define SIZEOF_OID SIZEOF_SIZE_T
typedef size_t oid;
#define OIDFMT "%zu"
@@ -1956,4 +1970,6 @@ gdk_export int ma_info(allocator *sa, ch
})
#endif
+#define FBLOCK_ON 1
+#define FBLOCK_OFF !FBLOCK_ON
#endif /* _GDK_H_ */
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -336,6 +336,7 @@ const ptr ptr_nil = NULL;
const uuid uuid_nil = {0};
const inet4 inet4_nil = {0};
const inet6 inet6_nil = {0};
+const inet6 fblock_nil = {0};
/*
* @- Atomic ADT functions
@@ -2213,6 +2214,70 @@ BLOBfromStr(allocator *ma, const char *i
return (ssize_t) (s - instr);
}
+static void *
+FBLOCKread(allocator *ma, void *U, size_t *dstlen, stream *s, size_t cnt)
+{
+ fblock *u = U;
+ if (u == NULL || *dstlen < cnt * sizeof(fblock)) {
+ if (ma) {
+ u = ma_realloc(ma, u, cnt * sizeof(fblock), *dstlen);
+ } else {
+ u = GDKmalloc(cnt * sizeof(fblock));
+ }
+ if (u == NULL)
+ return NULL;
+ }
+ if (mnstr_read(s, u, sizeof(fblock), cnt) < (ssize_t) cnt) {
+ if (ma == NULL && u != (fblock *) U)
+ GDKfree(u);
+ return NULL;
+ }
+ if (u != (fblock *) U) {
+ if (ma == NULL)
+ GDKfree(U);
+ *dstlen = cnt * sizeof(fblock);
+ }
+ return u;
+}
+
+static gdk_return
+FBLOCKwrite(const void *u, stream *s, size_t cnt)
+{
+ return mnstr_write(s, u, sizeof(fblock), cnt) ? GDK_SUCCEED : GDK_FAIL;
+}
+
+static bool
+FBLOCKeq(const void *L, const void *R)
+{
+ if (L == R)
+ return true;
+ const fblock *l = L, *r = R;
+ return memcmp(l->data, r->data, sizeof(fblock)) == 0;
+}
+
+static BUN
+FBLOCKhash(const void *v)
+{
+ const fblock *b = (const fblock *) v;
+ // TODO better hash
+ return mix_uuid((const uuid *) b->data);
+}
+
+static int
+FBLOCKcmp(const void *L, const void *R)
+{
+ const fblock *l = L, *r = R;
+ size_t litems = l->header.nrows * l->header.ncols;
+ size_t ritems = r->header.nrows * r->header.ncols;
+ if (litems == ritems)
+ return 0;
+ if (litems > ritems)
+ return 1;
+ return -1;
+}
+
+
+
atomDesc BATatoms[MAXATOMS] = {
[TYPE_void] = {
.name = "void",
@@ -2523,9 +2588,21 @@ atomDesc BATatoms[MAXATOMS] = {
.atomLen = BLOBlength,
.atomHeap = BLOBheap,
},
+ [TYPE_fblock] = {
+ .name = "fblock",
+ .storage = TYPE_fblock,
+ .linear = false,
+ .size = sizeof(fblock),
+ .atomNull = (void *) &fblock_nil,
+ .atomRead = FBLOCKread,
+ .atomWrite = FBLOCKwrite,
+ .atomEqual = FBLOCKeq,
+ .atomHash = FBLOCKhash,
+ .atomCmp = FBLOCKcmp,
+ },
};
-int GDKatomcnt = TYPE_blob + 1;
+int GDKatomcnt = TYPE_fblock + 1;
/*
* Sometimes a bat descriptor is loaded before the dynamic module
diff --git a/gdk/gdk_atoms.h b/gdk/gdk_atoms.h
--- a/gdk/gdk_atoms.h
+++ b/gdk/gdk_atoms.h
@@ -47,7 +47,7 @@ typedef struct {
char name[IDLENGTH];
uint8_t storage; /* stored as another type? */
bool linear; /* atom can be ordered linearly */
- uint16_t size; /* fixed size of atom */
+ uint32_t size; /* fixed size of atom */
/* automatically generated fields */
const void *atomNull; /* global nil value */
diff --git a/monetdb5/modules/kernel/vss.c b/monetdb5/modules/kernel/vss.c
--- a/monetdb5/modules/kernel/vss.c
+++ b/monetdb5/modules/kernel/vss.c
@@ -794,6 +794,85 @@ BONDknn(Client cntxt, MalBlkPtr mb, MalS
}
+//static str
+//process_block(fblock *blk, dbl *query_vals, size_t nrows, size_t ncols, dbl
*threshold)
+//{
+//
+//
+// return MAL_SUCCEED;
+//}
+
+static char*
+pdx(Client ctx, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ (void) ctx;
+ (void) mb;
+ //lng T0 = GDKusec();
+ bat *ret = getArgReference_bat(stk, pci, 0);
+ // data
+ BAT *b = BATdescriptor(*getArgReference_bat(stk, pci, 1));
+ size_t k = *getArgReference_int(stk, pci, 2);
+ size_t nblocks = BATcount(b);
+ (void) nblocks;
+ size_t ndims = (size_t) (pci->argc - pci->retc - 2);
+ size_t block_capacity = sizeof(fblock) / sizeof(dbl);
+ // Number of rows per block
+ size_t nrows = block_capacity / ndims;
+ (void) nrows;
+ fblock *blocks = (fblock *) Tloc(b, 0);
+ (void) blocks;
+
+ allocator *ta = MT_thread_getallocator();
+ allocator_state ta_state = ma_open(ta);
+
+ dbl *query_vals = ma_alloc(ta, ndims * sizeof(dbl));
+ // size_t len = nrows > k ? nrows : k;
+ // block candidates
+ //oid *bc = ma_alloc(ta, nrows * sizeof(oid));
+ //dbl *bd = ma_alloc(ta, nrows * sizeof(dbl));
+ oid *cands = ma_zalloc(ta, k * sizeof(oid));
+ (void) cands;
+ if (!query_vals) {
+ ma_close(&ta_state);
+ throw(MAL, "vss.pdx", MAL_MALLOC_FAIL);
+ }
+
+ for (size_t i = 0; i < ndims; i++) {
+ BAT *b = BATdescriptor(*getArgReference_bat(stk, pci, i + 3));
+ if (!b) {
+ ma_close(&ta_state);
+ throw(MAL, "vss.knn", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
+ }
+ query_vals[i] = *(dbl*)Tloc(b, 0);
+ }
+
+ // TODO process blks
+
+ BAT *bn = COLnew(0, TYPE_oid, k, TRANSIENT);
+ if (bn == NULL)
+ throw(MAL, "batvss.pdx", MAL_MALLOC_FAIL);
+
+ // Final top k
+ //{
+ // for (size_t i=0; i < k; i++) {
+ // *(oid*) Tloc(bn, i) = cands[i];
+ // }
+ //}
+
+ // Finalize BAT metadata
+ BATsetcount(bn, k);
+ bn->tnonil = true;
+ bn->tkey = false;
+ bn->tsorted = false;
+ bn->trevsorted = false;
+
+ //printf("#BATl2sq " LLFMT "\n", GDKusec() - T0);
+
+ *ret = bn->batCacheid;
+ BBPkeepref(bn);
+ return MAL_SUCCEED;
+}
+
#include "mel.h"
static mel_func vss_init_funcs[] = {
pattern("vss", "bond", BONDknn, false, "BOND k-NN search on decomposed
vector columns",
@@ -817,6 +896,12 @@ static mel_func vss_init_funcs[] = {
pattern("batvss", "l2sq_distance", BATl2sq_distance, false,
"Euclidean distanse L2",
args(1, 2, batarg("", dbl), batvararg("cols", dbl))),
+ //pattern("vss", "pdx", pdx, false,
+ // "Euclidean distanse L2",
+ // args(1, 3, arg("", oid), arg("", fblock), varargany("args",
0))),
+ pattern("batvss", "pdx", pdx, false,
+ "Euclidean distanse L2",
+ args(1, 4, batarg("", oid), batarg("", fblock), arg("k", int),
varargany("args", 0))),
{ .imp=NULL } /* sentinel */
};
diff --git a/sql/backends/monet5/vaults/netcdf/netcdf.c
b/sql/backends/monet5/vaults/netcdf/netcdf.c
--- a/sql/backends/monet5/vaults/netcdf/netcdf.c
+++ b/sql/backends/monet5/vaults/netcdf/netcdf.c
@@ -1028,7 +1028,7 @@ HDF5dataset(Client ctx, MalBlkPtr mb, Ma
nc_inq_dimlen(ncid, dimids[0], &rows);
nc_inq_dimlen(ncid, dimids[1], &cols);
- assert(cols == (size_t)pci->retc);
+ //assert(cols == (size_t)pci->retc);
//printf("Dataset 'train' has dimensions: %zu x %zu\n", rows, cols);
allocator_state ta_state = ma_open(ta);
@@ -1056,45 +1056,83 @@ HDF5dataset(Client ctx, MalBlkPtr mb, Ma
throw(MAL, "netcdf.HDF5dataset", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
- for(int i = 0; i < pci->retc; i++) {
- bats[i] = COLnew(0, getBatType(getArgType(mb, pci, i)), rows,
TRANSIENT);
- if (!bats[i]) {
- msg = createException(MAL, "netcdf.HDF5dataset",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
- goto bailout;
+ if (FBLOCK_OFF) {
+ for(int i = 0; i < pci->retc; i++) {
+ bats[i] = COLnew(0, getBatType(getArgType(mb, pci, i)),
rows, TRANSIENT);
+ if (!bats[i]) {
+ msg = createException(MAL,
"netcdf.HDF5dataset", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ goto bailout;
+ }
+ dbls[i] = Tloc(bats[i], 0);
}
- dbls[i] = Tloc(bats[i], 0);
+ } else {
+ size_t block_size = sizeof(fblock);
+ size_t block_capacity = block_size / sizeof(dbl);
+ size_t nrows = block_capacity / cols;
+ //size_t nblocks = (rows + nrows - 1) / nrows;
+ size_t nblocks = rows / nrows;
+ int btype = getBatType(getArgType(mb, pci, 0));
+ bats[0] = COLnew(0, btype, nblocks, TRANSIENT);
+ assert(bats[0]->twidth == block_size);
}
+
// loop over load data
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]