Changeset: 8bb2096f7aca for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8bb2096f7aca Modified Files: monetdb5/modules/kernel/arrays.c monetdb5/modules/kernel/arrays.h monetdb5/modules/kernel/arrays.mal sql/backends/monet5/sql_arrays.mal Branch: arrays Log Message:
projecting the values of a non-dimensional column after a selection on dimensional columns only is the same as projecting any other column + Cleaning code diffs (truncated from 628 to 300 lines): 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 @@ -4,13 +4,6 @@ #include <gdk_arrays.h> -static gdk_dimension* getDimension(gdk_cells *dims, int dimNum) { - dim_node *n; - - for(n=dims->h; n && n->data->dimNum<dimNum; n=n->next); - return n->data; -} - static int jumpSize(gdk_array *array, int dimNum) { int i=0; BUN skip = 1; @@ -23,26 +16,13 @@ static int arrayCellsNum(gdk_array *arra return jumpSize(array, array->dimsNum); } -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 - return 0; - } - return 1; +static gdk_dimension* getDimension(gdk_cells *dims, int dimNum) { + dim_node *n; + + for(n=dims->h; n && n->data->dimNum<dimNum; n=n->next); + return n->data; } -static gdk_dimension* mergeCandidateDimensions(gdk_dimension *dim1, gdk_dimension *dim2) { - oid min, max, step; - - /*the biggest of the mins and the smallest of the maximums */ - min = *(oid*)dim1->min > *(oid*)dim2->min ? *(oid*)dim1->min : *(oid*)dim2->min; - max = *(oid*)dim1->max < *(oid*)dim2->max ? *(oid*)dim1->max : *(oid*)dim2->max; - step = *(oid*)dim1->step ; //step is always 1 - - //the dimensions that are merged should have the same order - //they also have the same number of initial elements because they came from the same dimension - return createDimension_oid(dim1->dimNum, dim1->initialElementsNum, min, max, step); } - static BUN oidToIdx(oid oidVal, int dimNum, int currentDimNum, BUN skipCells, gdk_array *dims) { BUN oid = 0; @@ -61,7 +41,6 @@ static BUN oidToIdx(oid oidVal, int dimN return oid%skipCells; } - static BUN* oidToIdx_bulk(oid* oidVals, int valsNum, int dimNum, int currentDimNum, BUN skipCells, gdk_array *dims) { BUN *oids = GDKmalloc(valsNum*sizeof(BUN)); int i; @@ -102,129 +81,36 @@ static BUN* oidToIdx_bulk(oid* oidVals, return oids; } -#define computeValues(TPE) \ -do { \ - TPE min = *(TPE*)dimension->min; \ - TPE step = *(TPE*)dimension->step; \ - TPE *vals; \ - oid *oids; \ - BUN *idxs; \ - BUN i; \ -\ - if(!(resBAT = BATnew(TYPE_void, TYPE_##TPE, resSize, TRANSIENT))) \ - throw(MAL, "algebra.dimensionLeftfetchjoin", "Problem allocating new BAT"); \ - vals = (TPE*)Tloc(resBAT, BUNfirst(resBAT)); \ - oids = (oid*)Tloc(candsBAT, BUNfirst(candsBAT)); \ -\ - idxs = oidToIdx_bulk(oids, resSize, dimension->dimNum, 0, 1, array); \ - for(i=0; i<resSize; i++) { \ - *vals++ = min +idxs[i]*step; \ -/*fprintf(stderr, "%d - %d - %d\n", (int)oids[i], (int)idxs[i], (int)vals[-1]); */\ - } \ -} while(0) +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); + } + } -str ALGdimensionLeftfetchjoin1(bat *result, const bat *cands, const ptr *dims, const ptr *dim) { - gdk_array *array = (gdk_array*)*dims; - gdk_dimension *dimension = (gdk_dimension*)*dim; - BAT *candsBAT = NULL, *resBAT = NULL; - BUN resSize = 0; + if(dimsCand) + dimensionsCandidates_in = (gdk_cells*)*dimsCand; -//TODO: Make sure that the cabdidates form an MBR + //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); + BATsetcount(candidatesBAT_in, 0); + BATseqbase(candidatesBAT_in, 0); + BATderiveProps(candidatesBAT_in, FALSE); + } - if ((candsBAT = BATdescriptor(*cands)) == NULL) { - throw(MAL, "algebra.dimensionLeftfetchjoin", RUNTIME_OBJECT_MISSING); - } - resSize = BATcount(candsBAT); - /*for each oid in the candsBAT find the real value of the dimension */ - switch(dimension->type) { \ - case TYPE_bte: \ - computeValues(bte); - break; - case TYPE_sht: - computeValues(sht); - break; - case TYPE_int: - computeValues(int); - break; - case TYPE_wrd: - computeValues(wrd); - break; - case TYPE_oid: - computeValues(oid); - break; - case TYPE_lng: - computeValues(lng); - break; - case TYPE_dbl: - computeValues(dbl); - break; - case TYPE_flt: - computeValues(flt); - break; - default: - throw(MAL, "algebra.dimensionLeftfetchjoin", "Dimension type not supported\n"); - } - - BATsetcount(resBAT, resSize); - BATseqbase(resBAT, 0); - BATderiveProps(resBAT, FALSE); - - *result = resBAT->batCacheid; - BBPkeepref(*result); - - //free the space occupied by the dimension - freeDimension(dimension); - return MAL_SUCCEED; - -} - -//str ALGnonDimensionLeftfetchjoin1(bat* result, const ptr* dimsCand, const bat *candBat, const bat *valsBat) { -str ALGnonDimensionLeftfetchjoin1(bat* result, const bat* cands, const bat *vals, const ptr *dims) { - (void)*result; - (void)*cands; - (void)*vals; - (void)*dims; + *dimsRes = dimensionsCandidates_in; + *oidsRes = candidatesBAT_in; return MAL_SUCCEED; } -str ALGnonDimensionLeftfetchjoin2(bat* result, ptr *dimsRes, const bat *tids, const bat *vals, const ptr *dims) { - BAT *materialisedBAT = NULL; - BAT *nonDimensionalBAT = NULL; - BUN totalCellsNum, neededCellsNum; - - gdk_array *array = (gdk_array*)*dims; - - if ((nonDimensionalBAT = BATdescriptor(*vals)) == NULL) { - throw(MAL, "algebra.leftfecthjoin", RUNTIME_OBJECT_MISSING); - } - (void)*tids; //ignore the tids - - totalCellsNum = arrayCellsNum(array); - neededCellsNum = totalCellsNum - BATcount(nonDimensionalBAT); - - /*TODO: fix this so that I can have the real default value of the column */ - materialisedBAT = materialise_nonDimensional_column(ATOMtype(BATttype(nonDimensionalBAT)), neededCellsNum, NULL); - if(!materialisedBAT) { - BBPunfix(nonDimensionalBAT->batCacheid); - throw(MAL, "algebra.leftfetchjoin", "Problem materialising non-dimensional column"); - } - - - /*append the missing values to the BAT */ - BATappend(nonDimensionalBAT, materialisedBAT, TRUE); - BATsetcount(nonDimensionalBAT, totalCellsNum); - - BBPunfix(materialisedBAT->batCacheid); - BBPkeepref(*result = nonDimensionalBAT->batCacheid); - - //sent this to the output so that we do not lose it afterwards - *dimsRes = *dims; - - return MAL_SUCCEED; - -} - static str emptyCandidateResults(ptr *candsRes_dims, bat* candsRes_bid) { BAT *candidatesBAT = NULL; @@ -240,6 +126,27 @@ static str emptyCandidateResults(ptr *ca return MAL_SUCCEED; } +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 + return 0; + } + return 1; +} + +static gdk_dimension* mergeCandidateDimensions(gdk_dimension *dim1, gdk_dimension *dim2) { + oid min, max, step; + + /*the biggest of the mins and the smallest of the maximums */ + min = *(oid*)dim1->min > *(oid*)dim2->min ? *(oid*)dim1->min : *(oid*)dim2->min; + max = *(oid*)dim1->max < *(oid*)dim2->max ? *(oid*)dim1->max : *(oid*)dim2->max; + step = *(oid*)dim1->step ; //step is always 1 + + //the dimensions that are merged should have the same order + //they also have the same number of initial elements because they came from the same dimension + return createDimension_oid(dim1->dimNum, dim1->initialElementsNum, min, max, step); +} + static BAT* joinBATs(BAT *candsBAT, BAT* dimBAT, gdk_array *array, int dimNum) { oid *candsOIDs, *dimOIDs, *mergedOIDs; BAT* mergedBAT; @@ -461,37 +368,7 @@ 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); - BATsetcount(candidatesBAT_in, 0); - BATseqbase(candidatesBAT_in, 0); - BATderiveProps(candidatesBAT_in, FALSE); - } - - *dimsRes = dimensionsCandidates_in; - *oidsRes = candidatesBAT_in; - - return MAL_SUCCEED; -} - -str ALGdimensionSubselect2(ptr *dimsRes, bat* oidsRes, const ptr *dims, const ptr* dim, const ptr *dimsCand, const bat* oidsCand, +str ALGdimensionSubselect2(ptr *dimsRes, bat* oidsRes, const ptr *dim, const ptr* dims, const ptr *dimsCand, const bat* oidsCand, const void *low, const void *high, const bit *li, const bit *hi, const bit *anti) { gdk_array *array = (gdk_array*)*dims; //the sizes of all the dimensions (I treat them as indices and I do not care about the exact values) gdk_dimension *dimension = (gdk_dimension*)*dim; @@ -646,12 +523,12 @@ str ALGdimensionSubselect2(ptr *dimsRes, return MAL_SUCCEED; } -str ALGdimensionSubselect1(ptr *dimsRes, bat* oidsRes, const ptr *dims, const ptr* dim, +str ALGdimensionSubselect1(ptr *dimsRes, bat* oidsRes, const ptr *dim, const ptr* dims, const void *low, const void *high, const bit *li, const bit *hi, const bit *anti) { - return ALGdimensionSubselect2(dimsRes, oidsRes, dims, dim, NULL, NULL, low, high, li, hi, anti); + return ALGdimensionSubselect2(dimsRes, oidsRes, dim, dims, NULL, NULL, low, high, li, hi, anti); } -str ALGdimensionThetasubselect2(ptr *dimsRes, bat* oidsRes, const ptr *dims, const ptr* dim, const ptr *dimsCand, const bat* oidsCand, const void *val, const char **opp) { +str ALGdimensionThetasubselect2(ptr *dimsRes, bat* oidsRes, const ptr *dim, const ptr* dims, const ptr *dimsCand, const bat* oidsCand, const void *val, const char **opp) { bit li = 0; bit hi = 0; bit anti = 0; @@ -663,52 +540,190 @@ str ALGdimensionThetasubselect2(ptr *dim /* "=" or "==" */ li = hi = 1; anti = 0; - return ALGdimensionSubselect2(dimsRes, oidsRes, dims, dim, dimsCand, oidsCand, val, nil, &li, &hi, &anti); + return ALGdimensionSubselect2(dimsRes, oidsRes, dim, dims, dimsCand, oidsCand, val, nil, &li, &hi, &anti); } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list