Database Query Component

Database Query Component



Database Query

Run an SQL Query on an accessible database and copy the result to a table, via storage.

This component is for data-staging - getting data into a table in order to perform further processing and transformations on it. The target table should be considered temporary, as it will either be truncated or recreated each time the components runs.

Incremental loads using this component can be built using its JDBC Incremental Load generator.



Redshift Properties

Property Setting Description
Name String Input the descriptive name for the component.
Basic/Advanced Mode Select Basic: This mode will build a Query using settings from the Data Source, Data Selection, and Data Source Filter parameters. In most cases, this will be sufficient.
Advanced: This mode will require users to write an SQL-like query to call data from their chosen database.
Database Type Select IBM DB2: see their website for more details.
IBM DB2 for i: see their website for more details.
Microsoft SQL Server: see their website for more details.
MySQL: see their website for more details.
Netezza: see their website for more details.
Oracle: see their website for more details.
PostgreSQL: see their website for more details.
SAP Hana: see their website for more details.
SQL Server (Microsoft Driver): see their website for more details.
Sybase ASE: see their website for more details.
Teradata: see their website for more details.
Note: For some databases, you must first provide a JDBC driver as not all drivers can be distributed with Matillion ETL. See this article for instructions on managing drivers.
Connection URL String This is the database JDBC URL used to connect. The format of the URL varies considerably; however, a default template URL is offered once users have chosen a database type. Replace any special tags in the URL template with real values.
Although many parameters and options can be added to the end of the URL, it is generally easier to add them to the Connection Options, documented below.
Username String Input your database connection username.
Password String Input your database connection password. The password is masked so it can be set, but not read. Users have the option to store their password inside the component, but Matillion highly recommends using the Password Manager feature.
Connection Options Parameter A JDBC parameter supported by the Database driver. The available parameters are determined automatically from the driver, and may change from version to version. They are usually not required, since sensible defaults are assumed.
Value A value for the given parameter. Parameters and their allowed values are somewhat database-specific. The links below may help, or if you upload your own JDBC Driver, consult the documentation that was provided with it.
Data Source Select Select a data source.
Data Selection Select Select one or more columns from the chosen data source to return from the query.
Data Source Filter Input Column The available input columns vary depending upon the Data Source.
Qualifier Is: Compares the column to the value using the comparator.
Not: Reverses the effect of the comparison, so "Equals" becomes "Not equals", "Less than" becomes "Greater than or equal to", etc.
Comparator Choose a method of comparing the column to the value. Possible comparators include: "Equal To", "Greater than", "Less than", "Greater than or equal to", "Less than or equal to", "Like", "Null".
"Equal to" can match exact strings and numeric values, while other comparators such as "Greater than" will work only with numerics. The "Like" operator allows the wildcard character (%) to be used at the start and end of a string value to match a column. The "Null" operator matches only null values, ignoring whatever the value is set to.
Not all data sources support all comparators, thus it is likely that only a subset of the above comparators will be available to choose from.
Value The value to be compared.
Primary Keys Select Select one or more columns to be designated as the table's primary key.
SQL Query String This is an SQL query, written in the dialect of the target database. It can be as simple as
select * from tablename
It should be a simple select query. (Property only available in Advanced Mode.)
Type Select Choose between using a standard table or an external table.
Standard: The data will be staged on an S3 bucket before being loaded into a table.
External: The data will be put into an S3 Bucket and referenced by an external table.
Location S3 Bucket Select an S3 bucket path that will be used to store the data. Once the data is on an S3 bucket, it can be referenced by an external table.
This property is only available when the Type property is set to "External".
Schema Select Select the table schema. The special value, [Environment Default] will use the schema defined in the environment. For more information on using multiple schemas, see this article.
Target Table String Provide a new table name.
Warning: This table will be recreated on each run of the job, and drop any existing table of the same name.
S3 Staging Area Text The name of an S3 bucket for temporary storage. Ensure your access credentials have S3 access and permission to write to the bucket. See this document for details on setting up access. The temporary objects created in this bucket will be removed again after the load completes, they are not kept.
Concurrency Integer The number of S3 files to create. This helps when loading into Amazon Redshift as they are loaded in parallel. In addition, Matillion ETL for Redshift will be able to upload parts of these files concurrently.
Note: The maximum concurrency is 8 times the number of processors on your cloud instance. For example: An instance with 2 processors has a maximum concurrency of 16.
Distribution Style Select All: Copy rows to all nodes in the Redshift cluster.
Auto: (Default) Allow Redshift to manage your distribution style.
Even: Distributes rows around the Redshift cluster evenly.
Key: Distribute rows around the Redshift cluster according to the value of a key column.
Table distribution is critical to good performance. See the Amazon Redshift documentation for more information.
Distribution Key Select This is only displayed if the Table Distribution Style is set to Key. It is the column used to determine which cluster node the row is stored on.
Sort Key Select This is optional, and specifies the columns from the input that should be set as the table's sort-key.
Sort-keys are critical to good performance - see the Amazon Redshift documentation for more information.
Sort Key Options Select Decide whether the sort key is of a compound or interleaved variety - see the Amazon Redshift documentation for more information.
Encryption Select Decide on how the files are encrypted inside the S3 Bucket.
None: No encryption.
SSE KMS: Encrypt the data according to a key stored on KMS.
SSE S3: Encrypt the data according to a key stored on an S3 bucket.
KMS Key ID Select The ID of the KMS encryption key you have chosen to use in the 'Encryption' property.
Load Options Multiple Select Columns Comp Update: Apply automatic compression to the target table. Default is On.
Stat Update: Automatically update statistics when filling a table. Default is On. In this case, it is updating the statistics of the target table.
Clean S3 Objects: Automatically remove UUID-based objects on the S3 bucket. Default is On. Effectively, users decide here whether to keep the staged data in the S3 bucket or not.
String Null is Null: Converts any strings equal to "null" into a null value. This is case sensitive and only works with entirely lower-case strings. Default is On.
Recreate Target Table: Choose whether the component recreates its target table before the data load. If Off, the component will use an existing table or create one if it does not exist. Default is On.
File Prefix: Give staged file names a prefix of your choice. When this Load Option is selected, users should set their preferred prefix in the text field.
Use Grid Variable: Check this checkbox to use a grid variable. This box is unchecked by default.

Snowflake Properties

Property Setting Description
Name String Input the descriptive name for the component.
Basic/Advanced Mode Select Basic: This mode will build a Query using settings from the Data Source, Data Selection, and Data Source Filter parameters. In most cases, this will be sufficient.
Advanced: This mode will require users to write an SQL-like query to call data from their chosen database.
Database Type Select IBM DB2: see their website for more details.
IBM DB2 for i: see their website for more details.
Microsoft SQL Server: see their website for more details.
MySQL: see their website for more details.
Netezza: see their website for more details.
Oracle: see their website for more details.
PostgreSQL: see their website for more details.
SAP Hana: see their website for more details.
SQL Server (Microsoft Driver): see their website for more details.
Sybase ASE: see their website for more details.
Teradata: see their website for more details.
Note: For some databases, you must first provide a JDBC driver as not all drivers can be distributed with Matillion ETL. See this article for instructions on managing drivers.
Connection URL String This is the database JDBC URL used to connect. The format of the URL varies considerably; however, a default template URL is offered once users have chosen a database type. Replace any special tags in the URL template with real values.
Although many parameters and options can be added to the end of the URL, it is generally easier to add them to the Connection Options, documented below.
Username String Input your database connection username.
Password String Input your database connection password. The password is masked so it can be set, but not read. Users have the option to store their password inside the component, but Matillion highly recommends using the Password Manager feature.
Connection Options Parameter A JDBC parameter supported by the Database driver. The available parameters are determined automatically from the driver, and may change from version to version. They are usually not required, since sensible defaults are assumed.
Value A value for the given parameter. Parameters and their allowed values are somewhat database-specific. The links below may help, or if you upload your own JDBC Driver, consult the documentation that was provided with it.
Data Source Select Select a data source.
Data Selection Select Select one or more columns from the chosen data source to return from the query.
Data Source Filter Input Column The available input columns vary depending upon the Data Source.
Qualifier Is: Compares the column to the value using the comparator.
Not: Reverses the effect of the comparison, so "Equals" becomes "Not equals", "Less than" becomes "Greater than or equal to", etc.
Comparator Choose a method of comparing the column to the value. Possible comparators include: "Equal To", "Greater than", "Less than", "Greater than or equal to", "Less than or equal to", "Like", "Null".
"Equal to" can match exact strings and numeric values, while other comparators such as "Greater than" will work only with numerics. The "Like" operator allows the wildcard character (%) to be used at the start and end of a string value to match a column. The "Null" operator matches only null values, ignoring whatever the value is set to.
Not all data sources support all comparators, thus it is likely that only a subset of the above comparators will be available to choose from.
Value The value to be compared.
SQL Query String This is an SQL query, written in the dialect of the target database. It can be as simple as
select * from tablename
It should be a simple select query. (Property only available in Advanced Mode.)
Warehouse Select Choose a Snowflake warehouse that will run the load.
Database Select Choose a database to create the new table in.
Schema Select Select the table schema. The special value, [Environment Default] will use the schema defined in the environment. For more information on using multiple schemas, see this article.
Target Table String Provide a new table name.
Warning: This table will be recreated on each run of the job, and drop any existing table of the same name.
Storage Account Select (Azure Only) Select a Storage Account with your desired Blob Container to be used for staging the data.
Blob Container Select (Azure Only) Select a Blob Container to be used for staging the data.
Staging Select Select a staging setting.
Snowflake Managed: Allow Matillion ETL to create and use a temporary internal stage on Snowflake for staging the data. This stage, along with the staged data, will cease to exist after loading is complete.
(AWS only) Existing Amazon S3 Location: Selecting this will offer the S3 Staging Area property, allowing users to specify a custom staging area on Amazon S3.
(Azure only) Existing Azure Blob Storage Location: Selecting this will offer the Storage Account and Blob Container properties, allowing users to specify a custom staging location on Azure.
(GCP only) Existing Google Cloud Storage Location: Selecting this will offer the GCS Staging Area property, allowing users to specify a custom staging area within Google Cloud Storage.
GCS Staging Area Select (GCP only) The URL and path of the target Google Storage bucket to be used for staging the queried data.
Integration Select Choose your Google Cloud Storage Integration. Integrations are required to permit Snowflake to read data from and write to a Google Cloud Storage bucket. Integrations must be set up in advance of selecting them in Matillion ETL. To learn more about setting up a storage integration, read our Storage Integration Setup Guide.
S3 Staging Area Text (AWS Only) The name of an S3 bucket for temporary storage. Ensure your access credentials have S3 access and permission to write to the bucket. See this document for details on setting up access. The temporary objects created in this bucket will be removed again after the load completes, they are not kept.
This property is available when using an Existing Amazon S3 Location for Staging.
Encryption Select (AWS Only) Decide on how the files are encrypted inside the S3 Bucket.This property is available when using an Existing Amazon S3 Location for Staging.
None: No encryption.
SSE KMS: Encrypt the data according to a key stored on KMS.
SSE S3: Encrypt the data according to a key stored on an S3 bucket.
KMS Key ID Select (AWS Only) The ID of the KMS encryption key you have chosen to use in the 'Encryption' property.
Primary Key Select Multiple Select one or more columns to be designated as Primary Keys for the table.
Load Options Multiple Select Clean Staged Files: Destroy staged files after loading data. Default is On.
String Null is Null: Converts any strings equal to "null" into a null value. This is case sensitive and only works with entirely lower-case strings. Default is Off.
Recreate Target Table: Choose whether the component recreates its target table before the data load. If Off, the component will use an existing table or create one if it does not exist. Default is On.
File Prefix: Give staged file names a prefix of your choice. The default setting is an empty field.
Trim String Columns: Remove leading and trailing characters from a string column. Default is On
Use Grid Variable: Check this checkbox to use a grid variable. This box is unchecked by default.

BigQuery Properties

Property Setting Description
Name String Input the descriptive name for the component.
Basic/Advanced Mode Select Basic: This mode will build a Query using settings from the Data Source, Data Selection, and Data Source Filter parameters. In most cases, this will be sufficient.
Advanced: This mode will require users to write an SQL-like query to call data from their chosen database.
Database Type Select IBM DB2: see their website for more details.
IBM DB2 for i: see their website for more details.
Microsoft SQL Server: see their website for more details.
MySQL: see their website for more details.
Netezza: see their website for more details.
Oracle: see their website for more details.
PostgreSQL: see their website for more details.
SAP Hana: see their website for more details.
SQL Server (Microsoft Driver): see their website for more details.
Sybase ASE: see their website for more details.
Teradata: see their website for more details.
Note: For some databases, you must first provide a JDBC driver as not all drivers can be distributed with Matillion ETL. See this article for instructions on managing drivers.
Connection URL String This is the database JDBC URL used to connect. The format of the URL varies considerably; however, a default template URL is offered once users have chosen a database type. Replace any special tags in the URL template with real values.
Although many parameters and options can be added to the end of the URL, it is generally easier to add them to the Connection Options, documented below.
Username String Input your database connection username.
Password String Input your database connection password. The password is masked so it can be set, but not read. Users have the option to store their password inside the component, but Matillion highly recommends using the Password Manager feature.
Connection Options Parameter A JDBC parameter supported by the Database driver. The available parameters are determined automatically from the driver, and may change from version to version. They are usually not required, since sensible defaults are assumed.
Value A value for the given parameter. Parameters and their allowed values are somewhat database-specific. The links below may help, or if you upload your own JDBC Driver, consult the documentation that was provided with it.
Data Source Select Select a data source.
Data Selection Select Select one or more columns from the chosen data source to return from the query.
Data Source Filter Input Column The available input columns vary depending upon the Data Source.
Qualifier Is: Compares the column to the value using the comparator.
Not: Reverses the effect of the comparison, so "Equals" becomes "Not equals", "Less than" becomes "Greater than or equal to", etc.
Comparator Choose a method of comparing the column to the value. Possible comparators include: "Equal To", "Greater than", "Less than", "Greater than or equal to", "Less than or equal to", "Like", "Null".
"Equal to" can match exact strings and numeric values, while other comparators such as "Greater than" will work only with numerics. The "Like" operator allows the wildcard character (%) to be used at the start and end of a string value to match a column. The "Null" operator matches only null values, ignoring whatever the value is set to.
Not all data sources support all comparators, thus it is likely that only a subset of the above comparators will be available to choose from.
Value The value to be compared.
SQL Query String This is an SQL query, written in the dialect of the target database. It can be as simple as
select * from tablename
It should be a simple select query. (Property only available in Advanced Mode.)
Target Table String Provide a new table name.
Warning: This table will be recreated on each run of the job, and drop any existing table of the same name.
Project Select Select the target BigQuery project to load data into.
Dataset Select Select the target BigQuery dataset to load data into.
Cloud Storage Staging Area Text The URL and path of the target Google Storage bucket to be used for staging the queried data.
Load Options Multiple Select Clean Cloud Storage Files: Destroy staged files on Cloud Storage after loading data. Default is On.
Cloud Storage File Prefix: Give staged file names a prefix of your choice. The default setting is an empty field.
Recreate Target Table: Choose whether the component recreates its target table before the data load. If Off, the component will use an existing table or create one if it does not exist. Default is On.
Use Grid Variable: Check this checkbox to use a grid variable. This box is unchecked by default.

Variable Exports

This component makes the following values available to export into variables:

Source Description
Time Taken To Stage The amount of time (in seconds) taken to fetch the data from the data source and upload it to storage.
Time Taken To Load The amount of time (in seconds) taken to execute the COPY statement to load the data into the target table from storage.

Strategy

Connect to the target database and issue the query. Stream the results into objects on S3. Then create or truncate the target table and issue a COPY command to load the S3 objects into the table. Finally, clean up the temporary S3 objects.


Example

In this example we connect to a source database that contains a table of records that indicate an email sent via SES had been rejected (bounced). The Database Query component is used to load data from the database into a table.


In the Database Query component properties, we supply the URL to connect to our database and relevant credentials where they are needed. Data is selected for loading using an SQL Query. In this case, we take all data using a "select * ..." query.

When running, the results of the query are copied to rds_ses_bounce which is reloaded each time the component runs. To confirm that our data is in the table (and to perform Transformations) we can use the Table Input component in a Transformation job. Using the Sample tab, we can take a quick look at the data to confirm the load was successful.