Package: tap-redshift
Singertap that extracts data from aRedshiftdatabase and produces JSON-formatted data following the Singer spec.Usagetap-redshift assumes you have a connection to Redshift and requires Python 3.6+.Step 1: Create a configuration fileWhen you install tap-redshift, you need to create aconfig.jsonfile for the database connection.The json file requires the following attributes;hostportdbnameuserpasswordstart_date(Notation: yyyy-mm-ddThh:mm:ssZ)And an optional attribute;schemaExample:{"host":"REDSHIFT_HOST","port":"REDSHIFT_PORT","dbname":"REDSHIFT_DBNAME","user":"REDSHIFT_USER","password":"REDSHIFT_PASSWORD","start_date":"REDSHIFT_START_DATE","schema":"REDSHIFT_SCHEMA"}Step 2: Discover what can be extracted from RedshiftThe tap can be invoked in discovery mode to get the available tables and columns in the database.
It points to the config file created to connect to redshift:$tap-redshift--configconfig.json-dA full catalog tap is written to stdout, with a JSON-schema description of each table. A source
table directly corresponds to a Singer stream.Redirect output from the tap’s discovery mode to a file so that it can be modified when the tap is
to be invoked in sync mode.$tap-redshift-cconfig.json-d>catalog.jsonThis runs the tap in discovery mode and copies the output into acatalog.jsonfile.A catalog contains a list of stream objects, one for each table available in your Redshift schema.Example:{"streams":[{"tap_stream_id":"sample-dbname.public.sample-name","stream":"sample-stream","database_name":"sample-dbname","table_name":"public.sample-name""schema":{"properties":{"id":{"minimum":-2147483648,"inclusion":"automatic","maximum":2147483647,"type":["null","integer"]},"name":{"maxLength":255,"inclusion":"available","type":["null","string"]},"updated_at":{"inclusion":"available","type":["string"],"format":"date-time"},},"type":"object"},"metadata":[{"metadata":{"selected-by-default":false,"selected":true,"is-view":false,"table-key-properties":["id"],"schema-name":"sample-stream","valid-replication-keys":["updated_at"]},"breadcrumb":[],},{"metadata":{"selected-by-default":true,"sql-datatype":"int2","inclusion":"automatic"},"breadcrumb":["properties","id"]},{"metadata":{"selected-by-default":true,"sql-datatype":"varchar","inclusion":"available"},"breadcrumb":["properties","name"]},{"metadata":{"selected-by-default":true,"sql-datatype":"datetime","inclusion":"available",},"breadcrumb":["properties","updated_at"]}]}]}Step 3: Select the tables you want to syncIn sync mode,tap-redshiftrequires a catalog file to be supplied, where the user must
have selected which streams (tables) should be transferred. Streams are not selected by default.For each stream in the catalog, find themetadatasection. That is the section you will modify
to select the stream and, optionally, individual properties too.The stream itself is represented by an empty breadcrumb.Example:"metadata":[{"breadcrumb":[],"metadata":{"selected-by-default":false,...}}]You can select it by adding"selected": trueto its metadata.Example:"metadata":[{"breadcrumb":[],"metadata":{"selected":true,"selected-by-default":false,...}}]The tap can then be invoked in sync mode with the properties catalog argument:Example (paired withtarget-datadotworld)tap-redshift-cconfig.json--catalogcatalog.json|target-datadotworld-cconfig-dw.jsonStep 4: Sync your dataThere are two ways to replicate a given table. FULL_TABLE and INCREMENTAL.
FULL_TABLE replication is used by default.Full TableFull-table replication extracts all data from the source table each time the tap is invoked without
a state file.IncrementalIncremental replication works in conjunction with a state file to only extract new records each
time the tap is invoked i.e continue from the last synced data.To use incremental replication, we need to add thereplication_methodandreplication_keyto the streams (tables) metadata in thecatalog.jsonfile.Example:"metadata":[{"breadcrumb":[],"metadata":{"selected":true,"selected-by-default":false,"replication-method":"INCREMENTAL","replication-key":"updated_at",...}}]We can then invoke the tap again in sync mode. This time the output will haveSTATEmessages
that contains areplication_key_valueandbookmarkfor data that were extracted.Redirect the output to astate.jsonfile. Normally, the target will echo the last STATE after
it has finished processing data.Run the code below to pass the state into astate.jsonfile.Example:tap-redshift-cconfig.json--catalogcatalog.json|\target-datadotworld-cconfig-dw.json>state.jsonThestate.jsonfile should look like;{"currently_syncing":null,"bookmarks":{"sample-dbname.public.sample-name":{"replication_key":"updated_at","version":1516304171710,"replication_key_value":"2013-10-29T09:38:41.341Z"}}}For subsequent runs, you can then invoke the incremental replication passing the latest state in order to limit data only to what has been modified since the last execution.tail-1state.json>latest-state.json;\tap-redshift\-cconfig-redshift.json\--catalogcatalog.json\-slatest-state.json|\target-datadotworld-cconfig-dw.json>state.jsonAll steps in one MakefileFor your convenience, all the steps mentioned above are captured in theMakefilebelow.
This example usestarget-datadotworldbut can be modified to use any other Singer target.# Requires python 3.6install:pip3installtap-redshift;\pip3installtarget-datadotworld# Catalog discoverydiscover:tap-redshift\-cconfig-redshift.json-d>catalog.json# Full syncfullsync:tap-redshift\-cconfig-redshift.json\--catalogcatalog.json|\target-datadotworld-cconfig-dw.json>state.json# Incremental syncsync:tail-1state.json>latest-state.json;\tap-redshift\-cconfig-redshift.json\--catalogcatalog.json\-slatest-state.json|\target-datadotworld-cconfig-dw.json>state.json