fingerprint

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package fingerprint computes libpg_query's version-3 query fingerprints (pg_query_fingerprint.c + the generated pg_query_fingerprint_defs.c / pg_query_fingerprint_conds.c at the pinned 18.0.0).

Like the JSON emitter (internal/emit), the per-node walk is driven by protobuf reflection rather than generated per-node code: the upstream defs are generated from the same struct metadata the pinned pg_query.proto was generated from, so the descriptor already carries the field names, the alphabetical field order (sorted here), and the field kinds that select the per-type emission rule. The hand-written parts below mirror the upstream generator's special-case tables (scripts/generate_fingerprint_outfuncs.rb) and pg_query_fingerprint.c's hand-written value-node/list handling.

The C implementation streams tokens into an XXH3 state and snapshots the state to elide fields whose subtree contributed nothing. Appending zero bytes is the only way the digest stays unchanged, so this port streams the tokens into a byte buffer instead and elides by truncating; the digest is a one-shot XXH3 of the buffer. This keeps internal/xxh3 free of streaming state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Node

func Node(n *ast.Node) uint64

Node fingerprints a single node: pg_query_fingerprint_node (used by normalize's GROUP BY matching).

func Tree

func Tree(tree *ast.ParseResult) uint64

Tree fingerprints a full parse result (pg_query_fingerprint's _fingerprintNode over the raw statement list).

func TreeWithEmpties

func TreeWithEmpties(tree *ast.ParseResult, empties map[any]bool) uint64

TreeWithEmpties is Tree with the parser's present-but-empty string set: the C fingerprint emits a field name for a non-NULL empty string (COMMENT ... IS ”), which proto3 cannot represent in the tree alone.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL