Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
re-enabled select distinct aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Humphreys committed Jun 3, 2019
1 parent 2e9d2c9 commit ecd255b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 48 deletions.
2 changes: 1 addition & 1 deletion env/dos/dos.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int fputs_dos(const char *str, FILE *stream) {
output = d_charsetEncode((char *)str, consoleEncoding, &len);

/* eat last trailing newline (if we print something else we'll display it then) */
if(output[len-1] == '\n') {
if(output && output[len-1] == '\n') {
newline = TRUE;
lastWasErr = stream == stderr;
output[len-1] = '\0';
Expand Down
4 changes: 2 additions & 2 deletions env/win32/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int fputs_w32(const char *str, FILE *stream) {

output = d_charsetEncode((char *)str, ENC_UTF16LE, &len);

if(output[len-2] == '\n') {
if(output && output[len-2] == '\n') {
newline = TRUE;
len -= 2;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ int fputs_w32(const char *str, FILE *stream) {
output = d_charsetEncode((char *)str, consoleEncoding, &len);

/* eat last trailing newline. If we print something else we'll display it at that time */
if(output[len-1] == '\n') {
if(output && output[len-1] == '\n') {
newline = TRUE;
lastWasErr = stream == stderr;
output[len-1] = '\0';
Expand Down
1 change: 1 addition & 0 deletions querycsv.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#define TRE_BLACK 1
#define TRE_RED 2
#define TRE_CONVERTED 3
#define TRE_SKIP 4
#define isRed(x) (x != NULL && x->type == TRE_RED)

/* short codes for the character encodings we want to support */
Expand Down
55 changes: 22 additions & 33 deletions split/groupResultsInner.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,39 @@
void groupResultsInner(
struct qryData *query,
struct resultColumnValue *columns,
int i
int i,
struct resultTree *item
) {
struct resultColumnValue *previousMatch;
struct resultTree *tempItem;

MAC_YIELD

if(i == 0) {
updateRunningCounts(query, columns, TRUE);

if(query->recordCount > 1) {
query->match = columns;
}
else {
addGroupedResult(query, columns);
}

return;
if(item->type == TRE_SKIP) {
cleanup_matchValues(query, &columns);
}
else {
query->groupCount = 0;

previousMatch = query->match;
updateRunningCounts(query, item);

/* if the current record to look at is identical to the previous one */
/* if no group by clause then every record is part of one group */
if(
query->groupByClause == NULL ||
/* look at the next item */
tempItem = item->link[1];

/* while the next nth result is part of the same group
as this result, add to the number of items to look ahead */
while(
tempItem &&
recordCompare(
(void *)previousMatch,
(void *)columns,
(void *)tempItem->columns,
(void *)query
) != 0
) == 0
) {
addGroupedResult(query, previousMatch);

updateRunningCounts(query, columns, TRUE);

previousMatch = query->match = columns;
}
else {
updateRunningCounts(query, columns, FALSE);

cleanup_matchValues(query, &columns);
}
updateRunningCounts(query, tempItem);
tempItem->type = TRE_SKIP;
tempItem = tempItem->link[1];
}

if(i == query->recordCount - 1) {
addGroupedResult(query, previousMatch);
addGroupedResult(query, columns);
}
}
4 changes: 2 additions & 2 deletions split/outputResult.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
void outputResult(
struct qryData *query,
struct resultColumnValue *columns,
int currentIndex
int currentIndex,
struct resultTree *item
) {
struct resultColumn *currentResultColumn;
struct resultColumnValue *field;
Expand Down Expand Up @@ -82,5 +83,4 @@ void outputResult(
if(currentIndex > -1) {
cleanup_matchValues(query, &columns);
}

}
2 changes: 1 addition & 1 deletion split/runQuery.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int runQuery(char *queryFileName) {
while(getMatchingRecord(&query, match)) {
/* print record to stdout */
query.recordCount++;
outputResult(&query, match, -1);
outputResult(&query, match, -1, NULL);
}

cleanup_matchValues(&query, &match);
Expand Down
5 changes: 3 additions & 2 deletions split/tree_walkAndCleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
void tree_walkAndCleanup(
struct qryData *query,
struct resultTree **root,
void (*callback)(struct qryData *, struct resultColumnValue *, int)
void (*callback)(struct qryData *, struct resultColumnValue *, int, struct resultTree *)
) {
struct resultTree *currentResult;
struct resultTree *tempResult;
Expand Down Expand Up @@ -85,7 +85,8 @@ void tree_walkAndCleanup(
callback(
query,
currentResult->columns,
i++
i++,
currentResult
);

tempResult = currentResult;
Expand Down
18 changes: 11 additions & 7 deletions split/updateRunningCounts.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
void updateRunningCounts(
struct qryData *query,
struct resultColumnValue *match,
int startNewGroup
struct resultTree *item
) {
struct resultTree *tempItem;
struct resultColumnValue *match = item->columns;

struct columnRefHashEntry *currentHashEntry;
struct columnReference *currentReference;
struct resultColumn *currentResultColumn;
Expand Down Expand Up @@ -34,7 +36,7 @@ void updateRunningCounts(
) {

/* if query->groupCount = 1 then we're starting a new group */
if(startNewGroup) {
if(query->groupCount == 1) {
freeAndZero(currentResultColumn->groupText);
currentResultColumn->groupNum = ctof(0);
currentResultColumn->groupCount = 0;
Expand All @@ -46,11 +48,12 @@ void updateRunningCounts(
stringGet((unsigned char **)(&tempString), field, query->params);

/* distinct groupings. only add to the count if the column value hasn't aready been seen */
/* TODO: fix this code. we'll need to keep all results until the grouping is finished because of this */
/*if(currentResultColumn->groupType > GRP_STAR) {
if(currentResultColumn->groupType > GRP_STAR) { /* distinct variants */
if(query->groupCount > 1) {
tempItem = item->link[0];

for(j = 1; j < query->groupCount; j++) {
stringGet((unsigned char **)(&tempString2), &(match[(currentResultColumn->resultColumnIndex) - (query->columnCount)]), query->params);
stringGet((unsigned char **)(&tempString2), &(tempItem->columns[currentResultColumn->resultColumnIndex]), query->params);

if(strCompare(
(unsigned char **)(&tempString),
Expand All @@ -64,12 +67,13 @@ void updateRunningCounts(
}

freeAndZero(tempString2);
tempItem = tempItem->link[0];
}
}
else {
j = query->groupCount;
}
}*/
}

switch(currentResultColumn->groupType) {
case GRP_DIS_COUNT: {
Expand Down

0 comments on commit ecd255b

Please sign in to comment.