albert_m
07/19/2022, 1:00 AMchristoph
07/19/2022, 1:39 AMvisch
07/19/2022, 2:13 AM.jsonl I go
meltano run tap-postgres target-apprise (I also have ~5 other targets I write to, active directory, azuread, apprise, sftp, school based api)
So in prod it looks more like something like
meltano run tap-toggl target-postgres dbt:run tap-postgres target-apprisevisch
07/19/2022, 2:14 AM"""Apprise target sink class, which handles writing streams."""
from singer_sdk.sinks import RecordSink
from typing import Optional
import apprise
class AppriseSink(RecordSink):
"""Apprise target sink class."""
def process_record(self, record: dict, context: dict) -> None:
"""Process the record."""
a = apprise.Apprise()
for uri in self.config["uris"]:
a.add(uri)
title: Optional[str] = record.get("title")
body: Optional[str] = record.get("body")
if title is None and body is None:
raise Exception("Both the title and body cannot be None")
a.notify(title=title, body=body)visch
07/19/2022, 2:15 AMchristoph
07/19/2022, 3:37 AMTrick is in the dbt:run step, how to you be sure you're only sending the data you need to?The way how I solve this so far is to manage a (potentially compound) primary key in my dbt model. And I actually just write a sha-256 hash of the primary key values into a dedicated column in dbt (e.g.
_id)
And then I use that column with the sha-256 hash as the primary key in the target, because the targets I deal with are all mostly datastores which have this concept of primary key exposed as a function.
For targets which are not datastores, this approach may of course not work so well, if the target can't easily be persuaded to learn about the concept of an exposed primary key.visch
07/19/2022, 4:25 PMchristoph
07/19/2022, 9:33 PMvisch
07/20/2022, 2:06 AMchristoph
07/20/2022, 3:38 AMtarget-postgres and the string fields in the dbt source table are all of type unlimited varchar ... 😉
Even though in the Postgres case, using a length limited varchar doesn't actually have any benefits ...
There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. Whilehttps://www.postgresql.org/docs/current/datatype-character.htmlhas performance advantages in some other database systems, there is no such advantage in PostgreSQL; in factcharacter(_n_)is usually the slowest of the three because of its additional storage costs. In most situationscharacter(_n_)ortextshould be used instead.character varying