Rename conflicting Avro fields
When a user defined field conflicts with an internal MaxScale field, the field is suffixed with an underscore.
This commit is contained in:
@ -71,6 +71,23 @@ static const char *avro_event_type = "event_type";
|
|||||||
static const char *avro_timestamp = "timestamp";
|
static const char *avro_timestamp = "timestamp";
|
||||||
static char *avro_client_ouput[] = { "Undefined", "JSON", "Avro" };
|
static char *avro_client_ouput[] = { "Undefined", "JSON", "Avro" };
|
||||||
|
|
||||||
|
static inline bool is_reserved_word(const char* word)
|
||||||
|
{
|
||||||
|
return strcasecmp(word, avro_domain) == 0 ||
|
||||||
|
strcasecmp(word, avro_server_id) == 0 ||
|
||||||
|
strcasecmp(word, avro_sequence) == 0 ||
|
||||||
|
strcasecmp(word, avro_event_number) == 0 ||
|
||||||
|
strcasecmp(word, avro_event_type) == 0 ||
|
||||||
|
strcasecmp(word, avro_timestamp) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void fix_reserved_word(char *tok)
|
||||||
|
{
|
||||||
|
if (is_reserved_word(tok))
|
||||||
|
{
|
||||||
|
strcat(tok, "_");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** How a binlog file is closed */
|
/** How a binlog file is closed */
|
||||||
typedef enum avro_binlog_end
|
typedef enum avro_binlog_end
|
||||||
|
@ -584,6 +584,7 @@ static int process_column_definition(const char *nameptr, char*** dest, char***
|
|||||||
char type[100] = "";
|
char type[100] = "";
|
||||||
int len = extract_type_length(nameptr, type);
|
int len = extract_type_length(nameptr, type);
|
||||||
nameptr = next_field_definition(nameptr);
|
nameptr = next_field_definition(nameptr);
|
||||||
|
fix_reserved_word(colname);
|
||||||
|
|
||||||
lengths[i] = len;
|
lengths[i] = len;
|
||||||
types[i] = strdup(type);
|
types[i] = strdup(type);
|
||||||
@ -834,11 +835,15 @@ void make_avro_token(char* dest, const char* src, int length)
|
|||||||
|
|
||||||
memcpy(dest, src, length);
|
memcpy(dest, src, length);
|
||||||
dest[length] = '\0';
|
dest[length] = '\0';
|
||||||
|
fix_reserved_word(dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_column_index(TABLE_CREATE *create, const char *tok)
|
int get_column_index(TABLE_CREATE *create, const char *tok)
|
||||||
{
|
{
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
|
char safe_tok[strlen(tok) + 2];
|
||||||
|
strcpy(safe_tok, tok);
|
||||||
|
fix_reserved_word(safe_tok);
|
||||||
|
|
||||||
for (int x = 0; x < create->columns; x++)
|
for (int x = 0; x < create->columns; x++)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user