From 58aa15e4290edd92ab1b59128ba53b30dc3715e3 Mon Sep 17 00:00:00 2001 From: PerikAdjust Date: Tue, 23 Apr 2024 16:08:06 +0200 Subject: [PATCH 1/4] fix for pg16 test --- .github/workflows/ci.yml | 2 +- .github/workflows/ci_dockerfile.yml | 2 ++ kafka_fdw--0.0.3.sql | 30 +++++++++++++++++++++++++++++ src/parser.c | 16 ++++++++++----- 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 kafka_fdw--0.0.3.sql diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ce6a41..a09b1c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - pg: [15, 14, 13, 12, 11, 10] + pg: [16, 15, 14, 13, 12, 11, 10] name: PostgreSQL ${{ matrix.pg }} runs-on: ubuntu-latest container: pgxn/pgxn-tools diff --git a/.github/workflows/ci_dockerfile.yml b/.github/workflows/ci_dockerfile.yml index bc83f84..2994551 100644 --- a/.github/workflows/ci_dockerfile.yml +++ b/.github/workflows/ci_dockerfile.yml @@ -13,6 +13,8 @@ jobs: fail-fast: false matrix: include: + - clang: 15 + pg: 16 - clang: 15 pg: 15 - clang: 15 diff --git a/kafka_fdw--0.0.3.sql b/kafka_fdw--0.0.3.sql new file mode 100644 index 0000000..f9203bb --- /dev/null +++ b/kafka_fdw--0.0.3.sql @@ -0,0 +1,30 @@ +CREATE TABLE kafka_fdw_offset_dump( + tbloid oid, + partition int, + "offset" bigint, + last_fetch timestamp DEFAULT statement_timestamp(), + PRIMARY KEY(tbloid, partition) +); +SELECT pg_catalog.pg_extension_config_dump('kafka_fdw_offset_dump', ''); + +CREATE FUNCTION kafka_fdw_handler() +RETURNS fdw_handler +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT; + +CREATE FUNCTION kafka_fdw_validator(text[], oid) +RETURNS void +AS 'MODULE_PATHNAME' +LANGUAGE C STRICT; + +CREATE FOREIGN DATA WRAPPER kafka_fdw + HANDLER kafka_fdw_handler + VALIDATOR kafka_fdw_validator; + +CREATE FUNCTION kafka_get_watermarks(IN rel regclass, + OUT partition int, + OUT offset_low bigint, + OUT offset_high bigint) +RETURNS SETOF record +AS 'MODULE_PATHNAME', 'kafka_get_watermarks' +LANGUAGE C STRICT; diff --git a/src/parser.c b/src/parser.c index 4efb8b7..9a767cf 100644 --- a/src/parser.c +++ b/src/parser.c @@ -397,17 +397,23 @@ get_json_as_hash(char *json, int len, const char *funcname) state->lex = lex; sem->semstate = (void *) state; - sem->array_start = hash_array_start; - sem->scalar = hash_scalar; - sem->object_field_start = hash_object_field_start; - sem->object_field_end = hash_object_field_end; + sem->array_start = (void *) hash_array_start; + sem->scalar = (void *) hash_scalar; + sem->object_field_start = (void *) hash_object_field_start; + sem->object_field_end = (void *) hash_object_field_end; #if PG_VERSION_NUM < 130000 pg_parse_json(lex, sem); -#else +#elif PG_VERSION_NUM < 160000 JsonParseErrorType error; if ((error = pg_parse_json(lex, sem)) != JSON_SUCCESS) json_ereport_error(error, lex); +#else + JsonParseErrorType error; + Node *minimalContext = (Node *)malloc(sizeof(Node)); + if ((error = pg_parse_json(lex, sem)) != JSON_SUCCESS) + json_errsave_error(error, lex,minimalContext); + free(minimalContext); #endif return tab; From 924a2f17846a75506b2a89d7e63dfe2fcf7b9db6 Mon Sep 17 00:00:00 2001 From: PerikAdjust Date: Tue, 21 May 2024 16:50:14 +0200 Subject: [PATCH 2/4] correction after feedback --- src/parser.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/parser.c b/src/parser.c index 9a767cf..d5deb63 100644 --- a/src/parser.c +++ b/src/parser.c @@ -15,10 +15,10 @@ /* parse json */ static HTAB *get_json_as_hash(char *json, int len, const char *funcname); -static void hash_object_field_start(void *state, char *fname, bool isnull); -static void hash_object_field_end(void *state, char *fname, bool isnull); -static void hash_array_start(void *state); -static void hash_scalar(void *state, char *token, JsonTokenType tokentype); +static JsonParseErrorType hash_object_field_start(void *state, char *fname, bool isnull); +static JsonParseErrorType hash_object_field_end(void *state, char *fname, bool isnull); +static JsonParseErrorType hash_array_start(void *state); +static JsonParseErrorType hash_scalar(void *state, char *token, JsonTokenType tokentype); /* encode json */ @@ -397,35 +397,27 @@ get_json_as_hash(char *json, int len, const char *funcname) state->lex = lex; sem->semstate = (void *) state; - sem->array_start = (void *) hash_array_start; - sem->scalar = (void *) hash_scalar; - sem->object_field_start = (void *) hash_object_field_start; - sem->object_field_end = (void *) hash_object_field_end; + sem->array_start = hash_array_start; + sem->scalar = hash_scalar; + sem->object_field_start = hash_object_field_start; + sem->object_field_end = hash_object_field_end; #if PG_VERSION_NUM < 130000 pg_parse_json(lex, sem); -#elif PG_VERSION_NUM < 160000 - JsonParseErrorType error; - if ((error = pg_parse_json(lex, sem)) != JSON_SUCCESS) - json_ereport_error(error, lex); -#else - JsonParseErrorType error; - Node *minimalContext = (Node *)malloc(sizeof(Node)); - if ((error = pg_parse_json(lex, sem)) != JSON_SUCCESS) - json_errsave_error(error, lex,minimalContext); - free(minimalContext); +#else + pg_parse_json_or_ereport(lex, sem); #endif return tab; } -static void +static JsonParseErrorType hash_object_field_start(void *state, char *fname, bool isnull) { JHashState *_state = (JHashState *) state; if (_state->lex->lex_level > 1) - return; + return JSON_SUCCESS; if (_state->lex->token_type == JSON_TOKEN_ARRAY_START || _state->lex->token_type == JSON_TOKEN_OBJECT_START) { @@ -439,7 +431,7 @@ hash_object_field_start(void *state, char *fname, bool isnull) } } -static void +static JsonParseErrorType hash_object_field_end(void *state, char *fname, bool isnull) { JHashState * _state = (JHashState *) state; @@ -450,7 +442,7 @@ hash_object_field_end(void *state, char *fname, bool isnull) * Ignore nested fields. */ if (_state->lex->lex_level > 1) - return; + return JSON_SUCCESS; /* * Ignore field names >= NAMEDATALEN - they can't match a record field. @@ -460,7 +452,7 @@ hash_object_field_end(void *state, char *fname, bool isnull) * has previously insisted on exact equality, so we keep this behavior.) */ if (strlen(fname) >= NAMEDATALEN) - return; + return JSON_SUCCESS; hashentry = hash_search(_state->hash, fname, HASH_ENTER, &found); @@ -486,7 +478,7 @@ hash_object_field_end(void *state, char *fname, bool isnull) } } -static void +static JsonParseErrorType hash_array_start(void *state) { JHashState *_state = (JHashState *) state; @@ -495,9 +487,11 @@ hash_array_start(void *state) ereport( ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cannot call %s on an array", _state->function_name))); + + return JSON_SUCCESS; } -static void +static JsonParseErrorType hash_scalar(void *state, char *token, JsonTokenType tokentype) { JHashState *_state = (JHashState *) state; @@ -509,6 +503,8 @@ hash_scalar(void *state, char *token, JsonTokenType tokentype) if (_state->lex->lex_level == 1) _state->saved_scalar = token; + + return JSON_SUCCESS; } static int From 27656786fbc26534fccc7889fd78695b3127b5ce Mon Sep 17 00:00:00 2001 From: PerikAdjust Date: Tue, 21 May 2024 17:13:02 +0200 Subject: [PATCH 3/4] small test --- src/parser.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/parser.c b/src/parser.c index d5deb63..f58762f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -15,10 +15,10 @@ /* parse json */ static HTAB *get_json_as_hash(char *json, int len, const char *funcname); -static JsonParseErrorType hash_object_field_start(void *state, char *fname, bool isnull); -static JsonParseErrorType hash_object_field_end(void *state, char *fname, bool isnull); -static JsonParseErrorType hash_array_start(void *state); -static JsonParseErrorType hash_scalar(void *state, char *token, JsonTokenType tokentype); +static void hash_object_field_start(void *state, char *fname, bool isnull); +static void hash_object_field_end(void *state, char *fname, bool isnull); +static void hash_array_start(void *state); +static void hash_scalar(void *state, char *token, JsonTokenType tokentype); /* encode json */ @@ -411,13 +411,13 @@ get_json_as_hash(char *json, int len, const char *funcname) return tab; } -static JsonParseErrorType +static void hash_object_field_start(void *state, char *fname, bool isnull) { JHashState *_state = (JHashState *) state; if (_state->lex->lex_level > 1) - return JSON_SUCCESS; + return; if (_state->lex->token_type == JSON_TOKEN_ARRAY_START || _state->lex->token_type == JSON_TOKEN_OBJECT_START) { @@ -431,7 +431,7 @@ hash_object_field_start(void *state, char *fname, bool isnull) } } -static JsonParseErrorType +static void hash_object_field_end(void *state, char *fname, bool isnull) { JHashState * _state = (JHashState *) state; @@ -442,7 +442,7 @@ hash_object_field_end(void *state, char *fname, bool isnull) * Ignore nested fields. */ if (_state->lex->lex_level > 1) - return JSON_SUCCESS; + return; /* * Ignore field names >= NAMEDATALEN - they can't match a record field. @@ -452,7 +452,7 @@ hash_object_field_end(void *state, char *fname, bool isnull) * has previously insisted on exact equality, so we keep this behavior.) */ if (strlen(fname) >= NAMEDATALEN) - return JSON_SUCCESS; + return; hashentry = hash_search(_state->hash, fname, HASH_ENTER, &found); @@ -478,7 +478,7 @@ hash_object_field_end(void *state, char *fname, bool isnull) } } -static JsonParseErrorType +static void hash_array_start(void *state) { JHashState *_state = (JHashState *) state; @@ -486,12 +486,10 @@ hash_array_start(void *state) if (_state->lex->lex_level == 0) ereport( ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cannot call %s on an array", _state->function_name))); - - return JSON_SUCCESS; + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cannot call %s on an array", _state->function_name))); } -static JsonParseErrorType +static void hash_scalar(void *state, char *token, JsonTokenType tokentype) { JHashState *_state = (JHashState *) state; @@ -503,8 +501,6 @@ hash_scalar(void *state, char *token, JsonTokenType tokentype) if (_state->lex->lex_level == 1) _state->saved_scalar = token; - - return JSON_SUCCESS; } static int From e001ef41cffd2cca0e6dc33c46f2bbfb20f0c99a Mon Sep 17 00:00:00 2001 From: Artur Zakirov Date: Fri, 24 May 2024 15:43:19 +0200 Subject: [PATCH 4/4] Conditionally return JsonParseErrorType type --- src/parser.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/src/parser.c b/src/parser.c index f58762f..c5fd6f6 100644 --- a/src/parser.c +++ b/src/parser.c @@ -15,10 +15,17 @@ /* parse json */ static HTAB *get_json_as_hash(char *json, int len, const char *funcname); -static void hash_object_field_start(void *state, char *fname, bool isnull); -static void hash_object_field_end(void *state, char *fname, bool isnull); -static void hash_array_start(void *state); -static void hash_scalar(void *state, char *token, JsonTokenType tokentype); +#if PG_VERSION_NUM >=160000 +static JsonParseErrorType hash_object_field_start(void *state, char *fname, bool isnull); +static JsonParseErrorType hash_object_field_end(void *state, char *fname, bool isnull); +static JsonParseErrorType hash_array_start(void *state); +static JsonParseErrorType hash_scalar(void *state, char *token, JsonTokenType tokentype); +#else +static void hash_object_field_start(void *state, char *fname, bool isnull); +static void hash_object_field_end(void *state, char *fname, bool isnull); +static void hash_array_start(void *state); +static void hash_scalar(void *state, char *token, JsonTokenType tokentype); +#endif /* encode json */ @@ -411,13 +418,21 @@ get_json_as_hash(char *json, int len, const char *funcname) return tab; } +#if PG_VERSION_NUM >= 160000 +static JsonParseErrorType +#else static void +#endif hash_object_field_start(void *state, char *fname, bool isnull) { JHashState *_state = (JHashState *) state; if (_state->lex->lex_level > 1) - return; +#if PG_VERSION_NUM >= 160000 + return JSON_SUCCESS; +#else + return; +#endif if (_state->lex->token_type == JSON_TOKEN_ARRAY_START || _state->lex->token_type == JSON_TOKEN_OBJECT_START) { @@ -429,9 +444,17 @@ hash_object_field_start(void *state, char *fname, bool isnull) /* must be a scalar */ _state->save_json_start = NULL; } + +#if PG_VERSION_NUM >= 160000 + return JSON_SUCCESS; +#endif } +#if PG_VERSION_NUM >= 160000 +static JsonParseErrorType +#else static void +#endif hash_object_field_end(void *state, char *fname, bool isnull) { JHashState * _state = (JHashState *) state; @@ -442,7 +465,11 @@ hash_object_field_end(void *state, char *fname, bool isnull) * Ignore nested fields. */ if (_state->lex->lex_level > 1) - return; +#if PG_VERSION_NUM >= 160000 + return JSON_SUCCESS; +#else + return; +#endif /* * Ignore field names >= NAMEDATALEN - they can't match a record field. @@ -452,7 +479,11 @@ hash_object_field_end(void *state, char *fname, bool isnull) * has previously insisted on exact equality, so we keep this behavior.) */ if (strlen(fname) >= NAMEDATALEN) - return; +#if PG_VERSION_NUM >= 160000 + return JSON_SUCCESS; +#else + return; +#endif hashentry = hash_search(_state->hash, fname, HASH_ENTER, &found); @@ -476,9 +507,17 @@ hash_object_field_end(void *state, char *fname, bool isnull) /* must have had a scalar instead */ hashentry->val = _state->saved_scalar; } + +#if PG_VERSION_NUM >= 160000 + return JSON_SUCCESS; +#endif } +#if PG_VERSION_NUM >= 160000 +static JsonParseErrorType +#else static void +#endif hash_array_start(void *state) { JHashState *_state = (JHashState *) state; @@ -487,9 +526,17 @@ hash_array_start(void *state) ereport( ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cannot call %s on an array", _state->function_name))); + +#if PG_VERSION_NUM >= 160000 + return JSON_SUCCESS; +#endif } +#if PG_VERSION_NUM >= 160000 +static JsonParseErrorType +#else static void +#endif hash_scalar(void *state, char *token, JsonTokenType tokentype) { JHashState *_state = (JHashState *) state; @@ -501,6 +548,10 @@ hash_scalar(void *state, char *token, JsonTokenType tokentype) if (_state->lex->lex_level == 1) _state->saved_scalar = token; + +#if PG_VERSION_NUM >= 160000 + return JSON_SUCCESS; +#endif } static int