Skip to content

Latest commit

 

History

History
178 lines (149 loc) · 10.1 KB

README.md

File metadata and controls

178 lines (149 loc) · 10.1 KB

Hoglake / Trino integration tests

The native connector is maintained in PostHog/truffle. It builds and ships with the engine, using the same SPI, Parquet reader, and S3 filesystem versions. Connector unit tests and configuration documentation live there too.

This directory retains the server integration harness: it starts Postgres, MinIO, and the Hoglake server, then runs JDBC queries against a Trino image containing the connector. The REST contract and server behavior remain owned by Hoglake.

Run

Truffle publishes the server image with plugin/hoglake to ghcr.io/posthog/truffle. The image is public. It only supports ARM64. Select the greatest release tag in lexicographic order (r<position>-<sha6>):

cd server
flox activate -- ./gradlew :trino:test \
  -PhoglakeTrinoImage=ghcr.io/posthog/truffle:$( \
    curl -fsS -H "Authorization: Bearer $(curl -fsS 'https://ghcr.io/token?scope=repository:posthog/truffle:pull' | jq -r .token)" \
      'https://ghcr.io/v2/posthog/truffle/tags/list?n=1000' \
    | jq -r '.tags[]' | grep -E '^r[0-9]{12}-[0-9a-f]{6}$' | sort | tail -1)

Alternatively, set HOGLAKE_TRINO_IMAGE. For reproducible results, pin an immutable tag or digest. Start Docker before running the tests. The full Gradle test suite includes this harness. It requires the same image setting. -PunitOnly excludes the harness.

The trino-test job in server.yml uses the same default on an ARM runner. The HOGLAKE_TRINO_IMAGE repository variable overrides the default in CI. If the variable pins a legacy image, update it to a verified Truffle reference or remove it to use the default. The deploy job does not depend on this check.

There is deliberately no default Trino image and no local plugin mount: the tests exercise the connector shipped in the selected engine image. The old Gradle :trino:trinoPlugin assembly task and Trino 446 SPI pin have been removed. The JDBC client is pinned in build.gradle.kts (currently 483) and moves independently of the server version, so this harness can continue using the server project's Java 25 toolchain. Its failure-message format is load-bearing: the assertions strip the driver's Query failed (#...) preamble before matching, and assert that the strip matched rather than trusting it.

The tests cover schema/table discovery, Parquet reads, aggregates, column binding, type promotion, and deletion-vector application. The planned Iceberg REST facade remains a separate server feature.

The harness issues no DML. Every fixture is seeded through Hoglake's REST API and every case is a SHOW/DESCRIBE/SELECT, so the connector's write path — claimed uploads, /commit/mutations/prepared, /commit/transaction — is not exercised here at all. Two guarded-DML contracts consequently have no harness case, and neither is expressible without first giving the harness a write path of its own:

  • A deletion-vector target retired since read_snapshot is a 409, and the connector re-plans. Needs the connector to issue a DELETE that races a compaction. Even with DML, a successful internal retry is indistinguishable in the query result from one that never raced, so the assertion would have to pin fork behaviour (a retry count, a log line) — which the harness rules out.
  • An append-only transaction still sends an empty delete group for a table it read. That is a request shape; the harness observes SQL results, not the requests the connector sends, and has no interception point.

Adding connector DML (S3 write credentials in the engine container, upload claims, a publication path verified against the pinned fork image) is its own change, not a rider on a server-side fix. Until then both contracts are covered only by the server suite.

Deletion vectors

The connector applies deletion vectors; it does not refuse them. A read of a DV-backed table returns the surviving rows, and the harness asserts that as correctness, not as a refusal. The fixtures write real puffin deletion-vector-v1 bytes (TestPuffin, the byte-level twin of the server suite's PuffinTestFiles), because the connector opens the object, decodes the roaring bitmap, and checks its referenced-data-file and cardinality against the scan's pairing — a nominal DV path only ever produces a read failure.

The connector counts a DV-backed table on two paths, and the harness asserts the same answer on both. An unfiltered count(*) needs no columns, so it answers from catalog metadata (record_count minus the vector's delete_count) after reading and validating the vector. Any read that needs a column applies the vector per page inside the connector's page source, over row positions relative to each data file, after row-group pruning. (That the metadata path skips the Parquet file entirely is the connector's documented behavior and is visible in EXPLAIN ANALYZE as a TableScan with no physical input, but no assertion here observes it.)

Deleted positions are ordinals inside their own data file. A single-file table cannot tell that apart from table-global numbering, so multi_file_events holds two byte-identical files with the vector on the second one — the only fixture where the two numberings give different answers.

Two refusals are asserted, both of them cases only the reader can catch because hoglake never opens DV files: a vector whose cardinality disagrees with the scan's delete_count, and a vector whose blob names a different data file than the one it was paired with. The connector refuses more than these (missing, truncated, bad checksum, wrong format, positions past the row count); those are covered by the connector's own suite in PostHog/truffle, not here. The mismatch case is also the only assertion proving the metadata-count path decodes the bitmap rather than trusting delete_count.

This puts a floor under the fork image: these assertions fail against any image built before PostHog/truffle's "Apply deletion vectors to Hoglake reads" (d4d5fa2, first published as r000000046914-6e5fcd), which refuses DV-bearing scans at split planning. There is no harness-side way to satisfy both behaviors.

A later Truffle image can still regress deletion-vector support. If that occurs, use HOGLAKE_TRINO_IMAGE to pin an image with known support. Do not weaken the assertions.

Message assertions here match no fork prose at all — no required phrase, no excluded one. An exclusion evaporates silently the moment upstream rewords the string it names; a required phrase reds a correct image the moment upstream rewords it the other way, and even deletion vector is a live example, since hoglake's own blob type is spelled deletion-vector-v1. deletionVectorFailureBody therefore matches only object paths hoglake itself registered, and discriminates nothing on its own.

Each test asserts its own discriminator on the returned body, with the reason written beside it. The two in use are the referenced-data-file path, which exists only inside the blob's bytes, and the pair of delete counts — declared and decoded — which must differ, since the pre-DV refusal prints exactly one number. That refusal also printed the topic, the vector's path, the paired data file, and the declared count, so nothing weaker than these separates a connector that validates vectors from one that refuses them unread.

Two known limits, both accepted rather than fixed. A path discriminator is stronger than a numeric one: assertStandaloneNumber cannot tell the number it wants from a coincidental one elsewhere in a sentence, and the cardinality check is role-blind — a connector reporting the two counts the wrong way round would pass. And nothing structural stops the next refusal test from calling deletionVectorFailureBody and asserting nothing further, which would pass on a pre-DV image; the javadoc says so in those words, and that is the only guard.

The connector also supports CREATE TABLE, INSERT, and CTAS as of 2026-09-16. The harness does not exercise the write path — the connector's own suite does — so nothing here asserts read-only behavior.

SQL DELETE rollout

Deploy idempotent-delete-v1 to every Hoglake replica before rolling out the Trino connector that writes deletion vectors. /commit/deletes/prepared requires a snapshot, table UUID per delete group, and catalog-scoped operation UUID; it publishes all vectors atomically using the existing commit lock and durable receipt. It also accepts empty file lists for zero-row statements, validating identity and the DDL conflict window before recording the result. Legacy commit endpoints continue to reject empty delete file lists.

Full-payload replay returns the original result even after vector supersession, DDL or snapshot expiry. Missing receipts do not fence an in-flight publication. The connector retains uploads after submission if the outcome is uncertain. Deletes reject newer vectors on the same file and removed/compacted target files; concurrent appends are allowed and remain outside the pinned DELETE snapshot. No schema migration or new receipt store is needed. The new endpoint prevents old replicas from silently accepting a weaker contract.

SQL UPDATE and MERGE rollout

Deploy idempotent-mutation-v1 to every server replica first, then roll out Trino UPDATE/MERGE support. /commit/mutations/prepared reuses the commit transaction and full-payload receipt store to publish appends and deletion vectors in a single snapshot. It requires a read snapshot, operation UUID and table UUID guards, including an empty delete group for insert-only or no-op statements. No schema migration is needed. The delete-only endpoint remains unchanged and rejects appends.

Prepared mutations reject any intervening target-table change, including INSERT, DELETE, compaction, schema changes and lifecycle operations. Unrelated tables may change. Replays return the original receipt before current-state checks; both appended files and vectors are covered by the receipt. Unknown outcomes must retain all potentially committed uploads. MERGE provides SQL match semantics, not unique-key enforcement. Partitioned/sorted writes and new writable types are outside this contract's connector scope.