Skip to content
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

custom librdkafka options #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ KafkaFdwGetConnection(KafkaOptions *k_options,
rd_kafka_topic_conf_t *topic_conf = NULL;
rd_kafka_conf_t * conf;
char errstr[KAFKA_MAX_ERR_MSG];
ListCell *option;

/* brokers and topic should be validated just double check */

Expand All @@ -20,6 +21,15 @@ KafkaFdwGetConnection(KafkaOptions *k_options,
errstr, sizeof(errstr)) != RD_KAFKA_CONF_OK)
elog(ERROR, "%s\n", errstr);

foreach (option, k_options->options)
{
DefElem *def = (DefElem *) lfirst(option);

if (rd_kafka_conf_set(conf, def->defname + 1, defGetString(def),
errstr, sizeof(errstr)) != RD_KAFKA_CONF_OK)
elog(ERROR, "%s\n", errstr);
}

*kafka_handle = rd_kafka_new(RD_KAFKA_CONSUMER, conf, errstr, KAFKA_MAX_ERR_MSG);

if (*kafka_handle != NULL)
Expand Down
1 change: 1 addition & 0 deletions src/kafka_fdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ typedef struct KafkaOptions
bool strict; /* force strict parsing */
bool ignore_junk; /* ignore junk data by setting it to null */
int num_parse_col; /* number of parsable columns */
List *options;
} KafkaOptions;

typedef struct ParseOptions
Expand Down
10 changes: 9 additions & 1 deletion src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ is_valid_option(const char *option, Oid context)
{
const struct KafkaFdwOption *opt;

if (option[0] == '#')
return true;

for (opt = valid_options; opt->optname; opt++)
{
if (context == opt->optcontext && strcmp(opt->optname, option) == 0)
Expand Down Expand Up @@ -353,7 +356,12 @@ KafkaProcessKafkaOptions(Oid relid, KafkaOptions *kafka_options, List *options)
{
DefElem *def = (DefElem *) lfirst(option);

if (strcmp(def->defname, "topic") == 0)
if (def->defname[0] == '#')
{
kafka_options->options = lappend(kafka_options->options, def);
}

else if (strcmp(def->defname, "topic") == 0)
{
if (kafka_options->topic)
ereport(ERROR,
Expand Down
Loading