Package: pipelinewise-target-redshift
pipelinewise-target-redshiftSingertarget that loads data into Amazon Redshift following theSinger spec.This is aPipelineWisecompatible target connector.How to use itThe recommended method of running this target is to use it fromPipelineWise. When running it from PipelineWise you don't need to configure this tap with JSON files and most of things are automated. Please check the related documentation atTarget RedshiftIf you want to run thisSinger Targetindependently please read further.InstallFirst, make sure Python 3 is installed on your system or follow these
installation instructions forMacorUbuntu.It's recommended to use a virtualenv:python3-mvenvvenv.venv/bin/activatepipinstall--upgradepippipinstallpipelinewise-target-redshiftorpython3-mvenvvenv.venv/bin/activatepipinstall--upgradepippipinstall.To runLike any other target that's following the singer specificiation:some-singer-tap | target-redshift --config [config.json]It's reading incoming messages from STDIN and using the properites inconfig.jsonto upload data into Amazon Redshift.Note: To avoid version conflicts runtapandtargetsin separate virtual environments.Configuration settingsRunning the the target connector requires aconfig.jsonfile. Example with the minimal settings:{"host":"xxxxxx.redshift.amazonaws.com","port":5439,"user":"my_user","password":"password","dbname":"database_name","aws_access_key_id":"secret","aws_secret_access_key":"secret","s3_bucket":"bucket_name","default_target_schema":"my_target_schema"}Full list of options inconfig.json:PropertyTypeRequired?DescriptionhostStringYesRedshift HostportIntegerYesRedshift PortuserStringYesRedshift UserpasswordStringYesRedshift PassworddbnameStringYesRedshift Database nameaws_profileStringNoAWS profile name for profile based authentication. If not provided,AWS_PROFILEenvironment variable will be used.aws_access_key_idStringNoS3 Access Key Id. Used for S3 and Redshfit copy operations. If not provided,AWS_ACCESS_KEY_IDenvironment variable will be used.aws_secret_access_keyStringNoS3 Secret Access Key. Used for S3 and Redshfit copy operations. If not provided,AWS_SECRET_ACCESS_KEYenvironment variable will be used.aws_session_tokenStringNoS3 AWS STS token for temporary credentials. If not provided,AWS_SESSION_TOKENenvironment variable will be used.aws_redshift_copy_role_arnStringNoAWS Role ARN to be used for the Redshift COPY operation. Used instead of the given AWS keys for the COPY operation if provided - the keys are still used for other S3 operationss3_aclStringNoS3 Object ACLs3_bucketStringYesS3 Bucket names3_key_prefixString(Default: None) A static prefix before the generated S3 key names. Using prefixes you can upload files into specific directories in the S3 bucket.copy_optionsString(Default:EMPTYASNULL BLANKSASNULL TRIMBLANKS TRUNCATECOLUMNS TIMEFORMAT 'auto' COMPUPDATE OFF STATUPDATE OFF). Parameters to use in the COPY command when loading data to Redshift. Some basic file formatting parameters are fixed values and not recommended overriding them by custom values. They are like:CSV GZIP DELIMITER ',' REMOVEQUOTES ESCAPEbatch_size_rowsInteger(Default: 100000) Maximum number of rows in each batch. At the end of each batch, the rows in the batch are loaded into Redshift.flush_all_streamsBoolean(Default: False) Flush and load every stream into Redshift when one batch is full. Warning: This may trigger the COPY command to use files with low number of records, and may cause performance problems.parallelismInteger(Default: 0) The number of threads used to flush tables. 0 will create a thread for each stream, up to parallelism_max. -1 will create a thread for each CPU core. Any other positive number will create that number of threads, up to parallelism_max.max_parallelismInteger(Default: 16) Max number of parallel threads to use when flushing tables.default_target_schemaStringName of the schema where the tables will be created. Ifschema_mappingis not defined then every stream sent by the tap is loaded into this schema.default_target_schema_select_permissionsStringGrant USAGE privilege on newly created schemas and grant SELECT privilege on newly created tables to a specific list of users or groups. Example:{"users": ["user_1","user_2"], "groups": ["group_1", "group_2"]}Ifschema_mappingis not defined then every stream sent by the tap is granted accordingly.schema_mappingObjectUseful if you want to load multiple streams from one tap to multiple Redshift schemas.If the tap sends thestream_idin<schema_name>-<table_name>format then this option overwrites thedefault_target_schemavalue. Note, that usingschema_mappingyou can overwrite thedefault_target_schema_select_permissionsvalue to grant SELECT permissions to different groups per schemas or optionally you can create indices automatically for the replicated tables.Note: This is an experimental feature and recommended to use via PipelineWise YAML files that will generate the object mapping in the right JSON format. For further info check a [PipelineWise YAML Example]disable_table_cacheBoolean(Default: False) By default the connector caches the available table structures in Redshift at startup. In this way it doesn't need to run additional queries when ingesting data to check if altering the target tables is required. Withdisable_table_cacheoption you can turn off this caching. You will always see the most recent table structures but will cause an extra query runtime.add_metadata_columnsBoolean(Default: False) Metadata columns add extra row level information about data ingestions, (i.e. when was the row read in source, when was inserted or deleted in redshift etc.) Metadata columns are creating automatically by adding extra columns to the tables with a column prefix_SDC_. The metadata columns are documented athttps://transferwise.github.io/pipelinewise/data_structure/sdc-columns.html. Enabling metadata columns will flag the deleted rows by setting the_SDC_DELETED_ATmetadata column. Without theadd_metadata_columnsoption the deleted rows from singer taps will not be recongisable in Redshift.hard_deleteBoolean(Default: False) Whenhard_deleteoption is true then DELETE SQL commands will be performed in Redshift to delete rows in tables. It's achieved by continuously checking the_SDC_DELETED_ATmetadata column sent by the singer tap. Due to deleting rows requires metadata columns,hard_deleteoption automatically enables theadd_metadata_columnsoption as well.data_flattening_max_levelInteger(Default: 0) Object type RECORD items from taps can be loaded into VARIANT columns as JSON (default) or we can flatten the schema by creating columns automatically.When value is 0 (default) then flattening functionality is turned off.primary_key_requiredBoolean(Default: True) Log based and Incremental replications on tables with no Primary Key cause duplicates when merging UPDATE events. When set to true, stop loading data if no Primary Key is defined.validate_recordsBoolean(Default: False) Validate every single record message to the corresponding JSON schema. This option is disabled by default and invalid RECORD messages will fail only at load time by Snowflake. Enabling this option will detect invalid records earlier but could cause performance degradation.skip_updatesBooleanNo(Default: False) Do not update existing records when Primary Key is defined. Useful to improve performance when records are immutable, e.g. eventscompressionStringNoThe compression method to use when writing files to S3 and running RedshiftCOPY. The currently supported methods aregziporbzip2. Defaults to none ("").slicesIntegerNoThe number of slices to split files into prior to running COPY on Redshift. This should be set to the number of Redshift slices. The number of slices per node depends on the node size of the cluster - runSELECT COUNT(DISTINCT slice) slices FROM stv_slicesto calculate this. Defaults to1.temp_dirString(Default: platform-dependent) Directory of temporary CSV files with RECORD messages.To run tests:Install python dependencies in a virtual env:python3-mvenvvenv.venv/bin/activatepipinstall--upgradepippipinstall.[test]To run unit tests:coveragerun-mpytest-vv--disable-pytest-warningstests/unit&&coveragereportTo run integration tests define environment variables first:exportTARGET_REDSHIFT_HOST=<redshift-host>exportTARGET_REDSHIFT_PORT=<redshift-port>exportTARGET_REDSHIFT_USER=<redshift-user>exportTARGET_REDSHIFT_PASSWORD=<redshift-password>exportTARGET_REDSHIFT_DBNAME=<redshift-database-name>exportTARGET_REDSHIFT_SCHEMA=<redshift-target-schema>exportTARGET_REDSHIFT_AWS_ACCESS_KEY=<aws-access-key-id>exportTARGET_REDSHIFT_AWS_SECRET_ACCESS_KEY=<aws-access-secret-access-key>exportTARGET_REDSHIFT_S3_ACL=<s3-target-acl>exportTARGET_REDSHIFT_S3_BUCKET=<s3-bucket>exportTARGET_REDSHIFT_S3_KEY_PREFIX=<s3-bucket-directory>coveragerun-mpytest-vv--disable-pytest-warningstests/integration&&coveragereportTo run pylint:Install python dependencies and run python linterpython3-mvenvvenv.venv/bin/activatepipinstall--upgradepippipinstall.[test]pipinstallpylintpylinttarget_redshift-dC,W,unexpected-keyword-arg,duplicate-codeLicenseApache License Version 2.0SeeLICENSEto see the full text.