Permalink
Browse files

#65 new feature offset and limit support combined with grouping+order…

… or just grouping
  • Loading branch information...
1 parent 5ea7157 commit 6229eda7637894d9226c9c35c94457934a0aea1f @msalvadores msalvadores committed Mar 21, 2012
Showing with 30 additions and 5 deletions.
  1. +1 −0 src/frontend/query-intl.h
  2. +5 −0 src/frontend/query.c
  3. +24 −5 src/frontend/results.c
@@ -88,6 +88,7 @@ struct _fs_query {
fs_rid_vector *default_graphs;
int console; /* true if the query is being used from a console app */
int aggregate; /* true if the query uses aggregates */
+ int offset_aggregate; /* offset to be evaluated in result generation */
long group_length; /* number of rows in the current group */
uint64_t *group_rows; /* row numbers of the rows in the current group */
unsigned char *apply_constraints; /* bit array initialized to 1s,
View
@@ -523,6 +523,11 @@ fs_query *fs_query_execute(fs_query_state *qs, fsp_link *link, raptor_uri *bu, c
if (rasqal_query_get_group_condition(rq, 0) ||
rasqal_query_get_having_condition(rq, 0)) {
q->aggregate = 1;
+ /* if aggregate then offset must be evaluated in the result generation */
+ if (q->aggregate) {
+ q->offset_aggregate = q->offset;
+ q->offset = 0;
+ }
}
#if 0
// This needs to be be refined so it only applies to queries without FILTERs etc.
View
@@ -2456,9 +2456,20 @@ nextrow: ;
fs_value val = fs_expression_eval(q, 0, 0, q->bt[i+1].expression);
fs_value_to_row(q, val, q->resrow+i);
}
+
return q->resrow;
} else if (q->row >= q->length) {
- if (q->aggregate_order) {
+ if (q->aggregate_order) {
+ while (q->offset_aggregate > 0) {
+ q->offset_aggregate--;
+ q->agg_index++;
+ }
+ if (q->limit >= 0 && q->rows_output >= q->limit) {
+ if (grows) fs_rid_vector_free(grows);
+ return NULL;
+ }
+ q->rows_output++;
+
if (q->agg_index >= q->agg_rows->len) {
fs_free_agg_rows(q->agg_rows,q->num_vars);
fs_free_agg_values(q->agg_values,q->num_vars);
@@ -2472,12 +2483,13 @@ nextrow: ;
int order_agg = q->ordering[q->agg_index++];
fs_row *xx = (fs_row *) g_ptr_array_index(q->agg_rows,order_agg);
return xx;
- }
- return NULL;
+ }
+ return NULL;
}
fs_rid_vector *groups = fs_binding_get_vals(q->bt, "_group", NULL);
fs_rid_vector *ord = q->bt[0].vals;
if (groups) {
+ nextgroup: ;
q->group_by = 1;
next_row--;
@@ -2500,6 +2512,11 @@ nextrow: ;
fs_rid_vector_append(grows, ord->data[next_row]);
next_row++;
}
+ if (q->offset_aggregate > 0 && !q->order) {
+ q->offset_aggregate--;
+ next_row++;
+ goto nextgroup;
+ }
} else
return NULL;
} else {
@@ -2515,7 +2532,7 @@ nextrow: ;
}
const int rows = q->length;
- if (q->limit >= 0 && q->rows_output >= q->limit) {
+ if (!q->aggregate_order && q->limit >= 0 && q->rows_output >= q->limit) {
if (grows) fs_rid_vector_free(grows);
return NULL;
}
@@ -2549,6 +2566,7 @@ nextrow: ;
q->agg_values = g_ptr_array_new();
}
q->aggregate_order = 1;
+ q->rows_output = 0;
}
} else if (q->ordering) {
row = q->ordering[q->row];
@@ -2671,7 +2689,8 @@ nextrow: ;
}
q->row = next_row;
- q->rows_output++;
+ if (!q->aggregate_order)
+ q->rows_output++;
if (grows) fs_rid_vector_free(grows);
if (!q->group_by && q->aggregate) {

0 comments on commit 6229eda

Please sign in to comment.