Changeset: a262abfaab7c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a262abfaab7c
Modified Files:
gdk/gdk_arrays.c
gdk/gdk_arrays.h
monetdb5/modules/kernel/arrays.c
monetdb5/modules/kernel/arrays.h
monetdb5/modules/kernel/arrays.mal
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_arrays.c
sql/backends/monet5/sql_arrays.h
sql/backends/monet5/sql_arrays.mal
sql/backends/monet5/sql_gencode.c
sql/server/rel_select.c
Branch: arrays
Log Message:
return dims when binding the nonDimensional BAT + create mbr when selecting on
nonDimensional BAT
diffs (truncated from 892 to 300 lines):
diff --git a/gdk/gdk_arrays.c b/gdk/gdk_arrays.c
--- a/gdk/gdk_arrays.c
+++ b/gdk/gdk_arrays.c
@@ -1702,3 +1702,141 @@ fprintf(stderr, "avg: group %u - (%u,%f)
return GDK_SUCCEED;
}
+
+static BUN qualifyingOIDs(int dimNum, int skipSize, gdk_cells* oidDims, BAT*
oidsBAT, oid **resOIDs ) {
+ BUN sz = 0;
+ BUN j;
+ oid io;
+
+ oid *qOIDS = NULL;
+
+ gdk_dimension *oidsDim;
+ dim_node *n;
+ for(n=oidDims->h; n && n->data->dimNum<dimNum; n = n->next);
+ oidsDim = n->data;
+
+ if(dimNum == oidDims->dimsNum-1) { //last dimension
+ if(oidsDim->elementsNum > 0) {
+ qOIDS = GDKmalloc(sizeof(oid)*oidsDim->elementsNum);
+ for(io=*(oid*)oidsDim->min, sz=0; io<=*(oid*)oidsDim->max;
io+=*(oid*)oidsDim->step, sz++) {
+ qOIDS[sz] = skipSize*io;
+//fprintf(stderr, "%u = %u\n", (unsigned int)sz, (unsigned int)qOIDS[sz]);
+ }
+ } else {
+ //the oids are in the BAT
+ //iterate over the elements in the BAT to find the indices of the
dimension that have survided
+ //and add and idx for each one of these elements
+ oid* candOIDs = (oid*)Tloc(oidsBAT, BUNfirst(oidsBAT));
+ int previousIdx = -1;
+ BUN i;
+ qOIDS = GDKmalloc(sizeof(oid)*oidsDim->initialElementsNum);
+
+ for(i=0; i<BATcount(oidsBAT); i++) {
+ int idx = candOIDs[i]/skipSize;
+ if(idx > previousIdx) {
+ qOIDS[sz] = skipSize*idx;
+//fprintf(stderr, "%u = %u\n", (unsigned int)sz, (unsigned int)qOIDS[sz]);
+ sz++;
+ previousIdx = idx;
+ }
+ }
+ }
+ *resOIDs = qOIDS;
+ } else {
+ oid *resOIDs_local = NULL;
+ BUN addedEls = qualifyingOIDs(dimNum+1,
skipSize*oidsDim->initialElementsNum, oidDims, oidsBAT, &resOIDs_local);
+ if(dimNum == 0)
+ qOIDS = *resOIDs;
+ else {
+ if(oidsDim->elementsNum > 0)
+ qOIDS = GDKmalloc(sizeof(oid)*oidsDim->elementsNum*addedEls);
+ else
+ qOIDS =
GDKmalloc(sizeof(oid)*oidsDim->initialElementsNum*addedEls);
+ }
+
+ for(j=0, sz=0; j<addedEls; j++) {
+//fprintf(stderr, "-> %u = %u\n", (unsigned int)j, (unsigned
int)resOIDs_local[j]);
+ if(oidsDim->elementsNum > 0) {
+ for(io=*(oid*)oidsDim->min; io<=*(oid*)oidsDim->max;
io+=*(oid*)oidsDim->step, sz++) {
+ qOIDS[sz] = resOIDs_local[j] + skipSize*io;
+//fprintf(stderr, "%u = %u\n", (unsigned int)sz, (unsigned int)qOIDS[sz]);
+ }
+ } else {
+ //check the BAT
+ oid* candOIDs = (oid*)Tloc(oidsBAT, BUNfirst(oidsBAT));
+ int previousIdx = -1;
+ BUN i;
+ for(i=0; i<BATcount(oidsBAT); i++) {
+ int idx =
(candOIDs[i]%(skipSize*oidsDim->initialElementsNum))/skipSize;
+ if(idx > previousIdx) {
+ qOIDS[sz] = resOIDs_local[j]+skipSize*idx;
+//fprintf(stderr, "%u = %u\n", (unsigned int)sz, (unsigned int)qOIDS[sz]);
+ sz++;
+ previousIdx = idx;
+ }
+ }
+ }
+ }
+ *resOIDs = qOIDS;
+ }
+
+ return sz;
+}
+
+BAT *projectCells(gdk_cells* dims, BAT* oidsBAT) {
+ BAT *resBAT = NULL;
+ BUN resSize = 1;
+ oid *resOIDs = NULL;
+ dim_node *n;
+
+ /*combine the oidsDimensions in order to get the global oids (the cells)*/
+ for(n=dims->h; n; n=n->next) {
+ BUN sz = n->data->elementsNum;
+ if(sz > 0)
+ resSize *= sz;
+ else
+ resSize *= n->data->initialElementsNum;
+ }
+ resSize += BATcount(oidsBAT); //this is not accurate but I believe it is ok
+ //fprintf(stderr, "estiamted size = %u\n", (unsigned int)resSize);
+ /*the size of the result is the same as the number of cells in the
candidatesDimensions */
+ if(!(resBAT = BATnew(TYPE_void, TYPE_oid, resSize, TRANSIENT)))
+ return NULL;
+ resOIDs = (oid*)Tloc(resBAT, BUNfirst(resBAT));
+ resSize = qualifyingOIDs(0, 1, dims, oidsBAT, &resOIDs);
+ //fprintf(stderr, "real size = %u\n", (unsigned int)resSize);
+ BATsetcount(resBAT, resSize);
+ BATseqbase(resBAT, 0);
+ BATderiveProps(resBAT, FALSE);
+
+ return resBAT;
+}
+
+
+/*takes a set of dimensions of any type and returns the corresponding
dimensions in indices format */
+gdk_cells* arrayToCells(gdk_array *array) {
+ gdk_cells *resDims = cells_new();
+ int i=0;
+
+ for(i=0; i<array->dimsNum; i++) {
+ gdk_dimension *dim = createDimension_oid(i, array->dimSizes[i], 0,
array->dimSizes[i]-1, 1);
+ resDims = cells_add_dimension(resDims, dim);
+ }
+ return resDims;
+}
+
+gdk_array *cellsToArray(gdk_cells *cells) {
+ dim_node *n;
+ int i=0;
+ gdk_array *array = GDKmalloc(sizeof(gdk_array));
+ if(!array)
+ return NULL;
+ //count the dimensions
+ array->dimsNum = 0;
+ for(n=cells->h ; n ; n=n->next)
+ array->dimsNum++;
+ //get the size of each dimension (the initial size)
+ for(n=cells->h , i=0; n ; n= n->next, i++)
+ array->dimSizes[i] = n->data->initialElementsNum;
+ return array;
+}
diff --git a/gdk/gdk_arrays.h b/gdk/gdk_arrays.h
--- a/gdk/gdk_arrays.h
+++ b/gdk/gdk_arrays.h
@@ -16,7 +16,7 @@ typedef struct dimStruct {
} gdk_dimension;
typedef struct arrayStruct {
- int dimsNum; //the number of dimensions
+ unsigned short dimsNum; //the number of dimensions (0 to 65,535)
BUN *dimSizes; //an array having the size for each dimension
} gdk_array;
@@ -289,4 +289,9 @@ gdk_return dimensionBATgroup(BAT **group
gdk_return dimensionBATgroupavg(BAT **bnp, BAT **cntsp, BAT *b, BAT *g, BAT
*e, BAT *s, int tp, int skip_nils, int abort_on_error);
gdk_return dimensionBATsubjoin(BAT **outBATl, BAT **outBATr, BAT
*dimensionBATl, BAT *dimensionBATr, BAT *sl, BAT *sr, int nil_matches, BUN
estimate);
+/*NEW*/
+gdk_export BAT *projectCells(gdk_cells* dims, BAT* oidsBAT);
+gdk_export gdk_cells* arrayToCells(gdk_array *array);
+gdk_export gdk_array *cellsToArray(gdk_cells *cells);
#endif /* _GDK_ARRAYS_H */
+
diff --git a/monetdb5/modules/kernel/arrays.c b/monetdb5/modules/kernel/arrays.c
--- a/monetdb5/modules/kernel/arrays.c
+++ b/monetdb5/modules/kernel/arrays.c
@@ -19,19 +19,6 @@ static int jumpSize(gdk_array *array, in
return skip;
}
-/*takes a set of dimensions of any type and returns the correspondin
- * dimensions in indices format */
-static gdk_cells* sizesToDimensions(gdk_array *array) {
- gdk_cells *resDims = cells_new();
- int i=0;
-
- for(i=0; i<array->dimsNum; i++) {
- gdk_dimension *dim = createDimension_oid(i, array->dimSizes[i],
0, array->dimSizes[i]-1, 1);
- resDims = cells_add_dimension(resDims, dim);
- }
- return resDims;
-}
-
static bool overlapingRanges(gdk_dimension *dim1, gdk_dimension *dim2) {
if(*(oid*)dim1->max < *(oid*)dim2->min || *(oid*)dim2->max <
*(oid*)dim1->min) {
//disjoint ranges. empty result
@@ -111,86 +98,6 @@ static BUN* oidToIdx_bulk(oid* oidVals,
return oids;
}
-static BUN qualifyingOIDs(int dimNum, int skipSize, gdk_cells* oidDims, BAT*
oidsBAT, oid **resOIDs ) {
- BUN sz = 0;
- BUN j;
- oid io;
-
- oid *qOIDS = NULL;
-
- gdk_dimension *oidsDim;
- dim_node *n;
- for(n=oidDims->h; n && n->data->dimNum<dimNum; n = n->next);
- oidsDim = n->data;
-
- if(dimNum == oidDims->dimsNum-1) { //last dimension
- if(oidsDim->elementsNum > 0) {
- qOIDS = GDKmalloc(sizeof(oid)*oidsDim->elementsNum);
- for(io=*(oid*)oidsDim->min, sz=0;
io<=*(oid*)oidsDim->max; io+=*(oid*)oidsDim->step, sz++) {
- qOIDS[sz] = skipSize*io;
-//fprintf(stderr, "%u = %u\n", (unsigned int)sz, (unsigned int)qOIDS[sz]);
- }
- } else {
- //the oids are in the BAT
- //iterate over the elements in the BAT to find the
indices of the dimension that have survided
- //and add and idx for each one of these elements
- oid* candOIDs = (oid*)Tloc(oidsBAT, BUNfirst(oidsBAT));
- int previousIdx = -1;
- BUN i;
- qOIDS =
GDKmalloc(sizeof(oid)*oidsDim->initialElementsNum);
-
- for(i=0; i<BATcount(oidsBAT); i++) {
- int idx = candOIDs[i]/skipSize;
- if(idx > previousIdx) {
- qOIDS[sz] = skipSize*idx;
-//fprintf(stderr, "%u = %u\n", (unsigned int)sz, (unsigned int)qOIDS[sz]);
- sz++;
- previousIdx = idx;
- }
- }
- }
- *resOIDs = qOIDS;
- } else {
- oid *resOIDs_local = NULL;
- BUN addedEls = qualifyingOIDs(dimNum+1,
skipSize*oidsDim->initialElementsNum, oidDims, oidsBAT, &resOIDs_local);
- if(dimNum == 0)
- qOIDS = *resOIDs;
- else {
- if(oidsDim->elementsNum > 0)
- qOIDS =
GDKmalloc(sizeof(oid)*oidsDim->elementsNum*addedEls);
- else
- qOIDS =
GDKmalloc(sizeof(oid)*oidsDim->initialElementsNum*addedEls);
- }
-
- for(j=0, sz=0; j<addedEls; j++) {
-//fprintf(stderr, "-> %u = %u\n", (unsigned int)j, (unsigned
int)resOIDs_local[j]);
- if(oidsDim->elementsNum > 0) {
- for(io=*(oid*)oidsDim->min;
io<=*(oid*)oidsDim->max; io+=*(oid*)oidsDim->step, sz++) {
- qOIDS[sz] = resOIDs_local[j] +
skipSize*io;
-//fprintf(stderr, "%u = %u\n", (unsigned int)sz, (unsigned int)qOIDS[sz]);
- }
- } else {
- //check the BAT
- oid* candOIDs = (oid*)Tloc(oidsBAT,
BUNfirst(oidsBAT));
- int previousIdx = -1;
- BUN i;
- for(i=0; i<BATcount(oidsBAT); i++) {
- int idx =
(candOIDs[i]%(skipSize*oidsDim->initialElementsNum))/skipSize;
- if(idx > previousIdx) {
- qOIDS[sz] =
resOIDs_local[j]+skipSize*idx;
-//fprintf(stderr, "%u = %u\n", (unsigned int)sz, (unsigned int)qOIDS[sz]);
- sz++;
- previousIdx = idx;
- }
- }
- }
- }
- *resOIDs = qOIDS;
- }
-
- return sz;
-}
-
#define computeValues(TPE) \
do { \
TPE min = *(TPE*)dimension->min; \
@@ -519,6 +426,36 @@ static bool updateCandidateResults(gdk_a
return 1;
}
+static str readCands(gdk_cells** dimsRes, BAT** oidsRes, const ptr *dimsCand,
const bat *oidsCand, gdk_array* array) {
+ gdk_cells *dimensionsCandidates_in = NULL;
+ BAT *candidatesBAT_in = NULL;
+
+ if(oidsCand) {
+ if ((candidatesBAT_in = BATdescriptor(*oidsCand)) == NULL) {
+ throw(MAL, "algebra.dimensionSubselect",
RUNTIME_OBJECT_MISSING);
+ }
+ }
+
+ if(dimsCand)
+ dimensionsCandidates_in = (gdk_cells*)*dimsCand;
+
+ //if there are no candidates then everything is a candidate
+ if(!dimsCand && !oidsCand) {
+ dimensionsCandidates_in = arrayToCells(array);
+ //create an empy candidates BAT
+ if((candidatesBAT_in = BATnew(TYPE_void, TYPE_oid, 0,
TRANSIENT)) == NULL)
+ throw(MAL, "algebra.dimensionSubselect", GDK_EXCEPTION);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list