Skip to content

Add file_fdw support for external decompressors #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Fix population of program, null list issue
Turns out it's unsafe to modify a list while iterating over it, since
the delete method actually frees the node (and possibly the list, too!)
rather than just updating the next/prev pointers.
  • Loading branch information
jasonmp85 committed Dec 31, 2013
commit 51fa91adf1479767c674611d44f9aef9679637e5
29 changes: 19 additions & 10 deletions contrib/file_fdw/file_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,9 @@ fileGetOptions(Oid foreigntableid,
ListCell *lc,
*prev;

char *decompressor = NULL;
char *decompressor;
char *write_ptr, *token, *input, *read_ptr;

bool gzip_found, filename_found;
gzip_found = filename_found = FALSE;

/*
* Extract options from FDW objects. We ignore user mappings because
* file_fdw doesn't have any options that can be specified there.
Expand All @@ -372,7 +369,7 @@ fileGetOptions(Oid foreigntableid,
options = list_concat(options, get_file_fdw_attribute_options(foreigntableid));

/*
* Separate out the filename and decompressor.
* Separate out the filename.
*/
*filename = NULL;
prev = NULL;
Expand All @@ -384,17 +381,29 @@ fileGetOptions(Oid foreigntableid,
{
*filename = defGetString(def);
options = list_delete_cell(options, lc, prev);
filename_found = TRUE;
break;
}
else if (strcmp(def->defname, "decompressor") == 0)

prev = lc;
}

/*
* Separate out the decompressor, which will be used to calculate program.
*/
decompressor = NULL;
*program = NULL;
prev = NULL;
foreach(lc, options)
{
DefElem *def = (DefElem *) lfirst(lc);

if (strcmp(def->defname, "decompressor") == 0)
{
decompressor = defGetString(def);
options = list_delete_cell(options, lc, prev);
gzip_found = TRUE;
break;
}

if (filename_found && gzip_found) break;

prev = lc;
}

Expand Down