Skip to content

Commit f927f77

Browse files
committed
more gufi_vt fixes
temporary xattr views need to be generated when parsing column types gufi_query initial arg count was not correct added tests selecting from xpentries
1 parent d939d53 commit f927f77

File tree

7 files changed

+78
-10
lines changed

7 files changed

+78
-10
lines changed

src/dbutils.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,11 +1216,9 @@ static trie_t *sqlite3_types(void) {
12161216
}
12171217

12181218
int get_col_types(sqlite3 *db, const refstr_t *sql, int **types, int *cols) {
1219-
int rc = SQLITE_OK;
1220-
12211219
/* parse sql */
12221220
sqlite3_stmt *stmt = NULL;
1223-
rc = sqlite3_prepare_v2(db, sql->data, sql->len, &stmt, NULL);
1221+
const int rc = sqlite3_prepare_v2(db, sql->data, sql->len, &stmt, NULL);
12241222
if (rc != SQLITE_OK) {
12251223
fprintf(stderr, "Error: Could not prepare '%s' for getting column types: %s (%d)\n",
12261224
sql->data, sqlite3_errstr(rc), rc);
@@ -1281,7 +1279,7 @@ int get_col_names(sqlite3 *db, const refstr_t *sql, char ***names, size_t **lens
12811279
sqlite3_stmt *stmt = NULL;
12821280
rc = sqlite3_prepare_v2(db, sql->data, sql->len, &stmt, NULL);
12831281
if (rc != SQLITE_OK) {
1284-
fprintf(stderr, "Error: Could not prepare '%s' for getting column types: %s (%d)\n",
1282+
fprintf(stderr, "Error: Could not prepare '%s' for getting column names: %s (%d)\n",
12851283
sql->data, sqlite3_errstr(rc), rc);
12861284
return -1;
12871285
}

src/gufi_query/handle_sql.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ int handle_sql(struct input *in) {
167167
}
168168
}
169169

170+
if (in->process_xattrs) {
171+
size_t count = 0; /* unused */
172+
setup_xattrs_views(in, db, &work, &count);
173+
}
174+
170175
/* if not aggregating, get types for T, S, and E */
171176
if (!in->sql.init_agg.len) {
172177
if (in->sql.tsum.len) {

src/gufi_vt.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static int gufi_query(const char *indexroot, const char *threads, const gq_sql_t
145145

146146
#define set_argv(argc, argv, flag, value) if (value) { argv[argc++] = flag; argv[argc++] = value; }
147147

148-
int argc = 2;
148+
int argc = 3;
149149
set_argv(argc, argv, "-n", threads);
150150
set_argv(argc, argv, "-I", sql->I.data);
151151
set_argv(argc, argv, "-T", sql->T.data);
@@ -636,15 +636,23 @@ static int gufi_vtpu_xConnect(sqlite3 *db,
636636
/* make sure all setup tables are placed into a different db */
637637
/* this should never fail */
638638
sqlite3 *tempdb = opendb(SQLITE_MEMORY, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
639-
0, 0, create_dbdb_tables, NULL);
639+
0, 0, create_dbdb_tables, NULL);
640+
641+
create_xattr_tables(SQLITE_MEMORY, tempdb, NULL);
642+
643+
struct input in;
644+
in.process_xattrs = 1;
645+
struct work work; /* unused */
646+
memset(&work, 0, sizeof(work));
647+
size_t count = 0; /* unused */
648+
setup_xattrs_views(&in, tempdb, &work, &count);
640649

641650
int cols = 0;
642651
int *types = NULL;
643652
char **names = NULL;
644653
size_t *lens = NULL;
645654

646655
/* this should never fail */
647-
struct work work;
648656
addqueryfuncs_with_context(tempdb, &work);
649657

650658
if (sql.T.len) {
@@ -718,10 +726,12 @@ static int gufi_vtpu_xConnect(sqlite3 *db,
718726
schema, threads, &sql, indexroot);
719727
error:
720728
free(lens);
721-
for(int c = 0; c < cols; c++) {
722-
free(names[c]);
729+
if (names) {
730+
for(int c = 0; c < cols; c++) {
731+
free(names[c]);
732+
}
733+
free(names);
723734
}
724-
free(names);
725735
free(types);
726736

727737
closedb(tempdb);

test/regression/gufi_sqlite3.expected

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ $ echo -n "CREATE VIRTUAL TABLE gufi USING gufi_vt('prefix', E='SELECT path() ||
7777
1024|prefix/1KB
7878
1048576|prefix/1MB
7979

80+
# gufi_vt xattrs
81+
$ echo -n "CREATE VIRTUAL TABLE gufi USING gufi_vt('prefix', E='SELECT path() || '/' || name AS fullpath, xattr_name, xattr_value FROM xpentries;'); SELECT fullpath, xattr_name, xattr_value FROM gufi ORDER BY fullpath ASC, xattr_name ASC;" | gufi_sqlite3 -d "|"
82+
prefix/.hidden||
83+
prefix/1KB||
84+
prefix/1MB|user.size|1MB
85+
prefix/directory/executable||
86+
prefix/directory/readonly||
87+
prefix/directory/subdirectory/directory_symlink||
88+
prefix/directory/subdirectory/repeat_name||
89+
prefix/directory/writable||
90+
prefix/file_symlink||
91+
prefix/leaf_directory/leaf_file1|user.name1|value1
92+
prefix/leaf_directory/leaf_file1|user.name2|value2
93+
prefix/leaf_directory/leaf_file1|user.name3|value3
94+
prefix/leaf_directory/leaf_file2|user.name4|value4
95+
prefix/leaf_directory/leaf_file2|user.name5|value5
96+
prefix/leaf_directory/leaf_file2|user.name6|value6
97+
prefix/old_file||
98+
prefix/repeat_name||
99+
prefix/unusual#? directory ,/unusual, name?#||
100+
80101
# bad SQL
81102
$ (echo "CREATE TABLE;") | gufi_sqlite3
82103
Error: SQL error: near ";": syntax error

test/regression/gufi_sqlite3.sh.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ PATH="@CMAKE_BINARY_DIR@/src:${PATH}" run_no_sort "echo \"SELECT size, path || '
120120
echo "# gufi_vt"
121121
PATH="@CMAKE_BINARY_DIR@/src:${PATH}" run_no_sort "echo -n \"CREATE VIRTUAL TABLE gufi USING gufi_vt('${INDEXROOT}', E='SELECT path() || '/' || name AS fullpath, size FROM pentries;'); SELECT size, fullpath FROM gufi ORDER BY size ASC, fullpath ASC;\" | ${GUFI_SQLITE3} -d \"|\""
122122

123+
echo "# gufi_vt xattrs"
124+
PATH="@CMAKE_BINARY_DIR@/src:${PATH}" run_no_sort "echo -n \"CREATE VIRTUAL TABLE gufi USING gufi_vt('${INDEXROOT}', E='SELECT path() || '/' || name AS fullpath, xattr_name, xattr_value FROM xpentries;'); SELECT fullpath, xattr_name, xattr_value FROM gufi ORDER BY fullpath ASC, xattr_name ASC;\" | ${GUFI_SQLITE3} -d \"|\""
125+
123126
echo "# bad SQL"
124127
run_no_sort "(echo \"CREATE TABLE;\") |" \
125128
"${GUFI_SQLITE3}"

test/regression/gufi_vt.expected

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,30 @@ $ (
287287
1024|prefix/1KB
288288
1048576|prefix/1MB
289289

290+
# xattr view
291+
$ (
292+
echo ".load gufi_vt"
293+
echo "CREATE VIRTUAL TABLE gufi USING gufi_vt("prefix", E="SELECT path() || '/' || name AS fullpath, xattr_name, xattr_value FROM xpentries;");SELECT * FROM gufi ORDER BY fullpath ASC, xattr_name ASC;"
294+
) | sqlite3
295+
prefix/.hidden||
296+
prefix/1KB||
297+
prefix/1MB|user.size|1MB
298+
prefix/directory/executable||
299+
prefix/directory/readonly||
300+
prefix/directory/subdirectory/directory_symlink||
301+
prefix/directory/subdirectory/repeat_name||
302+
prefix/directory/writable||
303+
prefix/file_symlink||
304+
prefix/leaf_directory/leaf_file1|user.name1|value1
305+
prefix/leaf_directory/leaf_file1|user.name2|value2
306+
prefix/leaf_directory/leaf_file1|user.name3|value3
307+
prefix/leaf_directory/leaf_file2|user.name4|value4
308+
prefix/leaf_directory/leaf_file2|user.name5|value5
309+
prefix/leaf_directory/leaf_file2|user.name6|value6
310+
prefix/old_file||
311+
prefix/repeat_name||
312+
prefix/unusual#? directory ,/unusual, name?#||
313+
290314
# ######################################
291315
# errors
292316
# Missing indexroot (error)

test/regression/gufi_vt.sh.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ query_vt() {
140140
)
141141
query_vt "${query}"
142142

143+
echo "# xattr view"
144+
query=$(
145+
echo -n "CREATE VIRTUAL TABLE gufi USING gufi_vt(\"${INDEXROOT}\", E=\"SELECT path() || '/' || name AS fullpath, xattr_name, xattr_value FROM xpentries;\");"
146+
echo -n "SELECT * FROM gufi ORDER BY fullpath ASC, xattr_name ASC;"
147+
)
148+
query_vt "${query}"
149+
143150
echo "# ######################################"
144151
echo "# errors"
145152

0 commit comments

Comments
 (0)