Skip to content

Commit

Permalink
gufi_query -Q <dbname> <attachname> <sql>
Browse files Browse the repository at this point in the history
attach single db file to all threads
file is attached at the start of gufi_query instead of being reattached at every single directory
  • Loading branch information
calccrypto committed Jan 23, 2024
1 parent 113f83a commit 7e219a9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/bf.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ struct input {

/* compress work items (if compression library was found) */
int compress;

struct {
refstr_t dbname; /* name of single db file */
refstr_t attachname; /* attach name of db file */
refstr_t sql; /* SQL used to create view(s) on attached data */
} attach_single;
};

void print_help(const char *prog_name,
Expand Down
1 change: 1 addition & 0 deletions scripts/gufi_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from shlex import quote as sanitize # new in Python 3.3

# table names
ENTRIES = 'entries'
SUMMARY = 'summary'
PENTRIES = 'pentries'
XSUMMARY = 'xsummary'
Expand Down
18 changes: 18 additions & 0 deletions src/bf.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ void print_help(const char* prog_name,
#if HAVE_ZLIB
case 'e': printf(" -e compress work items"); break;
#endif
case 'Q': printf(" -Q <dbname>\n"
" <attachname>\n"
" <sql> Attach a single file across every single db in the index and use the SQL to create views"); break;
default: printf("print_help(): unrecognized option '%c'", (char)ch);
}
printf("\n");
Expand Down Expand Up @@ -197,6 +200,9 @@ void show_input(struct input* in, int retval) {
printf("in.target_memory_footprint = %" PRIu64 "\n", in->target_memory_footprint);
printf("in.subdir_limit = %zu\n", in->subdir_limit);
printf("in.compress = %d\n", in->compress);
printf("in.attach_single.dbname = %s\n", in->attach_single.dbname.data);
printf("in.attach_single.attachname = %s\n", in->attach_single.attachname.data);
printf("in.attach_single.sql = %s\n", in->attach_single.sql.data);
printf("\n");
printf("retval = %d\n", retval);
printf("\n");
Expand Down Expand Up @@ -432,6 +438,18 @@ int parse_cmd_line(int argc,
break;
#endif

case 'Q':
INSTALL_STR(&in->attach_single.dbname, optarg);
optarg = argv[optind];

INSTALL_STR(&in->attach_single.attachname, optarg);
optarg = argv[++optind];

INSTALL_STR(&in->attach_single.sql, optarg);
optarg = argv[++optind];

break;

case '?':
// getopt returns '?' when there is a problem. In this case it
// also prints, e.g. "getopt_test: illegal option -- z"
Expand Down
19 changes: 19 additions & 0 deletions src/gufi_query/PoolArgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ int PoolArgs_init(PoolArgs_t *pa, struct input *in, pthread_mutex_t *global_mute
}
#endif

/* handle -Q */
if (in->attach_single.dbname.len) {
/* attach single db to thread instance */
if (!attachdb(in->attach_single.dbname.data, ta->outdb,
in->attach_single.attachname.data,
SQLITE_OPEN_READONLY, 1)) {
break;
}

/* set up views */
char *err = NULL;
if (sqlite3_exec(ta->outdb, in->attach_single.sql.data, NULL, NULL, &err) != SQLITE_OK) {
fprintf(stderr, "Error: Could not run SQL Init \"%s\" on %s: %s\n",
in->sql.init.data, ta->dbname, err);
sqlite3_free(err);
break;
}
}

/* run -I */
if (in->sql.init.len) {
char *err = NULL;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/googletest/aggregate.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ TEST(gufi_query, aggregate) {

const size_t row_count = std::uniform_int_distribution <uint32_t> (1, 8)(gen);

struct input in;
struct input in{};
in.output = STDOUT;
in.maxthreads = std::uniform_int_distribution <uint32_t> (1, 8)(gen);
in.delim = ' ';
Expand Down

0 comments on commit 7e219a9

Please sign in to comment.