Adapt Canonical Party to the domain platform; add unit tests
Makes the blog-generated product run on the digital-core domain built from
semprini-data-domain, with the same changes the canonical template received:
- flink/job.sql connects to ods:5432/ods as postgres with ${ODS_PASSWORD},
substituted by data-domain at submission, instead of the blog's credentials
- lakehouse/010_replication.sql uses the platform's `ods` sync group and grants
the lake tables to ducklake_reader and ducklake_writer
- product.yaml sync group, odps.yaml access URLs (domain ports 20000-20003,
management zone Apicurio on 8081), CLI names in comments
Adds tests/: the canonical template's generic unit tests and this product's
expectations.yaml (seed rows, 24 constraint rejections, 5 relationship
traversals, one inbound-to-tombstone round trip).
Verified on digital-core on 2026-09-18: 65 of 65 smoke checks, 100 unit tests
passing, and registered in OpenMetadata under the digital-core domain.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cfb32d2d1b
commit
dd096ee4dc
18 files changed
+590
-93
No files matched your search
@@ -0,0 +1,193 @@
|
||||
# Canonical Party: unit test expectations, generated with ods/040_seed.sql and kept in step with it.
|
||||
# Read by the generic tests beside this file (test_*.py, copied from the canonical template).
|
||||
# Run from the domain repository: uv run data-domain unit <path to canonical-party>
|
||||
|
||||
tables:
|
||||
# rows: how many rows the seed inserts
|
||||
# samples: seed rows checked by value in the ODS, through GraphQL and in the lake (the key
|
||||
# column is required; the first sample is also the row the reject updates target)
|
||||
# rejects: updates to the first sample the ODS must refuse, with the constraint named in the
|
||||
# error ("not-null" for NOT NULL)
|
||||
party:
|
||||
rows: 4
|
||||
samples:
|
||||
- party_id: 7d1e5a2c-0001-4a7b-9c11-000000000003
|
||||
party_type: Company
|
||||
legal_name: Kowhai Trading Limited
|
||||
also_known_as: "Kowhai Trading; KTL"
|
||||
party_status: Active
|
||||
rejects:
|
||||
- set: {party_type: Robot}
|
||||
violates: party_party_type_check
|
||||
- set: {party_status: Dormant}
|
||||
violates: party_party_status_check
|
||||
- set: {legal_name: null}
|
||||
violates: not-null
|
||||
|
||||
address:
|
||||
rows: 3
|
||||
samples:
|
||||
- address_id: 7d1e5a2c-0002-4a7b-9c11-000000000001
|
||||
address_type: Street Address
|
||||
address_line_1: 1 Queen Street
|
||||
suburb: Auckland Central
|
||||
city: Auckland
|
||||
postcode: "1010"
|
||||
country: NZ
|
||||
rejects:
|
||||
- set: {address_line_1: null}
|
||||
violates: street_address_requires_address_line_1
|
||||
- set: {address_type: Castle}
|
||||
violates: address_address_type_check
|
||||
- set: {country: null}
|
||||
violates: not-null
|
||||
|
||||
person:
|
||||
rows: 2
|
||||
samples:
|
||||
- person_id: 7d1e5a2c-0001-4a7b-9c11-000000000001
|
||||
date_of_birth: 1985-03-14
|
||||
preferred_name: Alice
|
||||
country_of_residence: NZ
|
||||
rejects:
|
||||
- set: {date_of_birth: "2999-01-01"}
|
||||
violates: date_of_birth_not_in_future
|
||||
- set: {person_id: 7d1e5a2c-0001-4a7b-9c11-00000000ffff}
|
||||
violates: person_person_id_fkey
|
||||
|
||||
company:
|
||||
rows: 2
|
||||
samples:
|
||||
- company_id: 7d1e5a2c-0001-4a7b-9c11-000000000004
|
||||
company_registration_number: "123456789"
|
||||
incorporation_country: AU
|
||||
incorporation_date: 2005-03-15
|
||||
legal_structure: Private Company
|
||||
rejects:
|
||||
- set: {legal_structure: Guild}
|
||||
violates: company_legal_structure_check
|
||||
|
||||
party_role:
|
||||
rows: 3
|
||||
samples:
|
||||
- party_role_id: 7d1e5a2c-0003-4a7b-9c11-000000000003
|
||||
party_role_type: Customer
|
||||
role_status: Closed
|
||||
role_start_date: 2021-03-01
|
||||
role_end_date: 2024-08-31
|
||||
party_id: 7d1e5a2c-0001-4a7b-9c11-000000000002
|
||||
rejects:
|
||||
- set: {role_end_date: null}
|
||||
violates: closed_role_requires_end_date
|
||||
- set: {role_end_date: "2020-01-01"}
|
||||
violates: role_end_after_start
|
||||
- set: {party_role_type: Merchant}
|
||||
violates: party_role_party_role_type_check
|
||||
- set: {party_id: 7d1e5a2c-0001-4a7b-9c11-00000000ffff}
|
||||
violates: party_role_party_id_fkey
|
||||
|
||||
customer:
|
||||
rows: 3
|
||||
samples:
|
||||
- customer_id: 7d1e5a2c-0003-4a7b-9c11-000000000002
|
||||
customer_number: CUST-000002
|
||||
onboarding_date: 2018-06-01
|
||||
relationship_start_date: 2015-06-01
|
||||
rejects:
|
||||
- set: {customer_number: CUST-000001}
|
||||
violates: customer_customer_number_key
|
||||
- set: {customer_number: null}
|
||||
violates: not-null
|
||||
|
||||
contact_address:
|
||||
rows: 3
|
||||
samples:
|
||||
- contact_address_id: 7d1e5a2c-0004-4a7b-9c11-000000000001
|
||||
address_purpose: Home
|
||||
is_primary: true
|
||||
verification_status: Verified
|
||||
verification_date: 2024-02-10
|
||||
verification_method: Documentary
|
||||
valid_from: 2019-12-01
|
||||
party_id: 7d1e5a2c-0001-4a7b-9c11-000000000001
|
||||
address_id: 7d1e5a2c-0002-4a7b-9c11-000000000001
|
||||
rejects:
|
||||
- set: {verification_date: null}
|
||||
violates: verification_date_required_when_verified
|
||||
- set: {valid_to: "2019-01-01"}
|
||||
violates: valid_to_after_valid_from
|
||||
- set: {verification_method: Telepathy}
|
||||
violates: contact_address_verification_method_check
|
||||
- set: {address_id: 7d1e5a2c-0002-4a7b-9c11-00000000ffff}
|
||||
violates: contact_address_address_id_fkey
|
||||
|
||||
party_role_contact_address:
|
||||
rows: 3
|
||||
samples:
|
||||
- party_role_contact_address_id: 7d1e5a2c-0005-4a7b-9c11-000000000003
|
||||
party_role_id: 7d1e5a2c-0003-4a7b-9c11-000000000002
|
||||
contact_address_id: 7d1e5a2c-0004-4a7b-9c11-000000000003
|
||||
rejects:
|
||||
- set: {party_role_id: 7d1e5a2c-0003-4a7b-9c11-00000000ffff}
|
||||
violates: party_role_contact_address_party_role_id_fkey
|
||||
|
||||
party_association:
|
||||
rows: 3
|
||||
samples:
|
||||
- party_association_id: 7d1e5a2c-0006-4a7b-9c11-000000000003
|
||||
source_party_id: 7d1e5a2c-0001-4a7b-9c11-000000000002
|
||||
target_party_id: 7d1e5a2c-0001-4a7b-9c11-000000000001
|
||||
association_type: Partner
|
||||
association_start_date: 2016-06-01
|
||||
verified: false
|
||||
rejects:
|
||||
- set: {association_type: Nemesis}
|
||||
violates: party_association_association_type_check
|
||||
- set: {target_party_id: null}
|
||||
violates: not-null
|
||||
|
||||
# Relationship traversals in graphql/schema.graphql, checked against the seed. `expect` must be
|
||||
# contained in the response (lists compare item by item, in order).
|
||||
graphql:
|
||||
- name: person-extends-party
|
||||
query: '{ personCollection(filter: {personId: {eq: "7d1e5a2c-0001-4a7b-9c11-000000000001"}}) { edges { node { preferredName party { legalName partyType } } } } }'
|
||||
expect:
|
||||
personCollection: {edges: [{node: {preferredName: Alice, party: {legalName: Alice Margaret Ng, partyType: Person}}}]}
|
||||
- name: party-has-its-company-subtype
|
||||
query: '{ partyCollection(filter: {partyId: {eq: "7d1e5a2c-0001-4a7b-9c11-000000000004"}}) { edges { node { company { incorporationCountry } person { preferredName } } } } }'
|
||||
expect:
|
||||
partyCollection: {edges: [{node: {company: {incorporationCountry: AU}, person: null}}]}
|
||||
- name: customer-role-of-party
|
||||
query: '{ customerCollection(filter: {customerNumber: {eq: "CUST-000001"}}) { edges { node { partyRole { roleStatus party { legalName } } } } } }'
|
||||
expect:
|
||||
customerCollection: {edges: [{node: {partyRole: {roleStatus: Active, party: {legalName: Alice Margaret Ng}}}}]}
|
||||
- name: role-uses-contact-addresses
|
||||
query: '{ partyRoleCollection(filter: {partyRoleId: {eq: "7d1e5a2c-0003-4a7b-9c11-000000000001"}}) { edges { node { partyRoleContactAddressCollection(orderBy: [{partyRoleContactAddressId: AscNullsLast}]) { edges { node { contactAddress { addressPurpose address { city } } } } } } } } }'
|
||||
expect:
|
||||
partyRoleCollection: {edges: [{node: {partyRoleContactAddressCollection: {edges: [
|
||||
{node: {contactAddress: {addressPurpose: Home, address: {city: Auckland}}}},
|
||||
{node: {contactAddress: {addressPurpose: Mailing, address: {city: Wellington}}}}]}}}]}
|
||||
- name: associations-are-directional
|
||||
query: '{ partyCollection(filter: {partyId: {eq: "7d1e5a2c-0001-4a7b-9c11-000000000001"}}) { edges { node { outgoingAssociationCollection(orderBy: [{partyAssociationId: AscNullsLast}]) { edges { node { associationType targetParty { legalName } } } } incomingAssociationCollection { edges { node { associationType sourceParty { legalName } } } } } } } }'
|
||||
expect:
|
||||
partyCollection: {edges: [{node: {
|
||||
outgoingAssociationCollection: {edges: [
|
||||
{node: {associationType: Director, targetParty: {legalName: Kowhai Trading Limited}}},
|
||||
{node: {associationType: Authorised Signatory, targetParty: {legalName: Kowhai Trading Limited}}}]},
|
||||
incomingAssociationCollection: {edges: [
|
||||
{node: {associationType: Partner, sourceParty: {legalName: Rangi Parata}}}]}}}]}
|
||||
|
||||
# One record published to an inbound topic and followed through every interface, then updated
|
||||
# and deleted through GraphQL. Use a table without required foreign keys, and a key no seed row
|
||||
# uses; the test refuses to publish a record the ODS would reject.
|
||||
round_trip:
|
||||
table: address
|
||||
record:
|
||||
address_id: 7d1e5a2c-0002-4a7b-9c11-00000000e2e0
|
||||
address_type: PO Box
|
||||
address_line_1: PO Box 999
|
||||
city: Nelson
|
||||
postcode: "7040"
|
||||
country: NZ
|
||||
update:
|
||||
city: Richmond
|
||||
@@ -0,0 +1,48 @@
|
||||
"""Constraints and triggers: the ODS refuses what the model forbids, and keeps updated_at current.
|
||||
|
||||
Every statement runs in a transaction that is rolled back, so the seed is untouched. Each
|
||||
rejected update in expectations.yaml is applied to the table's first sample row and must fail
|
||||
with the named constraint (or "not-null") in PostgreSQL's error.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from semprini_data_domain.testing import expectations_for
|
||||
|
||||
TABLES = list(expectations_for(__file__)["tables"].items())
|
||||
REJECTS = [(table, reject) for table, spec in TABLES for reject in spec.get("rejects", [])]
|
||||
|
||||
|
||||
def key_of(dp, table):
|
||||
return next(t.key for t in dp.product.tables if t.name == table)
|
||||
|
||||
|
||||
def first_sample_key(dp, table, spec):
|
||||
assert spec.get("samples"), f"{table} needs a sample in expectations.yaml"
|
||||
return spec["samples"][0][key_of(dp, table)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"table,reject", REJECTS, ids=[f"{t}-{r['violates']}" for t, r in REJECTS]
|
||||
)
|
||||
def test_update_is_refused(dp, table, reject):
|
||||
spec = dict(TABLES)[table]
|
||||
key = key_of(dp, table)
|
||||
assignments = ", ".join(f"{column} = {dp.sql_literal(value)}" for column, value in reject["set"].items())
|
||||
error = dp.sql_error(
|
||||
f"UPDATE {dp.product.schema}.{table} SET {assignments} "
|
||||
f"WHERE {key} = '{first_sample_key(dp, table, spec)}'"
|
||||
)
|
||||
assert error is not None, f"{table}: update {reject['set']} was accepted"
|
||||
assert reject["violates"] in error, error
|
||||
|
||||
|
||||
@pytest.mark.parametrize("table,spec", TABLES, ids=[t for t, _ in TABLES])
|
||||
def test_update_sets_updated_at(dp, table, spec):
|
||||
key = key_of(dp, table)
|
||||
sample_key = first_sample_key(dp, table, spec)
|
||||
rows = dp.sql_rolled_back(
|
||||
f"UPDATE {dp.product.schema}.{table} SET {key} = {key} WHERE {key} = '{sample_key}'",
|
||||
f"SELECT updated_at > created_at AS moved FROM {dp.product.schema}.{table} WHERE {key} = '{sample_key}'",
|
||||
)
|
||||
assert rows == [{"moved": True}]
|
||||
@@ -0,0 +1,47 @@
|
||||
"""CRUD API: pg_graphql reflects every column of every table, serves the seed rows, and
|
||||
resolves the relationships the product documents in graphql/schema.graphql.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from semprini_data_domain.platform import camel, pascal
|
||||
from semprini_data_domain.testing import contains, expectations_for, same_value
|
||||
|
||||
EXPECT = expectations_for(__file__)
|
||||
TABLES = list(EXPECT["tables"].items())
|
||||
SAMPLES = [(table, sample) for table, spec in TABLES for sample in spec.get("samples", [])]
|
||||
QUERIES = EXPECT.get("graphql", [])
|
||||
|
||||
|
||||
def key_of(dp, table):
|
||||
return next(t.key for t in dp.product.tables if t.name == table)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("table,spec", TABLES, ids=[t for t, _ in TABLES])
|
||||
def test_type_reflects_every_column(dp, table, spec):
|
||||
data = dp.graphql(f'{{ __type(name: "{pascal(table)}") {{ fields {{ name }} }} }}')
|
||||
assert data["__type"], f"type {pascal(table)} not reflected"
|
||||
fields = {f["name"] for f in data["__type"]["fields"]}
|
||||
missing = [camel(c) for c in dp.columns(table) if camel(c) not in fields]
|
||||
assert not missing, f"{pascal(table)} lacks {missing}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("table,sample", SAMPLES, ids=[t for t, _ in SAMPLES])
|
||||
def test_seed_row_through_graphql(dp, table, sample):
|
||||
key = key_of(dp, table)
|
||||
fields = " ".join(camel(column) for column in sample)
|
||||
data = dp.graphql(
|
||||
f'{{ {camel(table)}Collection(filter: {{{camel(key)}: {{eq: "{sample[key]}"}}}}) '
|
||||
f"{{ edges {{ node {{ {fields} }} }} }} }}"
|
||||
)
|
||||
edges = data[f"{camel(table)}Collection"]["edges"]
|
||||
assert len(edges) == 1, f"{table} {sample[key]}: {edges}"
|
||||
node = edges[0]["node"]
|
||||
for column, expected in sample.items():
|
||||
assert same_value(expected, node[camel(column)]), f"{camel(column)}: {node[camel(column)]!r} != {expected!r}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("case", QUERIES, ids=[q["name"] for q in QUERIES])
|
||||
def test_relationship(dp, case):
|
||||
data = dp.graphql(case["query"])
|
||||
assert contains(case["expect"], data), f"{data} does not contain {case['expect']}"
|
||||
@@ -0,0 +1,33 @@
|
||||
"""Analytic SQL: pg_duckpipe has replicated every seed row into the lake, and Trino serves it."""
|
||||
|
||||
import pytest
|
||||
|
||||
from semprini_data_domain.testing import expectations_for, same_value
|
||||
|
||||
TABLES = list(expectations_for(__file__)["tables"].items())
|
||||
SAMPLES = [(table, sample) for table, spec in TABLES for sample in spec.get("samples", [])]
|
||||
|
||||
|
||||
def key_of(dp, table):
|
||||
return next(t.key for t in dp.product.tables if t.name == table)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("table,spec", TABLES, ids=[t for t, _ in TABLES])
|
||||
def test_lake_matches_ods(dp, table, spec):
|
||||
lake = f"{dp.product.trino_catalog}.{dp.product.lake_schema}.{table}"
|
||||
ods = dp.sql(f"SELECT count(*) AS n FROM {dp.product.schema}.{table}")[0]["n"]
|
||||
assert ods == spec["rows"]
|
||||
dp.eventually(lambda: dp.trino(f"SELECT count(*) AS n FROM {lake}") == [{"n": ods}])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("table,sample", SAMPLES, ids=[t for t, _ in SAMPLES])
|
||||
def test_seed_row_in_lake(dp, table, sample):
|
||||
key = key_of(dp, table)
|
||||
lake = f"{dp.product.trino_catalog}.{dp.product.lake_schema}.{table}"
|
||||
# Every column is cast to varchar so dates and uuids compare as text, the way the seed writes them.
|
||||
columns = ", ".join(f"CAST({column} AS varchar) AS {column}" for column in sample)
|
||||
rows = dp.trino(f"SELECT {columns} FROM {lake} WHERE CAST({key} AS varchar) = '{sample[key]}'")
|
||||
assert len(rows) == 1, f"{sample[key]} not in {lake}"
|
||||
for column, expected in sample.items():
|
||||
want = None if expected is None else (str(expected).lower() if isinstance(expected, bool) else expected)
|
||||
assert same_value(want, rows[0][column]), f"{column}: {rows[0][column]!r} != {expected!r}"
|
||||
@@ -0,0 +1,31 @@
|
||||
"""Seed data: every ODS table holds the rows ods/040_seed.sql inserts, with the values it inserts.
|
||||
|
||||
Generic canonical-product test, copied unchanged into every product. What to expect comes
|
||||
from expectations.yaml beside it. Run from the domain repository: data-domain unit <product>.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from semprini_data_domain.testing import expectations_for, same_value
|
||||
|
||||
TABLES = list(expectations_for(__file__)["tables"].items())
|
||||
SAMPLES = [(table, sample) for table, spec in TABLES for sample in spec.get("samples", [])]
|
||||
|
||||
|
||||
def key_of(dp, table):
|
||||
return next(t.key for t in dp.product.tables if t.name == table)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("table,spec", TABLES, ids=[t for t, _ in TABLES])
|
||||
def test_seed_row_count(dp, table, spec):
|
||||
rows = dp.sql(f"SELECT count(*) AS n FROM {dp.product.schema}.{table}")
|
||||
assert rows[0]["n"] == spec["rows"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("table,sample", SAMPLES, ids=[t for t, _ in SAMPLES])
|
||||
def test_seed_row_values(dp, table, sample):
|
||||
key = key_of(dp, table)
|
||||
rows = dp.sql(f"SELECT * FROM {dp.product.schema}.{table} WHERE {key} = '{sample[key]}'")
|
||||
assert len(rows) == 1, f"seed row {sample[key]} not in {table}"
|
||||
for column, expected in sample.items():
|
||||
assert same_value(expected, rows[0][column]), f"{table}.{column}: {rows[0][column]!r} != {expected!r}"
|
||||
@@ -0,0 +1,75 @@
|
||||
"""Publish input and subscribe output.
|
||||
|
||||
Every row is on the table's compacted outbound topic, and one record published to an inbound
|
||||
topic travels through every interface: ODS, outbound topic, lake, then a GraphQL update and a
|
||||
GraphQL delete that follow it back out. The record is checked against the ODS constraints
|
||||
before it is published, because a record the ODS refuses stops the product's Flink job.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from semprini_data_domain.platform import camel, pascal
|
||||
from semprini_data_domain.testing import contains, expectations_for
|
||||
|
||||
EXPECT = expectations_for(__file__)
|
||||
TABLES = list(EXPECT["tables"].items())
|
||||
ROUND_TRIP = EXPECT.get("round_trip")
|
||||
|
||||
|
||||
def key_of(dp, table):
|
||||
return next(t.key for t in dp.product.tables if t.name == table)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("table,spec", TABLES, ids=[t for t, _ in TABLES])
|
||||
def test_outbound_topic_carries_every_row(dp, table, spec):
|
||||
key = key_of(dp, table)
|
||||
ods_keys = {r[key] for r in dp.sql(f"SELECT {key} FROM {dp.product.schema}.{table}")}
|
||||
topic = dp.topic(table, "subscribe-output")
|
||||
dp.eventually(lambda: ods_keys <= {k for k, v in dp.latest(topic).items() if v is not None}, timeout=60)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not ROUND_TRIP, reason="no round_trip in expectations.yaml")
|
||||
def test_record_round_trip(dp):
|
||||
table, record, update = ROUND_TRIP["table"], ROUND_TRIP["record"], ROUND_TRIP["update"]
|
||||
schema, key = dp.product.schema, key_of(dp, table)
|
||||
record_key = record[key]
|
||||
lake = f"{dp.product.trino_catalog}.{dp.product.lake_schema}.{table}"
|
||||
outbound = dp.topic(table, "subscribe-output")
|
||||
columns = ", ".join(record)
|
||||
values = ", ".join(dp.sql_literal(v) for v in record.values())
|
||||
where = f"{key} = '{record_key}'"
|
||||
|
||||
assert not dp.sql(f"SELECT 1 FROM {schema}.{table} WHERE {where}"), f"{record_key} already exists; clean up first"
|
||||
refused = dp.sql_error(f"INSERT INTO {schema}.{table} ({columns}) VALUES ({values})")
|
||||
assert refused is None, f"the ODS would refuse the round-trip record, so it is not published: {refused}"
|
||||
|
||||
try:
|
||||
# Publish input -> Flink -> ODS
|
||||
dp.publish(dp.topic(table, "publish-input"), [record])
|
||||
dp.eventually(lambda: contains(record, (dp.sql(f"SELECT * FROM {schema}.{table} WHERE {where}") or [None])[0]))
|
||||
|
||||
# ODS -> Flink CDC -> subscribe output, and ODS -> pg_duckpipe -> lake
|
||||
dp.eventually(lambda: contains(record, dp.latest(outbound).get(record_key)))
|
||||
dp.eventually(lambda: dp.trino(f"SELECT count(*) AS n FROM {lake} WHERE CAST({key} AS varchar) = '{record_key}'") == [{"n": 1}])
|
||||
|
||||
# CRUD API update -> subscribe output and lake
|
||||
assignments = ", ".join(f'{camel(c)}: "{v}"' for c, v in update.items())
|
||||
data = dp.graphql(
|
||||
f"mutation {{ update{pascal(table)}Collection(set: {{{assignments}}}, "
|
||||
f'filter: {{{camel(key)}: {{eq: "{record_key}"}}}}) {{ affectedCount }} }}'
|
||||
)
|
||||
assert data[f"update{pascal(table)}Collection"]["affectedCount"] == 1
|
||||
dp.eventually(lambda: contains(update, dp.latest(outbound).get(record_key)))
|
||||
column, value = next(iter(update.items()))
|
||||
dp.eventually(lambda: dp.trino(f"SELECT CAST({column} AS varchar) AS v FROM {lake} WHERE CAST({key} AS varchar) = '{record_key}'") == [{"v": str(value)}])
|
||||
|
||||
# CRUD API delete -> tombstone on subscribe output, row gone from the lake
|
||||
data = dp.graphql(
|
||||
f"mutation {{ deleteFrom{pascal(table)}Collection("
|
||||
f'filter: {{{camel(key)}: {{eq: "{record_key}"}}}}, atMost: 1) {{ affectedCount }} }}'
|
||||
)
|
||||
assert data[f"deleteFrom{pascal(table)}Collection"]["affectedCount"] == 1
|
||||
dp.eventually(lambda: (lambda state: record_key in state and state[record_key] is None)(dp.latest(outbound)))
|
||||
dp.eventually(lambda: dp.trino(f"SELECT count(*) AS n FROM {lake} WHERE CAST({key} AS varchar) = '{record_key}'") == [{"n": 0}])
|
||||
finally:
|
||||
dp.execute(f"DELETE FROM {schema}.{table} WHERE {where}")
|
||||
Reference in new issue
Block a user