diff options
| author | M.Shulhan <ms@kilabit.org> | 2009-04-05 17:52:57 +0700 |
|---|---|---|
| committer | M.Shulhan <ms@kilabit.org> | 2009-04-05 17:52:57 +0700 |
| commit | 19c3ee85ea45c5b5c2a479af17b86ba65d52673b (patch) | |
| tree | 2bf8fe1e94691e85d2c19adea8a42240586c5862 /op/vos_StmtSort.c | |
| parent | 459cd2d7715baea5a56090b3331f0b9b95e832c2 (diff) | |
| download | vos-19c3ee85ea45c5b5c2a479af17b86ba65d52673b.tar.xz | |
fix sort process.
type/vos_TStmtJoin:
- deleted, merge into vos_TStmtMeta.h
op/vos_File:
- file_open: fix memory leak on open fail.
- file_raw_copy: new, function to copy file.
- file_raw_get_dirname: new, function to get directory name from path.
op/vos_Stmt:
- stmt_find_by_name: re-structure the switch.
- stmt_update_meta: new, update meta filename to the last output name.
op/vos_StmtSort:
- stmtsort_create: remove free sort->in.
- stmtsort_init_output: split into stmtsort_init.
- stmtsort_init: new.
- stmtsort_destroy: remove unused temporary sort file.
proc/vos_create:
- vos_process_create: update meta object before processing.
proc/vos_join:
- change affect by split of stmtsort_init_output.
proc/vos_parser:
- use 'filename' as an alias if alias is not set in statement.
proc/vos_sort:
- vos_process_sort: fix bug in sort process.
when input file is splitted into several thread and the first split
is precisely end in a new-line character, this can cause losing of one
row in the output file.
- sort_write: use 'get_tmp_dir()' to get temporary directory.
proc/vos_sort_merge:
- vos_sort_merge: simplified the merge process if only one file to be merged.
- single_merge: new.
vos:
- get_tmp_dir: new, function to get temporary directory.
Diffstat (limited to 'op/vos_StmtSort.c')
| -rw-r--r-- | op/vos_StmtSort.c | 66 |
1 files changed, 50 insertions, 16 deletions
diff --git a/op/vos_StmtSort.c b/op/vos_StmtSort.c index a2d4bc8..437feeb 100644 --- a/op/vos_StmtSort.c +++ b/op/vos_StmtSort.c @@ -8,7 +8,6 @@ int stmtsort_create(struct Stmt **sort) (*sort)->out = (struct StmtMeta *) calloc(1, sizeof(struct StmtMeta)); if (! (*sort)->out) { - free((*sort)->in); free((*sort)); (*sort) = 0; return E_MEM; @@ -17,9 +16,9 @@ int stmtsort_create(struct Stmt **sort) return 0; } -int stmtsort_init_output(struct Stmt *sort) +int stmtsort_init(struct Stmt *sort) { - int s = E_MEM; + int s = 0; struct Field *fld_in = 0; struct Field *fld_out = 0; @@ -30,18 +29,7 @@ int stmtsort_init_output(struct Stmt *sort) return E_MEM; } - if (! sort->out->filename) { - do { - s = str_raw_randomize(VOS_SORT_OUT_FORMAT, - &sort->out->filename); - if (s) - return s; - - s = file_raw_is_exist(sort->out->filename); - if (s) - free(sort->out->filename); - } while (s); - } else { + if (sort->out->filename) { /* check if file output is exist */ s = file_raw_is_exist(sort->out->filename); if (s) { @@ -79,6 +67,49 @@ int stmtsort_init_output(struct Stmt *sort) return 0; } +/** + * @stmtsort_init_output: get temporary file name for sort output. + * + * @return: + * < 0 : success. + * < !0 : fail. + */ +int stmtsort_init_output(struct Stmt *sort) +{ + int s; + char *rndm_name = 0; + struct String *tmp = 0; + + /* filename already declared by INTO statement */ + if (sort->out->filename) + return 0; + + str_create(&tmp); + + do { + str_append(tmp, get_tmp_dir(0)); + + s = str_raw_randomize(VOS_SORT_OUT_FORMAT, &rndm_name); + if (s) + goto err; + + str_append(tmp, rndm_name); + + s = file_raw_is_exist(tmp->buf); + if (s) + str_prune(tmp); + + free(rndm_name); + } while (s); + + sort->out->flag |= SORT_TMP; + sort->out->filename = tmp->buf; + tmp->buf = 0; +err: + str_destroy(&tmp); + return s; +} + void stmtsort_print(struct Stmt *sort) { if (! sort) @@ -99,8 +130,11 @@ void stmtsort_destroy(struct Stmt **sort) stmtmeta_soft_destroy(&(*sort)->in); if ((*sort)->out) { - if ((*sort)->out->filename) + if ((*sort)->out->filename) { + if ((*sort)->out->flag & SORT_TMP) + unlink((*sort)->out->filename); free((*sort)->out->filename); + } if ((*sort)->out->alias) free((*sort)->out->alias); field_soft_destroy(&(*sort)->out->fields); |
