Skip to content

Commit

Permalink
Output Boolean nodes during fingerprinting (#170)
Browse files Browse the repository at this point in the history
This PR updates the fingerprinting logic to output values for the new
Boolean nodes. A minor version bump to 15-4.1.0 is included. The
formatting in `testdata/fingerprint.json` was also flattened to make it
easier to view diffs of future changes.
  • Loading branch information
msepga authored Jan 11, 2023
1 parent 20b3179 commit 346b34d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 170 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All versions are tagged by the major Postgres version, plus an individual semver for this library itself.

## 15-4.1.0 2022-12-28

* Add `Boolean` fingerprinting
- `Boolean` nodes are now output during fingerprinting
* Fix parsing issue on 32-bit big endian machines
- Now we use `size_t` to indicate the protobuf message size

## 15-4.0.0 2022-11-29

* Update to Postgres 15.1
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PG_VERSION = 15.1
PG_VERSION_MAJOR = $(call word-dot,$(PG_VERSION),1)
PROTOC_VERSION = 3.14.0

VERSION = 4.0.0
VERSION = 4.1.0
VERSION_MAJOR = $(call word-dot,$(VERSION),1)
VERSION_MINOR = $(call word-dot,$(VERSION),2)
VERSION_PATCH = $(call word-dot,$(VERSION),3)
Expand Down
28 changes: 24 additions & 4 deletions src/pg_query_fingerprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,34 @@ _fingerprintInteger(FingerprintContext *ctx, const union ValUnion *value)
static void
_fingerprintFloat(FingerprintContext *ctx, const union ValUnion *value)
{
if (value->sval.sval != NULL) {
if (value->fval.fval != NULL) {
// NB: We output `str` here intentionally, to match the output format from libpg_query 14
// and below. This results in stable fingerprints, despite the field name being changed in
// PG15 to `fval`.
_fingerprintString(ctx, "Float");
_fingerprintString(ctx, "str");
_fingerprintString(ctx, value->sval.sval);
_fingerprintString(ctx, value->fval.fval);
}
}

static void
_fingerprintBoolean(FingerprintContext *ctx, const union ValUnion *value)
{
_fingerprintString(ctx, "Boolean");
_fingerprintString(ctx, "boolval");
_fingerprintString(ctx, value->boolval.boolval ? "true" : "false");
}

static void
_fingerprintBitString(FingerprintContext *ctx, const union ValUnion *value)
{
if (value->sval.sval != NULL) {
if (value->bsval.bsval != NULL) {
// NB: We output `str` here intentionally, to match the output format from libpg_query 14
// and below. This results in stable fingerprints, despite the field name being changed in
// PG15 to `bsval`.
_fingerprintString(ctx, "BitString");
_fingerprintString(ctx, "str");
_fingerprintString(ctx, value->sval.sval);
_fingerprintString(ctx, value->bsval.bsval);
}
}

Expand Down Expand Up @@ -272,7 +286,13 @@ _fingerprintNode(FingerprintContext *ctx, const void *obj, const void *parent, c
case T_Float:
_fingerprintFloat(ctx, obj);
break;
case T_Boolean:
_fingerprintBoolean(ctx, obj);
break;
case T_String:
// NB: We output `str` here intentionally, to match the output format from libpg_query
// 14 and below. This results in stable fingerprints, despite the field name being
// changed in PG15 to `sval`.
_fingerprintString(ctx, "String");
_fingerprintString(ctx, "str");
_fingerprintString(ctx, ((union ValUnion*) obj)->sval.sval);
Expand Down
2 changes: 1 addition & 1 deletion test/fingerprint_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const char* tests[] = {
"CREATE PUBLICATION foo FOR TABLES IN SCHEMA bar",
"7dfa0872d08125e6",
"COPY vistest FROM stdin FREEZE CSV",
"adb3688e5278cf1c",
"25de297c6377cb74",
"MERGE INTO customer_account ca USING (VALUES (1, 42), (2, 99)) t(customer_id, transaction_value) ON t.customer_id = ca.customer_id WHEN MATCHED THEN UPDATE SET balance = balance + transaction_value + 1 WHEN NOT MATCHED THEN INSERT (customer_id, balance) VALUES (t.customer_id, t.transaction_value)",
"1cca3f304295181c",
};
Expand Down
Loading

0 comments on commit 346b34d

Please sign in to comment.