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

fix for pg16 test #49

Merged
merged 4 commits into from
Jun 17, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci_dockerfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
fail-fast: false
matrix:
include:
- clang: 15
pg: 16
- clang: 15
pg: 15
- clang: 15
Expand Down
30 changes: 30 additions & 0 deletions kafka_fdw--0.0.3.sql
Original file line number Diff line number Diff line change
@@ -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;
67 changes: 58 additions & 9 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -404,22 +411,28 @@ get_json_as_hash(char *json, int len, const char *funcname)

#if PG_VERSION_NUM < 130000
pg_parse_json(lex, sem);
#else
JsonParseErrorType error;
if ((error = pg_parse_json(lex, sem)) != JSON_SUCCESS)
json_ereport_error(error, lex);
#else
pg_parse_json_or_ereport(lex, sem);
#endif

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)
#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)
{
Expand All @@ -431,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;
Expand All @@ -444,7 +465,11 @@ hash_object_field_end(void *state, char *fname, bool isnull)
* Ignore nested fields.
*/
if (_state->lex->lex_level > 1)
#if PG_VERSION_NUM >= 160000
return JSON_SUCCESS;
#else
return;
#endif

/*
* Ignore field names >= NAMEDATALEN - they can't match a record field.
Expand All @@ -454,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)
#if PG_VERSION_NUM >= 160000
return JSON_SUCCESS;
#else
return;
#endif

hashentry = hash_search(_state->hash, fname, HASH_ENTER, &found);

Expand All @@ -478,20 +507,36 @@ 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;

if (_state->lex->lex_level == 0)
ereport(
ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cannot call %s on an array", _state->function_name)));
(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;
Expand All @@ -503,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
Expand Down
Loading