Skip to content

Commit

Permalink
default stream mode for PIPE was not good idea - the printing data in…
Browse files Browse the repository at this point in the history
… text format was broken
  • Loading branch information
okbob committed Jul 30, 2021
1 parent b3aa8b3 commit a97b146
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ or by specification watch time by option `--watch`.

# Streaming modes

`pspg` can read a stream of tabular data from pipe or from file (with an option
`--stream` or it can read a stream of queries from pipe or from file (with an
option `--querystream`).
`pspg` can read a continuous stream of tabular data from pipe, named pipe or from file
(with an option `--stream` or it can read a stream of queries from pipe or from file
(with an option `--querystream`). In stream mode, only data in table format can be
processed, because `pspg` uses empty line as separator between tables.

The query stream mode is an sequence of SQL statements separated by char GS (Group
separator - 0x1D on separated line.
Expand Down
4 changes: 0 additions & 4 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ readargs(char **argv,
fprintf(stdout, " --interactive force interactive mode\n");
fprintf(stdout, " --ignore_file_suffix don't try to deduce format from file suffix\n");
fprintf(stdout, " --ni not interactive mode (only for csv and query)\n");
fprintf(stdout, " --no-implicit-stream block implicit stream mode\n");
fprintf(stdout, " --no-mouse don't use own mouse handling\n");
fprintf(stdout, " --no-progressive-load don't use progressive data load\n");
fprintf(stdout, " --no-sigint-search-reset\n");
Expand Down Expand Up @@ -666,9 +665,6 @@ readargs(char **argv,
case 47:
opts->progressive_load_mode = false;
break;
case 48:
opts->no_implicit_stream = true;
break;
default:
{
format_error("Try %s --help\n", argv[0]);
Expand Down
3 changes: 0 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ save_config(char *path, Options *opts)
SAFE_SAVE_BOOL_OPTION("empty_string_is_null", opts->empty_string_is_null);
SAFE_SAVE_BOOL_OPTION("last_row_search", opts->last_row_search);
SAFE_SAVE_BOOL_OPTION("progressive_load_mode", opts->progressive_load_mode);
SAFE_SAVE_BOOL_OPTION("no_implicit_stream", opts->no_implicit_stream);

result = fprintf(f, "theme = %d\n", opts->theme);
if (result < 0)
Expand Down Expand Up @@ -319,8 +318,6 @@ load_config(char *path, Options *opts)
is_valid = assign_int(key, (int *) &opts->hist_size, int_val, res, 0, INT_MAX);
else if (strcmp(key, "progressive_load_mode") == 0)
is_valid = assign_bool(key, &opts->progressive_load_mode, bool_val, res);
else if (strcmp(key, "no_implicit_stream") == 0)
is_valid = assign_bool(key, &opts->no_implicit_stream, bool_val, res);

free(line);
line = NULL;
Expand Down
1 change: 0 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ typedef struct
bool last_row_search;
int hist_size;
bool progressive_load_mode;
bool no_implicit_stream;
} Options;

extern bool save_config(char *path, Options *opts);
Expand Down
12 changes: 0 additions & 12 deletions src/inputs.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,18 +698,6 @@ open_data_stream(Options *opts)
opts->progressive_load_mode = false;
}

/*
* The pspg over PIPE with streaming mode can be used as PSQL_PAGER
* or as PSQL_WATCH_PAGER. Without streaming mode can be used only
* as PSQL_PAGER. Then from user's perspective is better to use
* streaming mode by default.
*/
if ((f_data_opts & STREAM_IS_PIPE) && !opts->no_implicit_stream)
{
log_row("force stream mode because input is PIPE");
current_state->stream_mode = true;
}

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/pspg.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,9 @@ extern FILE *logfile;
/*
* REMOVE THIS COMMENT FOR DEBUG OUTPUT
* and modify a path.
*
#define DEBUG_PIPE "/home/pavel/debug"
*/
#define DEBUG_PIPE "/home/pavel/debug"
//*/

#ifdef DEBUG_PIPE

Expand Down
32 changes: 30 additions & 2 deletions src/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,22 @@ _getline(char **lineptr, size_t *n, FILE *fp, bool is_nonblocking, bool wait_on_
if (rc == -1)
{
log_row("poll error (%s)", strerror(errno));
if (handle_sigint)
{
free(dynbuf);
handle_sigint = false;
return -1;
}

usleep(1000);
}

if (fds[0].revents & POLLHUP)
{
free(dynbuf);
return -1;
}

clearerr(fp);
continue;
}
Expand Down Expand Up @@ -684,13 +696,29 @@ readfile(Options *opts, DataDesc *desc, StateData *state)

do
{
if (line && line[read - 1] == '\n')
if (line && read > 0 && line[read - 1] == '\n')
{
line[read - 1] = '\0';
read -= 1;
}

/* In streaming mode exit when you find empty row */
/*
* In streaming mode go out when you find empty row.
*
* Attention: streaming mode can be used only for tabular data!!!
* on nontabular data (plain text) we have not a possibility
* to detect end of block. In theory we can wait sone time to
* data, and after timeout we can alert end of block, but it
* increase the time of data load (and complexity).
*
* So until we get more possibilities (some marks in stream),
* it is better to hold stream mode as special case. I had an
* idea to set stream mode as default, but it doesn't work with
* non tabular data.
*
* Note: psql helps with it - it redirects only tabular data.
*
*/
if (state->stream_mode && read == 0)
{
free(line);
Expand Down

0 comments on commit a97b146

Please sign in to comment.