This SQL query integrates company data with engagement data from HubSpot. It counts different types of engagements (notes, tasks, calls, meetings, emails) for each company and joins this aggregated engagement data with the main company information. The result is a comprehensive view of each company with their details and engagement metrics.
IntegrationAggregationFeaturizationWITH companies AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__company
), engagements AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__engagements
), engagement_companies AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_company
), engagement_companies_joined AS (
SELECT
engagements.engagement_type,
engagement_companies.company_id
FROM engagements
INNER JOIN engagement_companies
USING (engagement_id)
), engagement_companies_agg AS (
SELECT
company_id,
COUNT(CASE WHEN engagement_type = 'NOTE' THEN company_id END) AS count_engagement_notes,
COUNT(CASE WHEN engagement_type = 'TASK' THEN company_id END) AS count_engagement_tasks,
COUNT(CASE WHEN engagement_type = 'CALL' THEN company_id END) AS count_engagement_calls,
COUNT(CASE WHEN engagement_type = 'MEETING' THEN company_id END) AS count_engagement_meetings,
COUNT(CASE WHEN engagement_type = 'EMAIL' THEN company_id END) AS count_engagement_emails,
COUNT(CASE WHEN engagement_type = 'INCOMING_EMAIL' THEN company_id END) AS count_engagement_incoming_emails,
COUNT(CASE WHEN engagement_type = 'FORWARDED_EMAIL' THEN company_id END) AS count_engagement_forwarded_emails
FROM engagement_companies_joined
GROUP BY
1
), joined AS (
SELECT
companies.*,
COALESCE(engagement_companies_agg.count_engagement_notes, 0) AS count_engagement_notes,
COALESCE(engagement_companies_agg.count_engagement_tasks, 0) AS count_engagement_tasks,
COALESCE(engagement_companies_agg.count_engagement_calls, 0) AS count_engagement_calls,
COALESCE(engagement_companies_agg.count_engagement_meetings, 0) AS count_engagement_meetings,
COALESCE(engagement_companies_agg.count_engagement_emails, 0) AS count_engagement_emails,
COALESCE(engagement_companies_agg.count_engagement_incoming_emails, 0) AS count_engagement_incoming_emails,
COALESCE(engagement_companies_agg.count_engagement_forwarded_emails, 0) AS count_engagement_forwarded_emails
FROM companies
LEFT JOIN engagement_companies_agg
USING (company_id)
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
company_id | bigint | The ID of the company. |
portal_id | None | The hub ID. |
is_company_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
count_engagement_notes | bigint | The total number of related note engagements. |
count_engagement_tasks | bigint | The total number of related task engagements. |
count_engagement_calls | bigint | The total number of related call engagements. |
count_engagement_meetings | bigint | The total number of related meeting engagements. |
count_engagement_emails | bigint | The total number of related email engagements. |
count_engagement_incoming_emails | bigint | The total number of related incoming email engagements. |
count_engagement_forwarded_emails | bigint | The total number of related forwarded email engagements. |
_fivetran_synced | timestamp without time zone | None |
company_name | text | None |
description | text | None |
created_date | timestamp without time zone | None |
industry | text | None |
street_address | text | None |
street_address_2 | text | None |
city | text | None |
state | text | None |
country | text | None |
company_annual_revenue | integer | None |
This SQL query processes company property history data to create a timeline of changes for each company and property. It establishes valid time ranges for each property value, generates a surrogate key for each record, and prepares the data for historical analysis.
FeaturizationOtherWITH history AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__company_property_history
), windows AS (
SELECT
company_id,
field_name,
change_source,
change_source_id,
change_timestamp AS valid_from,
new_value,
LEAD(change_timestamp) OVER (PARTITION BY company_id, field_name ORDER BY change_timestamp) AS valid_to
FROM history
), surrogate AS (
SELECT
windows.*,
MD5(
CAST(COALESCE(CAST(field_name AS TEXT), '_dbt_utils_surrogate_key_null_') || '-' || COALESCE(CAST(company_id AS TEXT), '_dbt_utils_surrogate_key_null_') || '-' || COALESCE(CAST(valid_from AS TEXT), '_dbt_utils_surrogate_key_null_') AS TEXT)
) AS id
FROM windows
)
SELECT
*
FROM surrogate
Name | Type | Comment |
---|---|---|
_fivetran_synced | None | Timestamp of when Fivetran synced a record. |
change_source | text | The source (reason) of the change. |
change_source_id | integer | The ID of the object that caused the change, if applicable. |
valid_from | timestamp without time zone | The timestamp the change was valid from. |
valid_to | timestamp without time zone | The timestamp the change was valid to. Null if still valid. |
company_id | bigint | The ID of the related company record. |
field_name | text | The name of the field being changed. |
new_value | text | The new value of the field. |
id | text | The ID of the change. |
This SQL query processes contact property history data from Hubspot. It creates a timeline of changes for each contact's properties, including the source of the change and the time period for which each value was valid. The query also generates a unique identifier for each record using a hash function.
FeaturizationOtherWITH history AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__contact_property_history
), windows AS (
SELECT
contact_id,
field_name,
change_source,
change_source_id,
change_timestamp AS valid_from,
new_value,
LEAD(change_timestamp) OVER (PARTITION BY contact_id, field_name ORDER BY change_timestamp) AS valid_to
FROM history
), surrogate AS (
SELECT
windows.*,
MD5(
CAST(COALESCE(CAST(field_name AS TEXT), '_dbt_utils_surrogate_key_null_') || '-' || COALESCE(CAST(contact_id AS TEXT), '_dbt_utils_surrogate_key_null_') || '-' || COALESCE(CAST(valid_from AS TEXT), '_dbt_utils_surrogate_key_null_') AS TEXT)
) AS id
FROM windows
)
SELECT
*
FROM surrogate
Name | Type | Comment |
---|---|---|
_fivetran_synced | None | Timestamp of when Fivetran synced a record. |
change_source | text | The source (reason) of the change. |
change_source_id | text | The ID of the object that caused the change, if applicable. |
valid_from | timestamp without time zone | The timestamp the change was valid from. |
valid_to | timestamp without time zone | The timestamp the change was valid to. Null if still valid. |
contact_id | integer | The ID of the related contact record. |
field_name | text | The name of the field being changed. |
new_value | text | The new value of the field. |
id | text | The ID of the change. |
This SQL query integrates data from two tables: contact lists and email metrics. It performs a left join between these tables using the contact_list_id as the joining key. The query selects all columns from the contact_lists table, effectively combining contact list information with associated email metrics data, if available.
IntegrationWITH contact_lists AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__contact_list
), email_metrics AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__email_metrics__by_contact_list
), joined AS (
SELECT
contact_lists.*
FROM contact_lists
LEFT JOIN email_metrics
USING (contact_list_id)
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
contact_list_id | integer | The ID of the contact list. |
contact_list_name | text | The name of the contact list. |
is_contact_list_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
created_timestamp | timestamp without time zone | A timestamp of the time the list was created. |
is_deletable | boolean | If this is false, this is a system list and cannot be deleted. |
is_dynamic | boolean | Whether the contact list is dynamic. |
metadata_error | integer | Any errors that happened the last time the list was processed. |
metadata_last_processing_state_change_at | timestamp without time zone | A timestamp of the last time that the processing state changed. |
metadata_last_size_change_at | timestamp without time zone | A timestamp of the last time that the size of the list changed. |
metadata_processing | text | One of DONE, REFRESHING, INITIALIZING, or PROCESSING. DONE indicates the list has finished processing, any other value indicates that list membership is being evaluated. |
metadata_size | integer | The approximate number of contacts in the list. |
portal_id | integer | The hub ID. |
updated_timestamp | timestamp without time zone | A timestamp of the time that the list was last modified. |
total_bounces | numeric | The total number of bounce email events. |
total_clicks | numeric | The total number of click email events. |
total_deferrals | numeric | The total number of deferral email events. |
total_deliveries | numeric | The total number of delivery email events. |
total_drops | numeric | The total number of drop email events. |
total_forwards | numeric | The total number of forward email events. |
total_opens | numeric | The total number of open email events. |
total_prints | numeric | The total number of print email events. |
total_spam_reports | numeric | The total number of spam report email events. |
total_unsubscribes | numeric | The total number of unsubscribe email events. |
total_unique_bounces | bigint | The total number of unique email sends with a bounce email event. |
total_unique_clicks | bigint | The total number of unique email sends with a click email event. |
total_unique_deferrals | bigint | The total number of unique email sends with a deferral email event. |
total_unique_deliveries | bigint | The total number of unique email sends with a delivery email event. |
total_unique_drops | bigint | The total number of unique email sends with a drop email event. |
total_unique_forwards | bigint | The total number of unique email sends with a forward email event. |
total_unique_opens | bigint | The total number of unique email sends with a opens email event. |
total_unique_prints | bigint | The total number of unique email sends with a print email event. |
total_unique_spam_reports | bigint | The total number of unique email sends with a spam report email event. |
total_unique_unsubscribes | bigint | The total number of unique email sends with a unsubscribe email event. |
This SQL query integrates contact data from Hubspot with engagement metrics and email send information. It combines data from multiple tables, including contacts, engagements, and email sends. The query calculates various engagement counts (notes, tasks, calls, meetings, emails) for each contact and joins this information with the main contact data. It also checks if a contact's email address has been used in email sends.
IntegrationAggregationFeaturizationWITH __dbt__cte__int_hubspot__engagement_metrics__by_contact AS (
WITH engagements AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__engagements
), engagement_contacts AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_contact
), engagement_contacts_joined AS (
SELECT
engagements.engagement_type,
engagement_contacts.contact_id
FROM engagements
INNER JOIN engagement_contacts
USING (engagement_id)
), engagement_contacts_agg AS (
SELECT
contact_id,
COUNT(CASE WHEN engagement_type = 'NOTE' THEN contact_id END) AS count_engagement_notes,
COUNT(CASE WHEN engagement_type = 'TASK' THEN contact_id END) AS count_engagement_tasks,
COUNT(CASE WHEN engagement_type = 'CALL' THEN contact_id END) AS count_engagement_calls,
COUNT(CASE WHEN engagement_type = 'MEETING' THEN contact_id END) AS count_engagement_meetings,
COUNT(CASE WHEN engagement_type = 'EMAIL' THEN contact_id END) AS count_engagement_emails,
COUNT(CASE WHEN engagement_type = 'INCOMING_EMAIL' THEN contact_id END) AS count_engagement_incoming_emails,
COUNT(CASE WHEN engagement_type = 'FORWARDED_EMAIL' THEN contact_id END) AS count_engagement_forwarded_emails
FROM engagement_contacts_joined
GROUP BY
1
)
SELECT
*
FROM engagement_contacts_agg
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), email_sends AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__email_sends
), email_metrics AS (
SELECT
recipient_email_address
FROM email_sends
GROUP BY
1
), email_joined AS (
SELECT
contacts.*
FROM contacts
LEFT JOIN email_metrics
ON contacts.email = email_metrics.recipient_email_address
), engagements AS (
SELECT
*
FROM __dbt__cte__int_hubspot__engagement_metrics__by_contact
), engagements_joined AS (
SELECT
email_joined.*,
COALESCE(engagements.count_engagement_notes, 0) AS count_engagement_notes,
COALESCE(engagements.count_engagement_tasks, 0) AS count_engagement_tasks,
COALESCE(engagements.count_engagement_calls, 0) AS count_engagement_calls,
COALESCE(engagements.count_engagement_meetings, 0) AS count_engagement_meetings,
COALESCE(engagements.count_engagement_emails, 0) AS count_engagement_emails,
COALESCE(engagements.count_engagement_incoming_emails, 0) AS count_engagement_incoming_emails,
COALESCE(engagements.count_engagement_forwarded_emails, 0) AS count_engagement_forwarded_emails
FROM email_joined
LEFT JOIN engagements
USING (contact_id)
)
SELECT
*
FROM engagements_joined
Name | Type | Comment |
---|---|---|
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
contact_id | integer | The ID of the contact. |
contact_company | text | The name of the contact's company |
first_name | text | The contact's first name. |
last_name | text | The contact's last name. |
text | The email address of the contact. | |
created_date | timestamp without time zone | The date that the contact was created in your HubSpot account. |
job_title | integer | The contact's job title. |
company_annual_revenue | integer | The contact's annual company revenue. |
total_bounces | numeric | The total number of bounce email events. |
total_clicks | numeric | The total number of click email events. |
total_deferrals | numeric | The total number of deferral email events. |
total_deliveries | numeric | The total number of delivery email events. |
total_drops | numeric | The total number of drop email events. |
total_forwards | numeric | The total number of forward email events. |
total_opens | numeric | The total number of open email events. |
total_prints | numeric | The total number of print email events. |
total_spam_reports | numeric | The total number of spam report email events. |
total_unsubscribes | numeric | The total number of unsubscribe email events. |
total_unique_bounces | bigint | The total number of unique email sends with a bounce email event. |
total_unique_clicks | bigint | The total number of unique email sends with a click email event. |
total_unique_deferrals | bigint | The total number of unique email sends with a deferral email event. |
total_unique_deliveries | bigint | The total number of unique email sends with a delivery email event. |
total_unique_drops | bigint | The total number of unique email sends with a drop email event. |
total_unique_forwards | bigint | The total number of unique email sends with a forward email event. |
total_unique_opens | bigint | The total number of unique email sends with a opens email event. |
total_unique_prints | bigint | The total number of unique email sends with a print email event. |
total_unique_spam_reports | bigint | The total number of unique email sends with a spam report email event. |
total_unique_unsubscribes | bigint | The total number of unique email sends with a unsubscribe email event. |
count_engagement_notes | bigint | The total number of related note engagements. |
count_engagement_tasks | bigint | The total number of related task engagements. |
count_engagement_calls | bigint | The total number of related call engagements. |
count_engagement_meetings | bigint | The total number of related meeting engagements. |
count_engagement_emails | bigint | The total number of related email engagements. |
count_engagement_incoming_emails | bigint | The total number of related incoming email engagements. |
count_engagement_forwarded_emails | bigint | The total number of related forwarded email engagements. |
calculated_merged_vids | text | List of mappings representing contact IDs that have been merged into the contact at hand. Format: |
This SQL query processes deal property history data from Hubspot. It creates a comprehensive view of deal property changes over time by establishing valid time ranges for each property value. The query also generates a unique identifier for each record using a combination of field name, deal ID, and valid from date.
FeaturizationOtherWITH history AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_property_history
), windows AS (
SELECT
deal_id,
field_name,
change_source,
change_source_id,
change_timestamp AS valid_from,
new_value,
LEAD(change_timestamp) OVER (PARTITION BY deal_id, field_name ORDER BY change_timestamp) AS valid_to
FROM history
), surrogate AS (
SELECT
windows.*,
MD5(
CAST(COALESCE(CAST(field_name AS TEXT), '_dbt_utils_surrogate_key_null_') || '-' || COALESCE(CAST(deal_id AS TEXT), '_dbt_utils_surrogate_key_null_') || '-' || COALESCE(CAST(valid_from AS TEXT), '_dbt_utils_surrogate_key_null_') AS TEXT)
) AS id
FROM windows
)
SELECT
*
FROM surrogate
Name | Type | Comment |
---|---|---|
_fivetran_synced | None | Timestamp of when Fivetran synced a record. |
change_source | text | The source (reason) of the change. |
change_source_id | text | The ID of the object that caused the change, if applicable. |
valid_from | timestamp without time zone | The timestamp the change was valid from. |
valid_to | timestamp without time zone | The timestamp the change was valid to. Null if still valid. |
deal_id | bigint | The ID of the related deal record. |
field_name | text | The name of the field being changed. |
new_value | text | The new value of the field. |
id | text | The ID of the change. |
This SQL query integrates data from multiple Hubspot-related tables (deals, pipelines, pipeline stages, owners) to create a comprehensive view of deal stages. It combines information about deals, their associated pipelines, stages, and owners, while also adding some derived fields. The query creates a unique identifier for each deal stage, includes various status flags, and incorporates temporal information about stage transitions.
IntegrationFeaturizationCleaningWITH __dbt__cte__int_hubspot__deals_enhanced AS (
WITH deals AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal
), pipelines AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_pipeline
), pipeline_stages AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_pipeline_stage
), owners AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__owner
), deal_fields_joined AS (
SELECT
deals.*,
COALESCE(pipelines.is_deal_pipeline_deleted, FALSE) AS is_deal_pipeline_deleted,
pipelines.pipeline_label,
pipelines.is_active AS is_pipeline_active,
COALESCE(pipeline_stages.is_deal_pipeline_stage_deleted, FALSE) AS is_deal_pipeline_stage_deleted,
pipelines.deal_pipeline_created_at,
pipelines.deal_pipeline_updated_at,
pipeline_stages.pipeline_stage_label,
owners.email_address AS owner_email_address,
owners.full_name AS owner_full_name
FROM deals
LEFT JOIN pipelines
ON deals.deal_pipeline_id = pipelines.deal_pipeline_id
LEFT JOIN pipeline_stages
ON deals.deal_pipeline_stage_id = pipeline_stages.deal_pipeline_stage_id
LEFT JOIN owners
ON deals.owner_id = owners.owner_id
)
SELECT
*
FROM deal_fields_joined
), deals_enhanced AS (
SELECT
*
FROM __dbt__cte__int_hubspot__deals_enhanced
), deal_stage AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_stage
), pipeline_stage AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_pipeline_stage
), pipeline AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_pipeline
), final AS (
SELECT
deal_stage.deal_id || '-' || ROW_NUMBER() OVER (PARTITION BY deal_stage.deal_id ORDER BY deal_stage.date_entered ASC) AS deal_stage_id,
deals_enhanced.deal_id,
deals_enhanced.deal_name,
deal_stage._fivetran_start AS date_stage_entered,
deal_stage._fivetran_end AS date_stage_exited,
deal_stage._fivetran_active AS is_stage_active,
deal_stage.deal_stage_name AS pipeline_stage_id,
pipeline_stage.pipeline_stage_label,
pipeline_stage.deal_pipeline_id AS pipeline_id,
pipeline.pipeline_label,
deal_stage.source,
deal_stage.source_id,
pipeline_stage.is_active AS is_pipeline_stage_active,
pipeline.is_active AS is_pipeline_active,
pipeline_stage.is_closed_won AS is_pipeline_stage_closed_won,
pipeline_stage.display_order AS pipeline_stage_display_order,
pipeline.display_order AS pipeline_display_order,
pipeline_stage.probability AS pipeline_stage_probability,
COALESCE(pipeline.is_deal_pipeline_deleted, FALSE) AS is_deal_pipeline_deleted,
COALESCE(pipeline_stage.is_deal_pipeline_stage_deleted, FALSE) AS is_deal_pipeline_stage_deleted,
COALESCE(deals_enhanced.is_deal_deleted, FALSE) AS is_deal_deleted,
pipeline_stage.deal_pipeline_stage_created_at,
pipeline_stage.deal_pipeline_stage_updated_at
FROM deal_stage
LEFT JOIN pipeline_stage
ON deal_stage.deal_stage_name = pipeline_stage.deal_pipeline_stage_id
LEFT JOIN pipeline
ON pipeline_stage.deal_pipeline_id = pipeline.deal_pipeline_id
LEFT JOIN deals_enhanced
ON deal_stage.deal_id = deals_enhanced.deal_id
)
SELECT
*
FROM final
Name | Type | Comment |
---|---|---|
deal_stage_id | text | The unique deal stage identifier. |
is_deal_pipeline_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
is_deal_pipeline_stage_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
is_deal_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
pipeline_stage_id | text | The ID of the deal's pipeline stage. |
date_stage_entered | timestamp without time zone | The timestamp the deal stage was entered. |
date_stage_exited | timestamp without time zone | The Fivetran calculated exit time of the deal stage. |
is_stage_active | boolean | Boolean indicating whether the deal stage active. |
deal_id | bigint | The ID of the deal. |
merged_deal_ids | None | A list of deals that had previously been merged into this record. |
pipeline_id | text | The ID of the deal's pipeline. |
pipeline_label | text | The label of the deal's pipeline. |
is_pipeline_active | boolean | Boolean indicating if the pipeline is active. |
is_pipeline_stage_active | boolean | Boolean indicating if the pipeline stage is active. |
pipeline_stage_label | text | The label of the deal's pipeline stage. |
source | text | The relevant source of the deal stage. |
source_id | text | Reference to the source. |
is_pipeline_stage_closed_won | boolean | Whether the stage represents a Closed Won deal. |
pipeline_stage_display_order | integer | Used to determine the order in which the stages appear when viewed in HubSpot. |
pipeline_display_order | integer | Used to determine the order in which the pipelines appear when viewed in HubSpot. |
pipeline_stage_probability | double precision | The probability that the deal will close. Used for the deal forecast. |
deal_name | text | The name you have given this deal. |
deal_pipeline_stage_created_at | text | A timestamp representing when the deal_pipeline_stage was created. |
deal_pipeline_stage_updated_at | text | A timestamp representing when the deal_pipeline_stage was updated. |
This SQL query integrates data from multiple Hubspot-related tables to create a comprehensive view of deals. It combines deal information with related pipeline, stage, and owner details. The query also aggregates engagement data (notes, tasks, calls, meetings, emails) for each deal. The result is a detailed dataset that includes deal attributes, associated metadata, and engagement counts.
IntegrationAggregationFeaturizationWITH __dbt__cte__int_hubspot__deals_enhanced AS (
WITH deals AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal
), pipelines AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_pipeline
), pipeline_stages AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_pipeline_stage
), owners AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__owner
), deal_fields_joined AS (
SELECT
deals.*,
COALESCE(pipelines.is_deal_pipeline_deleted, FALSE) AS is_deal_pipeline_deleted,
pipelines.pipeline_label,
pipelines.is_active AS is_pipeline_active,
COALESCE(pipeline_stages.is_deal_pipeline_stage_deleted, FALSE) AS is_deal_pipeline_stage_deleted,
pipelines.deal_pipeline_created_at,
pipelines.deal_pipeline_updated_at,
pipeline_stages.pipeline_stage_label,
owners.email_address AS owner_email_address,
owners.full_name AS owner_full_name
FROM deals
LEFT JOIN pipelines
ON deals.deal_pipeline_id = pipelines.deal_pipeline_id
LEFT JOIN pipeline_stages
ON deals.deal_pipeline_stage_id = pipeline_stages.deal_pipeline_stage_id
LEFT JOIN owners
ON deals.owner_id = owners.owner_id
)
SELECT
*
FROM deal_fields_joined
), deals_enhanced AS (
SELECT
*
FROM __dbt__cte__int_hubspot__deals_enhanced
), engagements AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__engagements
), engagement_deals AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_deal
), engagement_deal_joined AS (
SELECT
engagements.engagement_type,
engagement_deals.deal_id
FROM engagements
INNER JOIN engagement_deals
ON CAST(engagements.engagement_id AS BIGINT) = CAST(engagement_deals.engagement_id AS BIGINT)
), engagement_deal_agg AS (
SELECT
deal_id,
COUNT(CASE WHEN engagement_type = 'NOTE' THEN deal_id END) AS count_engagement_notes,
COUNT(CASE WHEN engagement_type = 'TASK' THEN deal_id END) AS count_engagement_tasks,
COUNT(CASE WHEN engagement_type = 'CALL' THEN deal_id END) AS count_engagement_calls,
COUNT(CASE WHEN engagement_type = 'MEETING' THEN deal_id END) AS count_engagement_meetings,
COUNT(CASE WHEN engagement_type = 'EMAIL' THEN deal_id END) AS count_engagement_emails,
COUNT(CASE WHEN engagement_type = 'INCOMING_EMAIL' THEN deal_id END) AS count_engagement_incoming_emails,
COUNT(CASE WHEN engagement_type = 'FORWARDED_EMAIL' THEN deal_id END) AS count_engagement_forwarded_emails
FROM engagement_deal_joined
GROUP BY
1
), engagements_joined AS (
SELECT
deals_enhanced.*,
COALESCE(engagement_deal_agg.count_engagement_notes, 0) AS count_engagement_notes,
COALESCE(engagement_deal_agg.count_engagement_tasks, 0) AS count_engagement_tasks,
COALESCE(engagement_deal_agg.count_engagement_calls, 0) AS count_engagement_calls,
COALESCE(engagement_deal_agg.count_engagement_meetings, 0) AS count_engagement_meetings,
COALESCE(engagement_deal_agg.count_engagement_emails, 0) AS count_engagement_emails,
COALESCE(engagement_deal_agg.count_engagement_incoming_emails, 0) AS count_engagement_incoming_emails,
COALESCE(engagement_deal_agg.count_engagement_forwarded_emails, 0) AS count_engagement_forwarded_emails
FROM deals_enhanced
LEFT JOIN engagement_deal_agg
ON CAST(deals_enhanced.deal_id AS BIGINT) = CAST(engagement_deal_agg.deal_id AS BIGINT)
)
SELECT
*
FROM engagements_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
description | text | A brief description of the deal. |
amount | integer | The total value of the deal in the deal's currency. |
closed_date | timestamp without time zone | The day the deal is expected to close, or was closed. |
created_date | timestamp without time zone | The date the deal was created. This property is set automatically by HubSpot. |
deal_id | bigint | The ID of the deal |
deal_name | text | The name you have given this deal. |
merged_deal_ids | None | A list of deals that had previously been merged into this record. |
is_deal_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
is_deal_pipeline_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
is_deal_pipeline_stage_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
portal_id | integer | The hub ID. |
deal_pipeline_id | text | The ID of the deal's pipeline. |
deal_pipeline_stage_id | text | The ID of the deal's pipeline stage. |
owner_id | bigint | The ID of the deal's owner. |
count_engagement_notes | bigint | The total number of related note engagements. |
count_engagement_tasks | bigint | The total number of related task engagements. |
count_engagement_calls | bigint | The total number of related call engagements. |
count_engagement_meetings | bigint | The total number of related meeting engagements. |
count_engagement_emails | bigint | The total number of related email engagements. |
count_engagement_incoming_emails | bigint | The total number of related incoming email engagements. |
count_engagement_forwarded_emails | bigint | The total number of related forwarded email engagements. |
is_pipeline_active | boolean | Boolean indicating if the pipeline is active. |
pipeline_label | text | The label of the deal's pipeline. |
pipeline_stage_label | text | The label of the deal's pipeline stage. |
owner_email_address | text | The email address of the deal's owner. |
owner_full_name | text | The full name of the deal's owner. |
deal_pipeline_created_at | text | A timestamp representing when the deal_pipeline was created. |
deal_pipeline_updated_at | text | A timestamp representing when the deal_pipeline was updated. |
This SQL query joins data from two tables: 'stg_hubspot__email_campaign' and 'hubspot__email_sends'. It first creates CTEs for each table, then groups the email sends data by email_campaign_id. Finally, it performs a left join between the campaigns data and the grouped email metrics data, returning all columns from the campaigns table along with the matching email campaign IDs from the email metrics.
IntegrationAggregationWITH campaigns AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_campaign
), email_sends AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__email_sends
), email_metrics AS (
SELECT
email_campaign_id
FROM email_sends
GROUP BY
1
), joined AS (
SELECT
campaigns.*
FROM campaigns
LEFT JOIN email_metrics
ON campaigns.email_campaign_id = email_metrics.email_campaign_id
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
app_id | integer | The app ID. |
app_name | text | The app name. |
content_id | bigint | The ID of the content. |
email_campaign_id | bigint | The ID of the email campaign. |
email_campaign_name | text | The name of the email campaign. |
email_campaign_sub_type | integer | The email campaign sub-type. |
email_campaign_subject | text | The subject of the email campaign. |
email_campaign_type | text | The email campaign type. |
num_included | integer | The number of messages included as part of the email campaign. |
num_queued | integer | The number of messages queued as part of the email campaign. |
total_bounces | numeric | The total number of bounce email events. |
total_clicks | numeric | The total number of click email events. |
total_deferrals | numeric | The total number of deferral email events. |
total_deliveries | numeric | The total number of delivery email events. |
total_drops | numeric | The total number of drop email events. |
total_forwards | numeric | The total number of forward email events. |
total_opens | numeric | The total number of open email events. |
total_prints | numeric | The total number of print email events. |
total_spam_reports | numeric | The total number of spam report email events. |
total_unsubscribes | numeric | The total number of unsubscribe email events. |
total_unique_bounces | bigint | The total number of unique email sends with a bounce email event. |
total_unique_clicks | bigint | The total number of unique email sends with a click email event. |
total_unique_deferrals | bigint | The total number of unique email sends with a deferral email event. |
total_unique_deliveries | bigint | The total number of unique email sends with a delivery email event. |
total_unique_drops | bigint | The total number of unique email sends with a drop email event. |
total_unique_forwards | bigint | The total number of unique email sends with a forward email event. |
total_unique_opens | bigint | The total number of unique email sends with a opens email event. |
total_unique_prints | bigint | The total number of unique email sends with a print email event. |
total_unique_spam_reports | bigint | The total number of unique email sends with a spam report email event. |
total_unique_unsubscribes | bigint | The total number of unique email sends with a unsubscribe email event. |
This SQL query integrates data from multiple tables related to Hubspot email events, specifically focusing on email bounce events. It joins the base email bounce event data with general email event data and contact information. The query enriches the bounce event data with additional details such as creation timestamp, campaign ID, recipient email, send timestamp, and contact information. It also includes a flag to indicate if the contact has been deleted.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_bounce
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
bounce_category | text | The best-guess of the type of bounce encountered. If an appropriate category couldn't be determined, this property is omitted. See below for the possible values. Note that this is a derived value, and may be modified at any time to improve the accuracy of classification. |
event_id | text | The ID of the event. |
returned_response | text | The full response from the recipient's email server. |
returned_status | integer | The status code returned from the recipient's email server. |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query integrates information from multiple tables related to Hubspot email event clicks. It starts with the base table of email event clicks, then joins it with the email events table to get additional event details. Finally, it joins with the contacts table to add contact information. The query also includes some basic data cleaning by coalescing the 'is_contact_deleted' field with a default value of FALSE.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_click
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
browser | text | A JSON object representing the browser which serviced the event. Its comprised of the properties: 'name', 'family', 'producer', 'producer_url', 'type', 'url', 'version'. |
click_url | text | The URL within the message that the recipient clicked. |
event_id | text | The ID of the event. |
geo_location | text | A JSON object representing the location where the event occurred. It's comprised of the properties: 'city', 'state', 'country'. |
ip_address | integer | The contact's IP address when the event occurred. |
referer_url | integer | The URL of the webpage that linked to the URL clicked. Whether this is provided, and what its value is, is determined by the recipient's email client. |
user_agent | text | The user agent responsible for the event, e.g. “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36” |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query integrates data from multiple tables related to Hubspot email events. It starts with the email_event_deferred table and joins it with the email_event table to add more event details. Then, it joins the result with the contact_merge_adjust table to include contact information. The query also adds a column to indicate if a contact is deleted. The final result includes all columns from these joined tables, providing a comprehensive view of deferred email events with associated contact information.
IntegrationFeaturizationWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_deferred
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
attempt_number | integer | The delivery attempt number. |
event_id | text | The ID of the event. |
returned_response | integer | The full response from the recipient's email server. |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query integrates data from three different sources: email event delivered, general email events, and contacts. It joins these tables to create a comprehensive view of email delivery events, including recipient information and contact details. The query also includes a coalesce function to handle potentially null values for the 'is_contact_deleted' field.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_delivered
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
event_id | text | The ID of the event. |
returned_response | text | The full response from the recipient's email server. |
smtp_id | text | An ID attached to the message by HubSpot. |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query integrates data from three different tables: email event dropped, email event, and contact information. It joins these tables to create a comprehensive view of dropped email events, including details about the email campaign, recipient, and associated contact. The query also adds a flag to indicate if the contact has been deleted.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_dropped
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
bcc_emails | text | The 'bcc' field of the email message. |
cc_emails | text | The 'cc' field of the email message. |
drop_message | text | The raw message describing why the email message was dropped. This will usually provide additional details beyond 'dropReason'. |
drop_reason | text | The reason why the email message was dropped. See below for the possible values. |
email_subject | text | The subject line of the email message. |
event_id | text | The ID of the event. |
from_email | text | The 'from' field of the email message. |
reply_to_email | text | The 'reply-to' field of the email message. |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query integrates data from three different tables: email event forwards, general email events, and contacts. It joins these tables to create a comprehensive view of email forward events, including details about the email campaign, recipient, and associated contact information. The query also handles potential deleted contacts by including a flag for this status.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_forward
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
browser | text | A JSON object representing the browser which serviced the event. Its comprised of the properties: 'name', 'family', 'producer', 'producer_url', 'type', 'url', 'version'. |
event_id | text | The ID of the event. |
geo_location | text | A JSON object representing the location where the event occurred. It's comprised of the properties: 'city', 'state', 'country'. |
ip_address | integer | The contact's IP address when the event occurred. |
user_agent | text | The user agent responsible for the event, e.g. “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36” |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query integrates data from multiple tables related to Hubspot email events. It starts with the email open events and joins them with general email events to get additional information such as campaign ID and send timestamp. Then it joins with contact data to associate the email events with specific contacts. The query also includes a check for deleted contacts.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_open
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
browser | text | A JSON object representing the browser which serviced the event. Its comprised of the properties: 'name', 'family', 'producer', 'producer_url', 'type', 'url', 'version'. |
duration_open | integer | If provided and nonzero, the approximate number of milliseconds the user had opened the email. |
event_id | text | The ID of the event. |
geo_location | text | A JSON object representing the location where the event occurred. It's comprised of the properties: 'city', 'state', 'country'. |
ip_address | integer | The contact's IP address when the event occurred. |
user_agent | text | The user agent responsible for the event, e.g. “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36” |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query integrates data from three different sources: email print events, general email events, and contact information. It joins these tables to create a comprehensive view of email print events, including details about the email campaign, recipient, and associated contact. The query also includes a coalesce function to handle potentially null values for the 'is_contact_deleted' field.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_print
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
browser | text | A JSON object representing the browser which serviced the event. Its comprised of the properties: 'name', 'family', 'producer', 'producer_url', 'type', 'url', 'version'. |
event_id | text | The ID of the event. |
geo_location | text | A JSON object representing the location where the event occurred. It's comprised of the properties: 'city', 'state', 'country'. |
ip_address | integer | The contact's IP address when the event occurred. |
user_agent | text | The user agent responsible for the event, e.g. “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36” |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query integrates data from three sources: email event sent data, general email event data, and contact data. It joins these tables to create a comprehensive view of email events, including recipient information, campaign details, and whether the contact has been deleted. The query doesn't perform any aggregation, filtering, or complex transformations, but focuses on combining related data from different tables.
IntegrationWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_sent
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
bcc_emails | text | The 'cc' field of the email message. |
cc_emails | text | The 'bcc' field of the email message. |
email_subject | text | The subject line of the email message. |
event_id | text | The ID of the event. |
from_email | text | The 'from' field of the email message. |
reply_to_email | text | The 'reply-to' field of the email message. |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query integrates data from three different sources: email spam report events, general email events, and contact information. It joins these tables to create a comprehensive view of spam report events, including details about the email campaign, recipient, and associated contact. The query also includes a check for deleted contacts.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_spam_report
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
event_id | text | The ID of the event. |
ip_address | integer | The contact's IP address when the event occurred. |
user_agent | integer | The user agent responsible for the event, e.g. “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36” |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query integrates data from three different tables: email event status changes, email events, and contacts. It joins these tables to create a comprehensive view of email status change events, including associated campaign information, recipient details, and contact status. The query uses LEFT JOINs to ensure all status change events are included, even if matching records are not found in the other tables. It also adds a flag to indicate whether the contact has been deleted.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_status_change
), events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.int_hubspot__contact_merge_adjust
), events_joined AS (
SELECT
base.*,
events.created_timestamp,
events.email_campaign_id,
events.recipient_email_address,
events.sent_timestamp AS email_send_timestamp,
events.sent_by_event_id AS email_send_id
FROM base
LEFT JOIN events
USING (event_id)
), contacts_joined AS (
SELECT
events_joined.*,
contacts.contact_id,
COALESCE(contacts.is_contact_deleted, FALSE) AS is_contact_deleted
FROM events_joined
LEFT JOIN contacts
ON events_joined.recipient_email_address = contacts.email
)
SELECT
*
FROM contacts_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
change_source | text | The source of the subscription change. |
event_id | text | The ID of the event. |
is_bounced | integer | A HubSpot employee explicitly initiated the status change to block messages to the recipient. (Note this usage has been deprecated in favor of dropping messages with a 'dropReason' of BLOCKED_ADDRESS.) |
requested_by_email | integer | The email address of the person requesting the change on behalf of the recipient. If not applicable, this property is omitted. |
subscription_status | text | The recipient's portal subscription status. Note that if this is 'UNSUBSCRIBED', the property 'subscriptions' is not necessarily an empty array, nor are all subscriptions contained in it necessarily going to have their statuses set to 'UNSUBSCRIBED'.) |
subscriptions | text | An array of JSON objects representing the status of subscriptions for the recipient. Each JSON subscription object is comprised of the properties: 'id', 'status'. |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
This SQL query aggregates and integrates various email event metrics from Hubspot data. It starts by creating CTEs for email event aggregates and status changes. Then it joins these aggregates with the main email sent events, adding various metrics like bounces, clicks, opens, etc. Finally, it calculates boolean flags for each metric and adds unsubscribe information. The result is a comprehensive view of email campaign performance with detailed metrics and flags for each email send.
AggregationIntegrationFeaturizationWITH __dbt__cte__int_hubspot__email_event_aggregates AS (
WITH events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), aggregates AS (
SELECT
sent_by_event_id AS email_send_id,
COUNT(CASE WHEN event_type = 'OPEN' THEN sent_by_event_id END) AS opens,
COUNT(CASE WHEN event_type = 'SENT' THEN sent_by_event_id END) AS sends,
COUNT(CASE WHEN event_type = 'DELIVERED' THEN sent_by_event_id END) AS deliveries,
COUNT(CASE WHEN event_type = 'DROPPED' THEN sent_by_event_id END) AS drops,
COUNT(CASE WHEN event_type = 'CLICK' THEN sent_by_event_id END) AS clicks,
COUNT(CASE WHEN event_type = 'FORWARD' THEN sent_by_event_id END) AS forwards,
COUNT(CASE WHEN event_type = 'DEFERRED' THEN sent_by_event_id END) AS deferrals,
COUNT(CASE WHEN event_type = 'BOUNCE' THEN sent_by_event_id END) AS bounces,
COUNT(CASE WHEN event_type = 'SPAMREPORT' THEN sent_by_event_id END) AS spam_reports,
COUNT(CASE WHEN event_type = 'PRINT' THEN sent_by_event_id END) AS prints
FROM events
WHERE
NOT sent_by_event_id IS NULL
GROUP BY
1
)
SELECT
*
FROM aggregates
), __dbt__cte__int_hubspot__email_aggregate_status_change AS (
WITH base AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__email_event_status_change
), aggregates AS (
SELECT
email_campaign_id,
email_send_id,
COUNT(CASE WHEN subscription_status = 'UNSUBSCRIBED' THEN 1 END) AS unsubscribes
FROM base
WHERE
NOT email_send_id IS NULL
GROUP BY
1,
2
)
SELECT
*
FROM aggregates
), sends AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__email_event_sent
), metrics AS (
SELECT
*
FROM __dbt__cte__int_hubspot__email_event_aggregates
), joined AS (
SELECT
sends.*,
COALESCE(metrics.bounces, 0) AS bounces,
COALESCE(metrics.clicks, 0) AS clicks,
COALESCE(metrics.deferrals, 0) AS deferrals,
COALESCE(metrics.deliveries, 0) AS deliveries,
COALESCE(metrics.drops, 0) AS drops,
COALESCE(metrics.forwards, 0) AS forwards,
COALESCE(metrics.opens, 0) AS opens,
COALESCE(metrics.prints, 0) AS prints,
COALESCE(metrics.spam_reports, 0) AS spam_reports
FROM sends
LEFT JOIN metrics
USING (email_send_id)
), booleans AS (
SELECT
*,
bounces > 0 AS was_bounced,
clicks > 0 AS was_clicked,
deferrals > 0 AS was_deferred,
deliveries > 0 AS was_delivered,
forwards > 0 AS was_forwarded,
opens > 0 AS was_opened,
prints > 0 AS was_printed,
spam_reports > 0 AS was_spam_reported
FROM joined
), unsubscribes AS (
SELECT
*
FROM __dbt__cte__int_hubspot__email_aggregate_status_change
), unsubscribes_joined AS (
SELECT
booleans.*,
COALESCE(unsubscribes.unsubscribes, 0) AS unsubscribes,
COALESCE(unsubscribes.unsubscribes, 0) > 0 AS was_unsubcribed
FROM booleans
LEFT JOIN unsubscribes
USING (email_send_id)
)
SELECT
*
FROM unsubscribes_joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
bcc_emails | text | The 'cc' field of the email message. |
cc_emails | text | The 'bcc' field of the email message. |
email_subject | text | The subject line of the email message. |
event_id | text | The ID of the event. |
from_email | text | The 'from' field of the email message. |
reply_to_email | text | The 'reply-to' field of the email message. |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
recipient_email_address | text | The email address of the contact related to the event. |
email_send_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
email_send_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
contact_id | integer | The ID of the related contact. |
bounces | bigint | The total number of bounce email events. |
clicks | bigint | The total number of click email events. |
deferrals | bigint | The total number of deferral email events. |
deliveries | bigint | The total number of delivery email events. |
drops | bigint | The total number of drop email events. |
forwards | bigint | The total number of forward email events. |
opens | bigint | The total number of open email events. |
prints | bigint | The total number of print email events. |
spam_reports | bigint | The total number of spam report email events. |
unsubscribes | bigint | The total number of unsubscribe email events. |
was_bounced | boolean | Whether the email was bounced. |
was_clicked | boolean | Whether the email was clicked. |
was_deferred | boolean | Whether the email was deferred. |
was_delivered | boolean | Whether the email was delivered. |
was_forwarded | boolean | Whether the email was forwarded. |
was_opened | boolean | Whether the email was opened. |
was_printed | boolean | Whether the email was printed. |
was_spam_reported | boolean | Whether the email was spam reported. |
was_unsubcribed | boolean | Whether the email was unsubcribed. |
This SQL query integrates data from two tables: 'stg_hubspot__engagement_call' and 'hubspot__engagements'. It joins these tables based on the engagement_id, and combines information from both sources. The query also performs some data cleaning by using COALESCE to handle potential null values and ensure data consistency. The final result includes all columns from both tables, with some specific fields being merged or coalesced for completeness.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_call
), engagements AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__engagements
), joined AS (
SELECT
*, /* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
engagements.contact_ids,
engagements.deal_ids,
engagements.company_ids,
COALESCE(engagements.is_active, NOT base._fivetran_deleted) AS is_active,
COALESCE(engagements.created_timestamp, base.created_timestamp) AS created_timestamp,
COALESCE(engagements.occurred_timestamp, base.occurred_timestamp) AS occurred_timestamp,
COALESCE(engagements.owner_id, base.owner_id) AS owner_id
FROM base
LEFT JOIN engagements
ON base.engagement_id = engagements.engagement_id
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
engagement_id | bigint | The ID of the engagement. |
is_active | boolean | Whether the engagement is currently being shown in the UI. |
created_timestamp | timestamp without time zone | A timestamp representing when the engagement was created. |
occurred_timestamp | timestamp without time zone | A timestamp in representing the time that the engagement should appear in the timeline. |
owner_id | integer | The ID of the engagement's owner. |
contact_ids | bigint[] | List of contacts related to the engagement. |
deal_ids | bigint[] | List of deals related to the engagement. |
company_ids | bigint[] | List of companies related to the engagement. |
engagement_type | text | None |
team_id | integer | None |
This SQL query joins engagement email data from a staging table with general engagements data. It combines information from both sources, using COALESCE to handle potential NULL values and ensure data completeness. The query also adds additional fields from the engagements table such as contact_ids, deal_ids, and company_ids to the email engagement data.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_email
), engagements AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__engagements
), joined AS (
SELECT
*, /* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
engagements.contact_ids,
engagements.deal_ids,
engagements.company_ids,
COALESCE(engagements.is_active, NOT base._fivetran_deleted) AS is_active,
COALESCE(engagements.created_timestamp, base.created_timestamp) AS created_timestamp,
COALESCE(engagements.occurred_timestamp, base.occurred_timestamp) AS occurred_timestamp,
COALESCE(engagements.owner_id, base.owner_id) AS owner_id
FROM base
LEFT JOIN engagements
ON base.engagement_id = engagements.engagement_id
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
engagement_id | bigint | The ID of the engagement. |
is_active | boolean | Whether the engagement is currently being shown in the UI. |
created_timestamp | timestamp without time zone | A timestamp representing when the engagement was created. |
occurred_timestamp | timestamp without time zone | A timestamp in representing the time that the engagement should appear in the timeline. |
owner_id | integer | The ID of the engagement's owner. |
contact_ids | bigint[] | List of contacts related to the engagement. |
deal_ids | bigint[] | List of deals related to the engagement. |
company_ids | bigint[] | List of companies related to the engagement. |
engagement_type | text | None |
team_id | integer | None |
all_owner_ids | integer | None |
all_team_ids | integer | None |
email_subject | text | None |
email_text | text | None |
lastmodifieddate | text | None |
modified_by | integer | None |
This SQL query joins engagement meeting data from a staging table with general engagement data, combining and coalescing information from both sources. It enriches the meeting data with additional fields such as contact IDs, deal IDs, and company IDs from the engagements table. The query also determines the active status of the engagement and ensures consistent timestamps and owner information.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_meeting
), engagements AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__engagements
), joined AS (
SELECT
*, /* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
engagements.contact_ids,
engagements.deal_ids,
engagements.company_ids,
COALESCE(engagements.is_active, NOT base._fivetran_deleted) AS is_active,
COALESCE(engagements.created_timestamp, base.created_timestamp) AS created_timestamp,
COALESCE(engagements.occurred_timestamp, base.occurred_timestamp) AS occurred_timestamp,
COALESCE(engagements.owner_id, base.owner_id) AS owner_id
FROM base
LEFT JOIN engagements
ON base.engagement_id = engagements.engagement_id
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
engagement_id | bigint | The ID of the engagement. |
is_active | boolean | Whether the engagement is currently being shown in the UI. |
created_timestamp | timestamp without time zone | A timestamp representing when the engagement was created. |
occurred_timestamp | timestamp without time zone | A timestamp in representing the time that the engagement should appear in the timeline. |
owner_id | integer | The ID of the engagement's owner. |
contact_ids | bigint[] | List of contacts related to the engagement. |
deal_ids | bigint[] | List of deals related to the engagement. |
company_ids | bigint[] | List of companies related to the engagement. |
engagement_type | text | None |
team_id | integer | None |
created_from_link_id | integer | None |
end_time | text | None |
pre_meeting_prospect_reminders | text | None |
source | text | None |
source_id | text | None |
start_time | text | None |
web_conference_meeting_id | integer | None |
meeting_outcome | integer | None |
body | text | None |
external_url | text | None |
title | text | None |
This SQL query combines engagement note data from a staging table with engagement data from another table. It joins these tables on the engagement_id field and coalesces several fields to use values from the engagements table when available, falling back to the base table values when not. The query also adds fields for contact_ids, deal_ids, and company_ids from the engagements table, and calculates an is_active field based on data from both tables.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_note
), engagements AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__engagements
), joined AS (
SELECT
*, /* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
engagements.contact_ids,
engagements.deal_ids,
engagements.company_ids,
COALESCE(engagements.is_active, NOT base._fivetran_deleted) AS is_active,
COALESCE(engagements.created_timestamp, base.created_timestamp) AS created_timestamp,
COALESCE(engagements.occurred_timestamp, base.occurred_timestamp) AS occurred_timestamp,
COALESCE(engagements.owner_id, base.owner_id) AS owner_id
FROM base
LEFT JOIN engagements
ON base.engagement_id = engagements.engagement_id
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
engagement_id | bigint | The ID of the engagement. |
note | text | The body of the note. The body has a limit of 65536 characters. |
is_active | boolean | Whether the engagement is currently being shown in the UI. |
created_timestamp | timestamp without time zone | A timestamp representing when the engagement was created. |
occurred_timestamp | timestamp without time zone | A timestamp in representing the time that the engagement should appear in the timeline. |
owner_id | integer | The ID of the engagement's owner. |
contact_ids | bigint[] | List of contacts related to the engagement. |
deal_ids | bigint[] | List of deals related to the engagement. |
company_ids | bigint[] | List of companies related to the engagement. |
engagement_type | text | None |
team_id | integer | None |
body_preview | text | None |
lastmodifieddate | text | None |
note_body | text | None |
This SQL query combines data from two tables: 'stg_hubspot__engagement_task' and 'hubspot__engagements'. It joins these tables based on the engagement_id, and selects all columns from both tables. The query also applies some data cleaning by using COALESCE to handle potential null values and to determine the is_active status. It integrates additional information such as contact_ids, deal_ids, and company_ids from the engagements table into the result set.
IntegrationCleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_task
), engagements AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__engagements
), joined AS (
SELECT
*, /* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
engagements.contact_ids,
engagements.deal_ids,
engagements.company_ids,
COALESCE(engagements.is_active, NOT base._fivetran_deleted) AS is_active,
COALESCE(engagements.created_timestamp, base.created_timestamp) AS created_timestamp,
COALESCE(engagements.occurred_timestamp, base.occurred_timestamp) AS occurred_timestamp,
COALESCE(engagements.owner_id, base.owner_id) AS owner_id
FROM base
LEFT JOIN engagements
ON base.engagement_id = engagements.engagement_id
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
engagement_id | bigint | The ID of the engagement. |
is_active | boolean | Whether the engagement is currently being shown in the UI. |
created_timestamp | timestamp without time zone | A timestamp representing when the engagement was created. |
occurred_timestamp | timestamp without time zone | A timestamp in representing the time that the engagement should appear in the timeline. |
owner_id | integer | The ID of the engagement's owner. |
contact_ids | bigint[] | List of contacts related to the engagement. |
deal_ids | bigint[] | List of deals related to the engagement. |
company_ids | bigint[] | List of companies related to the engagement. |
engagement_type | text | None |
team_id | integer | None |
task_type | text | None |
object_id | bigint | None |
engagement_source | text | None |
This SQL query integrates data from multiple Hubspot engagement-related tables. It aggregates contact IDs, deal IDs, and company IDs associated with each engagement, and then joins this aggregated information with the main engagements table. The result is a comprehensive view of each engagement, including its associated contacts, deals, and companies.
IntegrationAggregationWITH engagements AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement
), contacts AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_contact
), contacts_agg AS (
SELECT
engagement_id,
ARRAY_AGG(contact_id) AS contact_ids
FROM contacts
GROUP BY
1
), deals AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_deal
), deals_agg AS (
SELECT
engagement_id,
ARRAY_AGG(deal_id) AS deal_ids
FROM deals
GROUP BY
1
), companies AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_company
), companies_agg AS (
SELECT
engagement_id,
ARRAY_AGG(company_id) AS company_ids
FROM companies
GROUP BY
1
), joined AS (
SELECT
contacts_agg.contact_ids,
deals_agg.deal_ids,
companies_agg.company_ids,
engagements.*
FROM engagements
LEFT JOIN contacts_agg
USING (engagement_id)
LEFT JOIN deals_agg
USING (engagement_id)
LEFT JOIN companies_agg
USING (engagement_id)
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
activity_type | None | The engagement's activity type. |
created_timestamp | timestamp without time zone | A timestamp representing when the engagement was created. |
engagement_id | bigint | The ID of the engagement. |
engagement_type | text | One of NOTE, EMAIL, TASK, MEETING, or CALL, the type of the engagement. |
is_active | boolean | Whether the engagement is currently being shown in the UI. |
last_updated_timestamp | None | A timestamp in representing when the engagement was last updated. |
occurred_timestamp | timestamp without time zone | A timestamp in representing the time that the engagement should appear in the timeline. |
owner_id | integer | The ID of the engagement's owner. |
portal_id | integer | The hub ID. |
contact_ids | bigint[] | List of contacts related to the engagement. |
deal_ids | bigint[] | List of deals related to the engagement. |
company_ids | bigint[] | List of companies related to the engagement. |
This query adjusts contact data by removing merged contacts. It first extracts merged contact IDs from a string field, then removes any contacts that appear in this merged list. The result is a dataset of unique, non-merged contacts.
FilteringCleaningDeduplicationWITH contacts AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__contact
), contact_merge_audit AS (
SELECT
contacts.contact_id,
SPLIT_PART(merges.value, ':', 0) AS vid_to_merge
FROM contacts
CROSS JOIN TABLE(FLATTEN(STRTOK_TO_ARRAY(calculated_merged_vids, ';'))) AS merges
), contact_merge_removal AS (
SELECT
contacts.*
FROM contacts
LEFT JOIN contact_merge_audit
ON CAST(contacts.contact_id AS TEXT) = CAST(contact_merge_audit.vid_to_merge AS TEXT)
WHERE
contact_merge_audit.vid_to_merge IS NULL
)
SELECT
*
FROM contact_merge_removal
Name | Type | Comment |
---|---|---|
contact_id | integer | None |
is_contact_deleted | boolean | None |
calculated_merged_vids | text | None |
text | None | |
contact_company | text | None |
first_name | text | None |
last_name | text | None |
created_date | timestamp without time zone | None |
job_title | integer | None |
company_annual_revenue | integer | None |
_fivetran_synced | timestamp without time zone | None |
This SQL query integrates data from multiple tables related to HubSpot deals. It joins the main deals table with related tables for pipelines, pipeline stages, and owners. The query enriches the deal data with additional information such as pipeline and stage details, owner information, and various status flags. The result is a comprehensive view of deals with enhanced contextual data.
IntegrationCleaningWITH deals AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal
), pipelines AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_pipeline
), pipeline_stages AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_pipeline_stage
), owners AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__owner
), deal_fields_joined AS (
SELECT
deals.*,
COALESCE(pipelines.is_deal_pipeline_deleted, FALSE) AS is_deal_pipeline_deleted,
pipelines.pipeline_label,
pipelines.is_active AS is_pipeline_active,
COALESCE(pipeline_stages.is_deal_pipeline_stage_deleted, FALSE) AS is_deal_pipeline_stage_deleted,
pipelines.deal_pipeline_created_at,
pipelines.deal_pipeline_updated_at,
pipeline_stages.pipeline_stage_label,
owners.email_address AS owner_email_address,
owners.full_name AS owner_full_name
FROM deals
LEFT JOIN pipelines
ON deals.deal_pipeline_id = pipelines.deal_pipeline_id
LEFT JOIN pipeline_stages
ON deals.deal_pipeline_stage_id = pipeline_stages.deal_pipeline_stage_id
LEFT JOIN owners
ON deals.owner_id = owners.owner_id
)
SELECT
*
FROM deal_fields_joined
Name | Type | Comment |
---|
This SQL query aggregates data from the hubspot__email_event_status_change table. It counts the number of unsubscribes for each combination of email_campaign_id and email_send_id. The query filters out rows where email_send_id is null and only considers 'UNSUBSCRIBED' status for counting.
FilteringAggregationWITH base AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__email_event_status_change
), aggregates AS (
SELECT
email_campaign_id,
email_send_id,
COUNT(CASE WHEN subscription_status = 'UNSUBSCRIBED' THEN 1 END) AS unsubscribes
FROM base
WHERE
NOT email_send_id IS NULL
GROUP BY
1,
2
)
SELECT
*
FROM aggregates
Name | Type | Comment |
---|---|---|
email_send_id | None | None |
This SQL query aggregates email event data from the stg_hubspot__email_event table. It counts various types of email events (opens, sends, deliveries, drops, clicks, forwards, deferrals, bounces, spam reports, and prints) for each unique email_send_id. The query filters out rows where sent_by_event_id is null and groups the results by this ID.
FilteringAggregationWITH events AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event
), aggregates AS (
SELECT
sent_by_event_id AS email_send_id,
COUNT(CASE WHEN event_type = 'OPEN' THEN sent_by_event_id END) AS opens,
COUNT(CASE WHEN event_type = 'SENT' THEN sent_by_event_id END) AS sends,
COUNT(CASE WHEN event_type = 'DELIVERED' THEN sent_by_event_id END) AS deliveries,
COUNT(CASE WHEN event_type = 'DROPPED' THEN sent_by_event_id END) AS drops,
COUNT(CASE WHEN event_type = 'CLICK' THEN sent_by_event_id END) AS clicks,
COUNT(CASE WHEN event_type = 'FORWARD' THEN sent_by_event_id END) AS forwards,
COUNT(CASE WHEN event_type = 'DEFERRED' THEN sent_by_event_id END) AS deferrals,
COUNT(CASE WHEN event_type = 'BOUNCE' THEN sent_by_event_id END) AS bounces,
COUNT(CASE WHEN event_type = 'SPAMREPORT' THEN sent_by_event_id END) AS spam_reports,
COUNT(CASE WHEN event_type = 'PRINT' THEN sent_by_event_id END) AS prints
FROM events
WHERE
NOT sent_by_event_id IS NULL
GROUP BY
1
)
SELECT
*
FROM aggregates
Name | Type | Comment |
---|---|---|
email_send_id | None | None |
This SQL query joins email send data with contact list member data to generate email metrics grouped by contact list. It filters out records where the contact_list_id is null, effectively focusing on email sends associated with specific contact lists.
IntegrationFilteringAggregationWITH email_sends AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__email_sends
), contact_list_member AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__contact_list_member
), joined AS (
SELECT
email_sends.*,
contact_list_member.contact_list_id
FROM email_sends
LEFT JOIN contact_list_member
USING (contact_id)
WHERE
NOT contact_list_member.contact_list_id IS NULL
), email_metrics AS (
SELECT
contact_list_id
FROM joined
GROUP BY
1
)
SELECT
*
FROM email_metrics
Name | Type | Comment |
---|---|---|
contact_list_id | integer | None |
total_bounces | numeric | None |
total_unique_bounces | bigint | None |
total_clicks | numeric | None |
total_unique_clicks | bigint | None |
total_deferrals | numeric | None |
total_unique_deferrals | bigint | None |
total_deliveries | numeric | None |
total_unique_deliveries | bigint | None |
total_drops | numeric | None |
total_unique_drops | bigint | None |
total_forwards | numeric | None |
total_unique_forwards | bigint | None |
total_opens | numeric | None |
total_unique_opens | bigint | None |
total_prints | numeric | None |
total_unique_prints | bigint | None |
total_spam_reports | numeric | None |
total_unique_spam_reports | bigint | None |
total_unsubscribes | numeric | None |
total_unique_unsubscribes | bigint | None |
This SQL query calculates engagement metrics for each contact in HubSpot. It joins engagement data with contact data, then counts the number of different types of engagements (notes, tasks, calls, meetings, emails, incoming emails, and forwarded emails) for each contact. The result is a summary of engagement activities per contact.
IntegrationAggregationFeaturizationWITH engagements AS (
SELECT
*
FROM TEST.PUBLIC_hubspot.hubspot__engagements
), engagement_contacts AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_contact
), engagement_contacts_joined AS (
SELECT
engagements.engagement_type,
engagement_contacts.contact_id
FROM engagements
INNER JOIN engagement_contacts
USING (engagement_id)
), engagement_contacts_agg AS (
SELECT
contact_id,
COUNT(CASE WHEN engagement_type = 'NOTE' THEN contact_id END) AS count_engagement_notes,
COUNT(CASE WHEN engagement_type = 'TASK' THEN contact_id END) AS count_engagement_tasks,
COUNT(CASE WHEN engagement_type = 'CALL' THEN contact_id END) AS count_engagement_calls,
COUNT(CASE WHEN engagement_type = 'MEETING' THEN contact_id END) AS count_engagement_meetings,
COUNT(CASE WHEN engagement_type = 'EMAIL' THEN contact_id END) AS count_engagement_emails,
COUNT(CASE WHEN engagement_type = 'INCOMING_EMAIL' THEN contact_id END) AS count_engagement_incoming_emails,
COUNT(CASE WHEN engagement_type = 'FORWARDED_EMAIL' THEN contact_id END) AS count_engagement_forwarded_emails
FROM engagement_contacts_joined
GROUP BY
1
)
SELECT
*
FROM engagement_contacts_agg
Name | Type | Comment |
---|---|---|
contact_id | None | None |
This SQL query is primarily focused on data cleaning and structuring for a HubSpot company staging model. It starts by selecting all columns from a temporary table, then defines a set of columns with specific data types. The query then selects and casts specific fields, potentially adding pass-through columns and calculated fields (as indicated by comments, though not explicitly shown in the provided SQL). The final result is a cleaned and structured dataset of company information from HubSpot.
CleaningIntegrationWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__company_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS company_id,
CAST(NULL AS BOOLEAN) AS is_company_deleted,
CAST(NULL AS TEXT) AS company_name,
CAST(NULL AS TEXT) AS description,
CAST(NULL AS TIMESTAMP) AS created_date,
CAST(NULL AS TEXT) AS industry,
CAST(NULL AS TEXT) AS street_address,
CAST(NULL AS TEXT) AS street_address_2,
CAST(NULL AS TEXT) AS city,
CAST(NULL AS TEXT) AS state,
CAST(NULL AS TEXT) AS country,
CAST(NULL AS INT) AS company_annual_revenue
FROM base
), fields AS (
SELECT
company_id, /* just default columns + explicitly configured passthrough columns */ /* a few columns below are aliased within the macros/get_company_columns.sql macro */
is_company_deleted,
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
company_name,
description,
created_date,
industry,
street_address,
street_address_2,
city,
state,
country,
company_annual_revenue
/* The below macro adds the fields defined within your hubspot__ticket_pass_through_columns variable into the staging model */ /* The below macro add the ability to create calculated fields using the hubspot__company_calculated_fields variable. */
FROM macro
), joined AS (
SELECT
fields.*
FROM fields
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
is_company_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
company_id | bigint | The ID of the company. |
company_name | text | The name of the company. |
description | text | A short statement about the company's mission and goals. |
created_date | timestamp without time zone | The date the company was added to your account. |
industry | text | The type of business the company performs. |
street_address | text | The street address of the company. |
street_address_2 | text | Additional address information for the company. |
city | text | The city where the company is located. |
state | text | The state where the company is located. |
country | text | The country where the company is located. |
company_annual_revenue | integer | The actual or estimated annual revenue of the company. |
This SQL query performs data type casting and column renaming on the 'stg_hubspot__company_property_history' table. It first creates a base CTE from the temporary table, then defines a macro CTE with null values and appropriate data types. Finally, it casts and renames columns in the fields CTE, preparing the data for further use.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__company_property_history_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS company_id,
CAST(NULL AS TEXT) AS name,
CAST(NULL AS TEXT) AS source,
CAST(NULL AS TEXT) AS source_id,
CAST(NULL AS TIMESTAMP) AS change_timestamp,
CAST(NULL AS TEXT) AS value
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
company_id,
name AS field_name,
source AS change_source,
source_id AS change_source_id,
CAST(change_timestamp AS TIMESTAMP) AS change_timestamp, /* source field name = timestamp ; alias declared in macros/get_company_property_history_columns.sql */
value AS new_value
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
change_source | text | The source (reason) of the change. |
change_source_id | integer | The ID of the object that caused the change, if applicable. |
change_timestamp | timestamp without time zone | The timestamp the changed occurred. |
company_id | bigint | The ID of the related company record. |
field_name | text | The name of the field being changed. |
new_value | text | The new value of the field. |
This SQL query is a simple select statement that retrieves all columns from the TEST.hubspot.company_property_history table. The comment suggests that this query is part of a dbt compilation process and may be used as a placeholder or for syntax validation purposes.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.company_property_history
Name | Type | Comment |
---|---|---|
company_id | bigint | None |
timestamp | text | None |
_fivetran_synced | text | None |
source | text | None |
source_id | integer | None |
name | text | None |
value | text | None |
This SQL query selects all columns from the 'company' table in the 'hubspot' schema of the 'TEST' database. The comment suggests that this is a placeholder query, possibly used during dbt compilation, and that the actual table might not exist yet or all columns might have been excluded.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.company
Name | Type | Comment |
---|---|---|
id | bigint | None |
is_deleted | boolean | None |
This SQL query is a staging model for HubSpot contact data. It selects and casts specific fields from a temporary table, applies default columns and configured pass-through columns, and prepares the data for further processing. The query includes placeholder logic for calculated fields and allows for customization through variables.
CleaningIntegrationOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__contact_tmp
), macro AS (
SELECT
CAST(NULL AS BOOLEAN) AS is_contact_deleted,
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS contact_id,
CAST(NULL AS TEXT) AS calculated_merged_vids,
CAST(NULL AS TEXT) AS email,
CAST(NULL AS TEXT) AS contact_company,
CAST(NULL AS TEXT) AS first_name,
CAST(NULL AS TEXT) AS last_name,
CAST(NULL AS TIMESTAMP) AS created_date,
CAST(NULL AS TEXT) AS job_title,
CAST(NULL AS INT) AS company_annual_revenue
FROM base
), fields AS (
SELECT
contact_id, /* just default columns + explicitly configured passthrough columns. */ /* a few columns below are aliased within the macros/get_contact_columns.sql macro */
is_contact_deleted,
calculated_merged_vids, /* will be null for BigQuery users until v3 api is rolled out to them */
email,
contact_company,
first_name,
last_name,
CAST(created_date AS TIMESTAMP) AS created_date,
job_title,
company_annual_revenue,
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced
/* The below macro adds the fields defined within your hubspot__contact_pass_through_columns variable into the staging model */ /* The below macro add the ability to create calculated fields using the hubspot__contact_calculated_fields variable. */
FROM macro
), joined AS (
SELECT
fields.*
FROM fields
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
is_contact_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
contact_id | integer | The ID of the contact. |
text | The contact's email. | |
contact_company | text | The name of the contact's company. |
first_name | text | The contact's first name. |
last_name | text | The contact's last name. |
created_date | timestamp without time zone | The date that the contact was created in your HubSpot account. |
job_title | integer | The contact's job title. |
company_annual_revenue | integer | The contact's annual company revenue. |
calculated_merged_vids | text | List of mappings representing contact IDs that have been merged into the contact at hand. Format: |
This SQL query stages data from a Hubspot contact list source table. It performs type casting on various fields, renames some columns for clarity, and transforms boolean fields into 'is_' prefixed columns. The query doesn't filter, deduplicate, or aggregate data, but primarily focuses on cleaning and standardizing the data format.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__contact_list_tmp
), macro AS (
SELECT
CAST(NULL AS BOOLEAN) AS _fivetran_deleted,
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TIMESTAMP) AS created_at,
CAST(NULL AS BOOLEAN) AS deleteable,
CAST(NULL AS BOOLEAN) AS dynamic,
CAST(NULL AS INT) AS id,
CAST(NULL AS TEXT) AS metadata_error,
CAST(NULL AS TIMESTAMP) AS metadata_last_processing_state_change_at,
CAST(NULL AS TIMESTAMP) AS metadata_last_size_change_at,
CAST(NULL AS TEXT) AS metadata_processing,
CAST(NULL AS INT) AS metadata_size,
CAST(NULL AS TEXT) AS name,
CAST(NULL AS INT) AS portal_id,
CAST(NULL AS TIMESTAMP) AS updated_at
FROM base
), fields AS (
SELECT
_fivetran_deleted AS is_contact_list_deleted,
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
CAST(created_at AS TIMESTAMP) AS created_timestamp,
deleteable AS is_deletable,
dynamic AS is_dynamic,
id AS contact_list_id,
metadata_error,
CAST(metadata_last_processing_state_change_at AS TIMESTAMP) AS metadata_last_processing_state_change_at,
CAST(metadata_last_size_change_at AS TIMESTAMP) AS metadata_last_size_change_at,
metadata_processing,
metadata_size,
name AS contact_list_name,
portal_id,
CAST(updated_at AS TIMESTAMP) AS updated_timestamp
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
is_contact_list_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
contact_list_id | integer | The ID of the contact list. |
contact_list_name | text | The name of the contact list. |
created_timestamp | timestamp without time zone | A timestamp of the time the list was created. |
is_deletable | boolean | If this is false, this is a system list and cannot be deleted. |
is_dynamic | boolean | Whether the contact list is dynamic. |
metadata_error | integer | Any errors that happened the last time the list was processed. |
metadata_last_processing_state_change_at | timestamp without time zone | A timestamp of the last time that the processing state changed. |
metadata_last_size_change_at | timestamp without time zone | A timestamp of the last time that the size of the list changed. |
metadata_processing | text | One of DONE, REFRESHING, INITIALIZING, or PROCESSING. DONE indicates the list has finished processing, any other value indicates that list membership is being evaluated. |
metadata_size | integer | The approximate number of contacts in the list. |
portal_id | integer | The hub ID. |
updated_timestamp | timestamp without time zone | A timestamp of the time that the list was last modified. |
This SQL query performs data type casting and column renaming for the 'stg_hubspot__contact_list_member' model. It starts with a base CTE that selects all columns from a temporary table. Then, it defines a structure with NULL values and specific data types. Finally, it casts the columns to the desired data types and renames some columns before selecting all fields from the final CTE.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__contact_list_member_tmp
), macro AS (
SELECT
CAST(NULL AS BOOLEAN) AS _fivetran_deleted,
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TIMESTAMP) AS added_at,
CAST(NULL AS INT) AS contact_id,
CAST(NULL AS INT) AS contact_list_id
FROM base
), fields AS (
SELECT
_fivetran_deleted AS is_contact_list_member_deleted,
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
CAST(added_at AS TIMESTAMP) AS added_timestamp,
contact_id,
contact_list_id
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
is_contact_list_member_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
added_timestamp | timestamp without time zone | The timestamp a contact was added to a list. |
contact_id | integer | The ID of the related contact. |
contact_list_id | integer | The ID of the related contact list. |
This SQL query selects all columns from the 'contact_list_member' table in the 'hubspot' schema of the 'TEST' database. The query appears to be a placeholder or template, as indicated by the comment suggesting that no columns were returned, possibly due to the relation not existing yet or all columns being excluded. The purpose seems to be setting up a staging table for Hubspot contact list member data.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.contact_list_member
Name | Type | Comment |
---|---|---|
contact_id | integer | None |
contact_list_id | integer | None |
_fivetran_deleted | boolean | None |
_fivetran_synced | text | None |
added_at | text | None |
This SQL query is a simple SELECT statement that retrieves all columns from the TEST.hubspot.contact_list table. The comment suggests that no columns were returned, possibly because the relation doesn't exist yet or all columns were excluded. The query is likely a placeholder or template for future development.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.contact_list
Name | Type | Comment |
---|---|---|
id | integer | None |
_fivetran_deleted | boolean | None |
_fivetran_synced | text | None |
created_at | text | None |
deleteable | boolean | None |
dynamic | boolean | None |
metadata_error | integer | None |
metadata_last_processing_state_change_at | text | None |
metadata_last_size_change_at | text | None |
metadata_processing | text | None |
metadata_size | integer | None |
offset | integer | None |
portal_id | integer | None |
updated_at | text | None |
name | text | None |
This SQL query is primarily focused on data cleaning and standardization. It starts by selecting all columns from a temporary staging table, then creates a macro CTE with NULL values to define the structure. The fields CTE then casts and renames columns to ensure proper data types and consistent naming conventions. The final SELECT statement returns all columns from the fields CTE.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__contact_property_history_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS contact_id,
CAST(NULL AS TEXT) AS name,
CAST(NULL AS TEXT) AS source,
CAST(NULL AS TEXT) AS source_id,
CAST(NULL AS TIMESTAMP) AS change_timestamp,
CAST(NULL AS TEXT) AS value
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
contact_id,
name AS field_name,
source AS change_source,
source_id AS change_source_id,
CAST(change_timestamp AS TIMESTAMP) AS change_timestamp, /* source field name = timestamp ; alias declared in macros/get_contact_property_history_columns.sql */
value AS new_value
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
change_source | text | The source (reason) of the change. |
change_source_id | text | The ID of the object that caused the change, if applicable. |
change_timestamp | timestamp without time zone | The timestamp the changed occurred. |
contact_id | integer | The ID of the related contact record. |
field_name | text | The name of the field being changed. |
new_value | text | The new value of the field. |
This SQL query is a simple SELECT statement that retrieves all columns from the 'contact_property_history' table in the 'hubspot' schema of the 'TEST' database. The query does not perform any filtering, transformation, or aggregation of the data. It's a straightforward extraction of all available data from the specified table.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.contact_property_history
Name | Type | Comment |
---|---|---|
contact_id | integer | None |
timestamp | text | None |
_fivetran_synced | text | None |
source | text | None |
name | text | None |
value | text | None |
source_id | text | None |
This SQL query selects all columns from the 'contact' table in the 'hubspot' schema of the 'TEST' database. The comment suggests that this query is part of a dbt model and is designed to create a temporary staging table for Hubspot contact data. The query itself is simple and doesn't perform any transformations or filtering on the data.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.contact
Name | Type | Comment |
---|---|---|
_fivetran_deleted | boolean | None |
_fivetran_synced | timestamp without time zone | None |
property_email | text | None |
id | integer | None |
property_company | text | None |
property_firstname | text | None |
property_lastname | text | None |
property_email_1 | text | None |
property_createdate | timestamp without time zone | None |
property_jobtitle | integer | None |
property_annualrevenue | integer | None |
property_hs_calculated_merged_vids | text | None |
property_created_at | timestamp without time zone | None |
This SQL query is primarily focused on data cleaning and type casting for a HubSpot deals staging model. It starts with a base CTE that selects all columns from a temporary table. Then, it defines a macro CTE that sets up null values with specific data types for each column. The fields CTE then casts various columns to their appropriate data types and selects specific columns from the macro CTE. Finally, it joins the fields back to themselves (which effectively just selects all columns from the fields CTE) and returns the result.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS deal_id,
CAST(NULL AS TEXT) AS deal_pipeline_id,
CAST(NULL AS TEXT) AS deal_pipeline_stage_id,
CAST(NULL AS BOOLEAN) AS is_deal_deleted,
CAST(NULL AS INT) AS owner_id,
CAST(NULL AS INT) AS portal_id,
CAST(NULL AS TEXT) AS deal_name,
CAST(NULL AS TEXT) AS description,
CAST(NULL AS INT) AS amount,
CAST(NULL AS TIMESTAMP) AS closed_date,
CAST(NULL AS TIMESTAMP) AS created_date
FROM base
), fields AS (
SELECT
deal_name, /* just default columns + explicitly configured passthrough columns */ /* a few columns below are aliased within the macros/get_deal_columns.sql macro */
CAST(closed_date AS TIMESTAMP) AS closed_date,
CAST(created_date AS TIMESTAMP) AS created_date,
is_deal_deleted,
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
deal_id,
CAST(deal_pipeline_id AS TEXT) AS deal_pipeline_id,
CAST(deal_pipeline_stage_id AS TEXT) AS deal_pipeline_stage_id,
owner_id,
portal_id,
description,
amount
/* The below macro adds the fields defined within your hubspot__deal_pass_through_columns variable into the staging model */ /* The below macro add the ability to create calculated fields using the hubspot__deal_calculated_fields variable. */
FROM macro
), joined AS (
SELECT
fields.*
FROM fields
)
SELECT
*
FROM joined
Name | Type | Comment |
---|---|---|
is_deal_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
deal_id | bigint | The ID of the deal |
portal_id | integer | The hub ID. |
deal_pipeline_id | text | The ID of the deal's pipeline. |
deal_pipeline_stage_id | text | The ID of the deal's pipeline stage. |
owner_id | bigint | The ID of the deal's owner. |
deal_name | text | The name you have given this deal. |
description | text | A brief description of the deal. |
amount | integer | The total value of the deal in the deal's currency. |
closed_date | timestamp without time zone | The day the deal is expected to close, or was closed. |
created_date | timestamp without time zone | The date the deal was created. This property is set automatically by HubSpot. |
This SQL query creates a staging table for Hubspot deal-company associations. It starts with a base table, then creates a macro CTE to define the structure and data types of the fields. Finally, it selects and casts the fields from the macro CTE to create the final output. The query primarily focuses on data type standardization and structure definition.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_company_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS deal_id,
CAST(NULL AS INT) AS company_id,
CAST(NULL AS INT) AS type_id
FROM base
), fields AS (
SELECT
company_id,
deal_id,
type_id,
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
company_id | integer | The ID of the company. |
deal_id | integer | The ID of the deal. |
type_id | integer | The ID of the type. |
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
This SQL query selects all columns from the 'deal_company' table in the 'hubspot' schema of the 'TEST' database. The query is likely a staging step to prepare data for further processing or analysis in a dbt (data build tool) project. The comment suggests that the table might not exist yet or all columns were excluded, and the star (*) is used as a placeholder during dbt compilation.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.deal_company
Name | Type | Comment |
---|---|---|
company_id | integer | None |
deal_id | integer | None |
type_id | integer | None |
This SQL query performs a data type casting operation on a staging table for Hubspot deal-contact relationships. It selects all columns from a temporary table, creates a macro CTE with null values and specific data types, and then casts the columns to their appropriate data types in the final select statement. The query doesn't filter, deduplicate, or aggregate data, but rather focuses on standardizing the data types of the columns.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_contact_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS deal_id,
CAST(NULL AS INT) AS contact_id,
CAST(NULL AS INT) AS type_id
FROM base
), fields AS (
SELECT
contact_id,
deal_id,
type_id,
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
contact_id | bigint | The ID of the contact. |
deal_id | bigint | The ID of the deal. |
type_id | integer | The ID of the type. |
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
This SQL query selects all columns from the 'deal_contact' table in the 'hubspot' schema of the 'TEST' database. The query is likely a placeholder or template, as indicated by the comment suggesting that no columns were returned, possibly because the relation doesn't exist yet or all columns were excluded.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.deal_contact
Name | Type | Comment |
---|---|---|
contact_id | bigint | None |
deal_id | bigint | None |
_fivetran_synced | timestamp without time zone | None |
type_id | integer | None |
This SQL query performs data cleaning and transformation on the 'stg_hubspot__deal_pipeline_tmp' table. It casts columns to specific data types, renames some columns, and modifies others (e.g., converting '_fivetran_deleted' to 'is_deal_pipeline_deleted'). The query doesn't filter, deduplicate, or aggregate data, but focuses on standardizing and reformatting the existing columns.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_pipeline_tmp
), macro AS (
SELECT
CAST(NULL AS BOOLEAN) AS _fivetran_deleted,
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS BOOLEAN) AS active,
CAST(NULL AS INT) AS display_order,
CAST(NULL AS TEXT) AS label,
CAST(NULL AS TEXT) AS pipeline_id,
CAST(NULL AS TIMESTAMP) AS created_at,
CAST(NULL AS TIMESTAMP) AS updated_at
FROM base
), fields AS (
SELECT
_fivetran_deleted AS is_deal_pipeline_deleted,
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
active AS is_active,
display_order,
label AS pipeline_label,
CAST(pipeline_id AS TEXT) AS deal_pipeline_id,
created_at AS deal_pipeline_created_at,
updated_at AS deal_pipeline_updated_at
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
is_deal_pipeline_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
deal_pipeline_id | text | The ID of the pipeline. |
display_order | integer | Used to determine the order in which the pipelines appear when viewed in HubSpot |
deal_pipeline_created_at | text | A timestamp representing when the record was created. |
deal_pipeline_updated_at | text | A timestamp representing when the record was updated. |
is_active | boolean | Whether the stage is currently in use. |
pipeline_label | text | The human-readable label for the pipeline. The label is used when showing the pipeline in HubSpot. |
This SQL query performs a series of data type conversions and column renamings on the 'stg_hubspot__deal_pipeline_stage' model. It starts by selecting all columns from a temporary table, then creates a macro with null values and specific data types for each column. Finally, it applies these data type conversions and renames several columns to more descriptive names.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_pipeline_stage_tmp
), macro AS (
SELECT
CAST(NULL AS BOOLEAN) AS _fivetran_deleted,
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS BOOLEAN) AS active,
CAST(NULL AS BOOLEAN) AS closed_won,
CAST(NULL AS INT) AS display_order,
CAST(NULL AS TEXT) AS label,
CAST(NULL AS TEXT) AS pipeline_id,
CAST(NULL AS FLOAT) AS probability,
CAST(NULL AS TEXT) AS stage_id,
CAST(NULL AS TIMESTAMP) AS created_at,
CAST(NULL AS TIMESTAMP) AS updated_at
FROM base
), fields AS (
SELECT
_fivetran_deleted AS is_deal_pipeline_stage_deleted,
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
active AS is_active,
closed_won AS is_closed_won,
display_order,
label AS pipeline_stage_label,
pipeline_id AS deal_pipeline_id,
probability,
CAST(stage_id AS TEXT) AS deal_pipeline_stage_id,
created_at AS deal_pipeline_stage_created_at,
updated_at AS deal_pipeline_stage_updated_at
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
is_deal_pipeline_stage_deleted | boolean | Boolean indicating whether a record has been deleted in Hubspot and/or inferred deleted in Hubspot by Fivetran; _fivetran_deleted and is_deleted fields are equivalent. |
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
deal_pipeline_id | text | The ID of the related pipeline. |
deal_pipeline_stage_id | text | The ID of the pipeline stage. |
display_order | integer | Used to determine the order in which the stages appear when viewed in HubSpot. |
is_active | boolean | Whether the pipeline stage is currently in use. |
is_closed_won | boolean | Whether the stage represents a Closed Won deal. |
pipeline_stage_label | text | The human-readable label for the stage. The label is used when showing the stage in HubSpot. |
probability | double precision | The probability that the deal will close. Used for the deal forecast. |
deal_pipeline_stage_created_at | text | A timestamp representing when the record was created. |
deal_pipeline_stage_updated_at | text | A timestamp representing when the record was updated. |
This SQL query is a simple SELECT statement that retrieves all columns from the 'deal_pipeline_stage' table in the 'hubspot' schema of the 'TEST' database. The comment suggests that this query is part of a dbt model and may be used as a placeholder or for initial setup purposes.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.deal_pipeline_stage
Name | Type | Comment |
---|---|---|
_fivetran_deleted | boolean | None |
_fivetran_synced | text | None |
active | boolean | None |
closed_won | boolean | None |
display_order | integer | None |
probability | double precision | None |
stage_id | character varying(100) | None |
label | text | None |
pipeline_id | text | None |
created_at | text | None |
updated_at | text | None |
This SQL query selects all columns from the 'deal_pipeline' table in the 'hubspot' schema of the 'TEST' database. The query appears to be a placeholder or template, as indicated by the comment suggesting that no columns were returned, possibly because the relation doesn't exist yet or all columns were excluded. The asterisk (*) is used to keep SQLFluff (a SQL linter) happy during dbt compilation.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.deal_pipeline
Name | Type | Comment |
---|---|---|
pipeline_id | character varying(100) | None |
_fivetran_deleted | boolean | None |
_fivetran_synced | text | None |
active | boolean | None |
display_order | integer | None |
label | text | None |
created_at | text | None |
updated_at | text | None |
This SQL query performs data type casting and column renaming for the Hubspot deal property history data. It starts with a base CTE that selects all columns from a temporary table. Then, it defines a macro CTE with null values and specific data types for each column. Finally, it casts the columns to the appropriate data types and renames some columns in the fields CTE before selecting all columns from it.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_property_history_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS deal_id,
CAST(NULL AS TEXT) AS name,
CAST(NULL AS TEXT) AS source,
CAST(NULL AS TEXT) AS source_id,
CAST(NULL AS TIMESTAMP) AS change_timestamp,
CAST(NULL AS TEXT) AS value
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
deal_id,
name AS field_name,
source AS change_source,
source_id AS change_source_id,
CAST(change_timestamp AS TIMESTAMP) AS change_timestamp, /* source field name = timestamp ; alias declared in macros/get_deal_property_history_columns.sql */
value AS new_value
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
change_source | text | The source (reason) of the change. |
change_source_id | text | The ID of the object that caused the change, if applicable. |
change_timestamp | timestamp without time zone | The timestamp the changed occurred. |
deal_id | bigint | The ID of the related deal record. |
field_name | text | The name of the field being changed. |
new_value | text | The new value of the field. |
This SQL query selects all columns from the 'deal_property_history' table in the 'hubspot' schema of the 'TEST' database. The query appears to be a staging step, likely used to create a temporary or intermediate table for further processing in a dbt model.
IntegrationSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.deal_property_history
Name | Type | Comment |
---|---|---|
deal_id | bigint | None |
timestamp | text | None |
_fivetran_synced | text | None |
source | text | None |
name | text | None |
source_id | text | None |
value | text | None |
This SQL query performs data type casting and column renaming for the 'stg_hubspot__deal_stage' model. It starts by selecting all columns from a temporary table, then explicitly casts several columns to specific data types (mostly to handle NULL values), and finally renames the 'value' column to 'deal_stage_name' in the final output.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__deal_stage_tmp
), fields AS (
SELECT
CAST(NULL AS BOOLEAN) AS _fivetran_active,
CAST(NULL AS TIMESTAMP) AS _fivetran_end,
CAST(NULL AS TIMESTAMP) AS _fivetran_start,
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TIMESTAMP) AS date_entered,
CAST(NULL AS INT) AS deal_id,
CAST(NULL AS TEXT) AS source,
CAST(NULL AS TEXT) AS source_id,
CAST(NULL AS TEXT) AS value
FROM base
), final AS (
SELECT
CAST(date_entered AS TIMESTAMP) AS date_entered,
deal_id,
source,
source_id,
value AS deal_stage_name,
_fivetran_active,
CAST(_fivetran_end AS TIMESTAMP) AS _fivetran_end,
CAST(_fivetran_start AS TIMESTAMP) AS _fivetran_start
FROM fields
)
SELECT
*
FROM final
Name | Type | Comment |
---|---|---|
_fivetran_active | boolean | Boolean indicating whether the deal stage is active. |
_fivetran_end | timestamp without time zone | The Fivetran calculated exist time of the deal stage. |
_fivetran_start | timestamp without time zone | The date the deal stage was entered. |
_fivetran_synced | None | Timestamp of when Fivetran synced a record. |
date_entered | timestamp without time zone | The timestamp the deal stage was entered. |
deal_id | bigint | Reference to the deal. |
source | text | The relevant source of the deal stage. |
source_id | text | Reference to the source. |
deal_stage_name | text | The value of the deal stage. Typically the name of the stage. |
This SQL query selects all columns from the 'deal_stage' table in the 'hubspot' schema of the 'TEST' database. The query is designed as a staging step, likely to be used as an intermediate layer in a data transformation pipeline. The comment suggests that this query might be part of a dbt (data build tool) project and is possibly used as a placeholder or template for future development.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.deal_stage
Name | Type | Comment |
---|---|---|
_fivetran_start | timestamp without time zone | None |
deal_id | bigint | None |
_fivetran_active | boolean | None |
_fivetran_end | timestamp without time zone | None |
_fivetran_synced | timestamp without time zone | None |
date_entered | timestamp without time zone | None |
source | text | None |
source_id | text | None |
value | text | None |
This SQL query is a simple select statement that retrieves all columns from the 'deal' table in the 'hubspot' schema of the 'TEST' database. The comment suggests that this query is part of a dbt (data build tool) project and is used as a staging step for Hubspot deal data. The asterisk (*) is used as a placeholder to ensure compatibility with SQLFluff, a SQL linting tool.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.deal
Name | Type | Comment |
---|---|---|
deal_id | bigint | None |
owner_id | bigint | None |
deal_pipeline_id | text | None |
deal_pipeline_stage_id | text | None |
is_deleted | boolean | None |
This SQL query performs a series of transformations on data from the 'stg_hubspot__email_campaign_tmp' table. It first creates a CTE with NULL values for all expected columns, then casts and renames columns from the source table. The query primarily focuses on data type casting and column renaming to standardize the output format.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_campaign_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS app_id,
CAST(NULL AS TEXT) AS app_name,
CAST(NULL AS INT) AS content_id,
CAST(NULL AS INT) AS id,
CAST(NULL AS TEXT) AS name,
CAST(NULL AS INT) AS num_included,
CAST(NULL AS INT) AS num_queued,
CAST(NULL AS TEXT) AS sub_type,
CAST(NULL AS TEXT) AS subject,
CAST(NULL AS TEXT) AS type
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
app_id,
app_name,
content_id,
id AS email_campaign_id,
name AS email_campaign_name,
num_included,
num_queued,
sub_type AS email_campaign_sub_type,
subject AS email_campaign_subject,
type AS email_campaign_type
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
app_id | integer | The app ID. |
app_name | text | The app name. |
content_id | bigint | The ID of the content. |
email_campaign_id | bigint | The ID of the email campaign. |
email_campaign_name | text | The name of the email campaign. |
email_campaign_sub_type | integer | The email campaign sub-type. |
email_campaign_subject | text | The subject of the email campaign. |
email_campaign_type | text | The email campaign type. |
num_included | integer | The number of messages included as part of the email campaign. |
num_queued | integer | The number of messages queued as part of the email campaign. |
This SQL query selects all columns from the 'email_campaign' table in the 'hubspot' schema of the 'TEST' database. The comment suggests that this query is part of a dbt model and is used as a placeholder or template, possibly for compilation purposes or to satisfy SQLFluff formatting requirements.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_campaign
Name | Type | Comment |
---|---|---|
id | bigint | None |
_fivetran_synced | text | None |
app_id | integer | None |
content_id | bigint | None |
num_included | integer | None |
num_queued | integer | None |
sub_type | integer | None |
type | text | None |
app_name | text | None |
name | text | None |
subject | text | None |
This SQL query performs data cleaning and transformation on the 'stg_hubspot__email_event' table. It starts by selecting all columns from a temporary table, then defines a macro with null values for all expected columns. Finally, it casts and renames various columns to standardize data types and improve column naming conventions.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS app_id,
CAST(NULL AS TIMESTAMP) AS caused_by_created,
CAST(NULL AS TEXT) AS caused_by_id,
CAST(NULL AS TIMESTAMP) AS created,
CAST(NULL AS INT) AS email_campaign_id,
CAST(NULL AS BOOLEAN) AS filtered_event,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TIMESTAMP) AS obsoleted_by_created,
CAST(NULL AS TEXT) AS obsoleted_by_id,
CAST(NULL AS INT) AS portal_id,
CAST(NULL AS TEXT) AS recipient,
CAST(NULL AS TIMESTAMP) AS sent_by_created,
CAST(NULL AS TEXT) AS sent_by_id,
CAST(NULL AS TEXT) AS type
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
app_id,
CAST(caused_by_created AS TIMESTAMP) AS caused_timestamp,
caused_by_id AS caused_by_event_id,
CAST(created AS TIMESTAMP) AS created_timestamp,
email_campaign_id,
filtered_event AS is_filtered_event,
id AS event_id,
CAST(obsoleted_by_created AS TIMESTAMP) AS obsoleted_timestamp,
obsoleted_by_id AS obsoleted_by_event_id,
portal_id,
recipient AS recipient_email_address,
CAST(sent_by_created AS TIMESTAMP) AS sent_timestamp,
sent_by_id AS sent_by_event_id,
type AS event_type
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
app_id | integer | The ID of the app that sent the email. |
caused_by_event_id | integer | The event ID which uniquely identifies the event which directly caused this event. If not applicable, this property is omitted. |
caused_timestamp | timestamp without time zone | The timestamp of the event that caused this event. |
created_timestamp | timestamp without time zone | The created timestamp of the event. |
email_campaign_id | integer | The ID of the related email campaign. |
event_id | text | The ID of the event. |
event_type | text | The type of event. |
is_filtered_event | boolean | A boolean representing whether the event has been filtered out of reporting based on customer reports settings or not. |
obsoleted_by_event_id | integer | The event ID which uniquely identifies the follow-on event which makes this current event obsolete. If not applicable, this property is omitted. |
obsoleted_timestamp | timestamp without time zone | The timestamp of the event that made the current event obsolete. |
portal_id | integer | The hub ID. |
recipient_email_address | text | The email address of the contact related to the event. |
sent_by_event_id | text | The event ID which uniquely identifies the email message's SENT event. If not applicable, this property is omitted. |
sent_timestamp | timestamp without time zone | The timestamp of the SENT event related to this event. |
This SQL query performs a data cleaning and transformation process on the 'stg_hubspot__email_event_bounce_tmp' table. It first creates a base CTE with all columns from the source table. Then, it defines a macro CTE that sets up the desired data types for each column. Finally, it renames and casts the columns in the fields CTE before selecting all columns from the final result.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_bounce_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TEXT) AS category,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS response,
CAST(NULL AS TEXT) AS status
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
category AS bounce_category,
id AS event_id,
response AS returned_response,
status AS returned_status
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
bounce_category | text | The best-guess of the type of bounce encountered. If an appropriate category couldn't be determined, this property is omitted. See below for the possible values. Note that this is a derived value, and may be modified at any time to improve the accuracy of classification. |
event_id | text | The ID of the event. |
returned_response | text | The full response from the recipient's email server. |
returned_status | integer | The status code returned from the recipient's email server. |
This SQL query selects all columns from the 'email_event_bounce' table in the 'hubspot' schema of the 'TEST' database. It appears to be a staging query that extracts raw data without any transformations or filters.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_bounce
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
category | text | None |
status | integer | None |
response | text | None |
This SQL query performs a series of transformations on data from the 'stg_hubspot__email_event_click_tmp' table. It first creates a base CTE with all columns from the source table. Then, it defines a macro CTE that sets up a structure with NULL values for specific columns. Finally, it creates a fields CTE that casts and renames columns from the macro CTE. The main select statement then retrieves all columns from the fields CTE.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_click_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TEXT) AS browser,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS ip_address,
CAST(NULL AS TEXT) AS location,
CAST(NULL AS TEXT) AS referer,
CAST(NULL AS TEXT) AS url,
CAST(NULL AS TEXT) AS user_agent
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
browser,
id AS event_id,
ip_address,
location AS geo_location,
referer AS referer_url,
url AS click_url,
user_agent
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
browser | text | A JSON object representing the browser which serviced the event. Its comprised of the properties: 'name', 'family', 'producer', 'producer_url', 'type', 'url', 'version'. |
click_url | text | The URL within the message that the recipient clicked. |
event_id | text | The ID of the event. |
geo_location | text | A JSON object representing the location where the event occurred. It's comprised of the properties: 'city', 'state', 'country'. |
ip_address | integer | The contact's IP address when the event occurred. |
referer_url | integer | The URL of the webpage that linked to the URL clicked. Whether this is provided, and what its value is, is determined by the recipient's email client. |
user_agent | text | The user agent responsible for the event, e.g. “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36” |
This SQL query is a basic SELECT statement that retrieves all columns from the 'email_event_click' table in the 'hubspot' schema of the 'TEST' database. The query doesn't perform any filtering, transformation, or aggregation of the data. It's a straightforward extraction of all available data from the specified table.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_click
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
referer | integer | None |
browser | text | None |
location | text | None |
ip_address | integer | None |
url | text | None |
user_agent | text | None |
This SQL query performs a series of transformations on data from the 'stg_hubspot__email_event_deferred_tmp' table. It first creates a CTE with all columns from the source table, then defines a macro CTE with NULL values and specific data types for certain columns. Finally, it selects and renames columns from the macro CTE, casting the '_fivetran_synced' column to TIMESTAMP type. The query essentially creates a standardized structure for the email event deferred data.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_deferred_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS attempt,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS response
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
attempt AS attempt_number,
id AS event_id,
response AS returned_response
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
attempt_number | integer | The delivery attempt number. |
event_id | text | The ID of the event. |
returned_response | integer | The full response from the recipient's email server. |
This SQL query selects all columns from the 'email_event_deferred' table in the 'hubspot' schema of the 'TEST' database. It appears to be a staging query that extracts raw data without any transformations or filters.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_deferred
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
attempt | integer | None |
response | integer | None |
This SQL query performs data type casting and column renaming for the Hubspot email event delivered data. It starts with a base CTE that selects all columns from a temporary staging table. Then, it creates a macro CTE that defines the expected data types for specific columns. Finally, it applies these data type casts and renames some columns in the fields CTE before selecting all resulting columns.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_delivered_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS response,
CAST(NULL AS TEXT) AS smtp_id
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
id AS event_id,
response AS returned_response,
smtp_id
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
event_id | text | The ID of the event. |
returned_response | text | The full response from the recipient's email server. |
smtp_id | text | An ID attached to the message by HubSpot. |
This SQL query selects all columns from the 'email_event_delivered' table in the 'hubspot' schema of the 'TEST' database. The comment suggests that no columns were returned, possibly because the relation doesn't exist yet or all columns were excluded. The query appears to be a placeholder or template, potentially used for dbt compilation and to satisfy SQLFluff requirements.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_delivered
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
response | text | None |
smtp_id | text | None |
This SQL query performs data type casting and column renaming for the 'stg_hubspot__email_event_dropped' model. It starts by selecting all columns from a temporary table, then defines a structure with null values and specific data types. Finally, it casts and renames columns according to the defined structure, preparing the data for further use in the data pipeline.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_dropped_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TEXT) AS bcc,
CAST(NULL AS TEXT) AS cc,
CAST(NULL AS TEXT) AS drop_message,
CAST(NULL AS TEXT) AS drop_reason,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS reply_to,
CAST(NULL AS TEXT) AS subject,
CAST(NULL AS TEXT) AS from_email
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
bcc AS bcc_emails,
cc AS cc_emails,
drop_message,
drop_reason,
from_email, /* source field name = from ; alias declared in macros/get_email_event_dropped_columns.sql */
id AS event_id,
reply_to AS reply_to_email,
subject AS email_subject
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
bcc_emails | text | The 'bcc' field of the email message. |
cc_emails | text | The 'cc' field of the email message. |
drop_message | text | The raw message describing why the email message was dropped. This will usually provide additional details beyond 'dropReason'. |
drop_reason | text | The reason why the email message was dropped. See below for the possible values. |
email_subject | text | The subject line of the email message. |
event_id | text | The ID of the event. |
from_email | text | The 'from' field of the email message. |
reply_to_email | text | The 'reply-to' field of the email message. |
This query selects all columns from the 'email_event_dropped' table in the 'hubspot' schema of the 'TEST' database. The comment suggests that this might be a placeholder query, possibly used during development or compilation of a dbt model, as it mentions that no columns were returned and the star selection is used to keep SQLFluff (a SQL linter) happy.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_dropped
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
drop_reason | text | None |
bcc | text | None |
cc | text | None |
drop_message | text | None |
from | text | None |
reply_to | text | None |
subject | text | None |
This SQL query performs data type casting and column renaming on the 'stg_hubspot__email_event_forward_tmp' table. It creates a base CTE from the source table, then a macro CTE that defines the structure with NULL values, and finally a fields CTE that casts and renames columns. The query then selects all columns from the fields CTE.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_forward_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TEXT) AS browser,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS ip_address,
CAST(NULL AS TEXT) AS location,
CAST(NULL AS TEXT) AS user_agent
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
browser,
id AS event_id,
ip_address,
location AS geo_location,
user_agent
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
browser | text | A JSON object representing the browser which serviced the event. Its comprised of the properties: 'name', 'family', 'producer', 'producer_url', 'type', 'url', 'version'. |
event_id | text | The ID of the event. |
geo_location | text | A JSON object representing the location where the event occurred. It's comprised of the properties: 'city', 'state', 'country'. |
ip_address | integer | The contact's IP address when the event occurred. |
user_agent | text | The user agent responsible for the event, e.g. “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36” |
This SQL query selects all columns from the 'email_event_forward' table in the 'hubspot' schema of the 'TEST' database. The query is likely used as a staging step to prepare data for further processing or analysis in a dbt (data build tool) pipeline.
IntegrationSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_forward
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
browser | text | None |
ip_address | integer | None |
location | text | None |
user_agent | text | None |
This SQL query performs data type casting and column renaming for the Hubspot email event open data. It starts with a base table, creates a macro with null values and specific data types, then applies the actual data type conversions and column renamings in the fields CTE. The query doesn't filter, deduplicate, or aggregate data, but focuses on cleaning and standardizing the data structure.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_open_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TEXT) AS browser,
CAST(NULL AS TEXT) AS duration,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS ip_address,
CAST(NULL AS TEXT) AS location,
CAST(NULL AS TEXT) AS user_agent
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
browser,
duration AS duration_open,
id AS event_id,
ip_address,
location AS geo_location,
user_agent
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
browser | text | A JSON object representing the browser which serviced the event. Its comprised of the properties: 'name', 'family', 'producer', 'producer_url', 'type', 'url', 'version'. |
duration_open | integer | If provided and nonzero, the approximate number of milliseconds the user had opened the email. |
event_id | text | The ID of the event. |
geo_location | text | A JSON object representing the location where the event occurred. It's comprised of the properties: 'city', 'state', 'country'. |
ip_address | integer | The contact's IP address when the event occurred. |
user_agent | text | The user agent responsible for the event, e.g. “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36” |
This SQL query selects all columns from the 'email_event_open' table in the 'hubspot' schema of the 'TEST' database. It appears to be a staging query that extracts raw data without any transformations or filtering.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_open
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
duration | integer | None |
browser | text | None |
ip_address | integer | None |
location | text | None |
user_agent | text | None |
This SQL query performs a series of data transformations on the 'stg_hubspot__email_event_print_tmp' table. It first creates a CTE named 'base' to select all columns from the source table. Then, it defines a 'macro' CTE that establishes the structure and data types for the output. Finally, it creates a 'fields' CTE that casts and renames columns from the 'macro' CTE. The main SELECT statement then retrieves all columns from the 'fields' CTE.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_print_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TEXT) AS browser,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS ip_address,
CAST(NULL AS TEXT) AS location,
CAST(NULL AS TEXT) AS user_agent
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
browser,
id AS event_id,
ip_address,
location AS geo_location,
user_agent
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
browser | text | A JSON object representing the browser which serviced the event. Its comprised of the properties: 'name', 'family', 'producer', 'producer_url', 'type', 'url', 'version'. |
event_id | text | The ID of the event. |
geo_location | text | A JSON object representing the location where the event occurred. It's comprised of the properties: 'city', 'state', 'country'. |
ip_address | integer | The contact's IP address when the event occurred. |
user_agent | text | The user agent responsible for the event, e.g. “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36” |
This SQL query selects all columns from the 'email_event_print' table in the 'hubspot' schema of the 'TEST' database. The comment suggests that no columns were returned, possibly because the relation doesn't exist yet or all columns were excluded. The query is likely a placeholder or template for staging Hubspot email print event data.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_print
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
browser | text | None |
ip_address | integer | None |
location | text | None |
user_agent | text | None |
This SQL query performs data cleaning and transformation on the 'stg_hubspot__email_event_sent' model. It starts with a base CTE that selects all columns from a temporary table. Then, it defines a macro CTE that sets up the structure with NULL values and specific data types. Finally, it applies field transformations, including casting, renaming, and aliasing of columns to prepare the data for further use.
CleaningFeaturizationWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_sent_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TEXT) AS bcc,
CAST(NULL AS TEXT) AS cc,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS reply_to,
CAST(NULL AS TEXT) AS subject,
CAST(NULL AS TEXT) AS from_email
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
bcc AS bcc_emails,
cc AS cc_emails,
from_email, /* source field name = from ; alias declared in macros/get_email_event_sent_columns.sql */
id AS event_id,
reply_to AS reply_to_email,
subject AS email_subject
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
bcc_emails | text | The 'cc' field of the email message. |
cc_emails | text | The 'bcc' field of the email message. |
email_subject | text | The subject line of the email message. |
event_id | text | The ID of the event. |
from_email | text | The 'from' field of the email message. |
reply_to_email | text | The 'reply-to' field of the email message. |
This SQL query selects all columns from the 'email_event_sent' table in the 'hubspot' schema of the 'TEST' database. The comment suggests that no columns were returned, possibly because the relation doesn't exist yet or all columns were excluded. The query appears to be a template or placeholder, potentially used for staging data from HubSpot's email event sent information.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_sent
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
bcc | text | None |
cc | text | None |
from | text | None |
reply_to | text | None |
subject | text | None |
This SQL query performs a data transformation on the 'stg_hubspot__email_event_spam_report_tmp' table. It casts specific columns to appropriate data types and renames the 'id' column to 'event_id'. The query uses a series of CTEs (Common Table Expressions) to structure the transformation process, starting with the raw data, applying a macro for type casting, and then finalizing the field selection and renaming.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_spam_report_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS ip_address,
CAST(NULL AS TEXT) AS user_agent
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
id AS event_id,
ip_address,
user_agent
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
event_id | text | The ID of the event. |
ip_address | integer | The contact's IP address when the event occurred. |
user_agent | integer | The user agent responsible for the event, e.g. “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36” |
This SQL query selects all columns from the 'email_event_spam_report' table in the 'hubspot' schema of the 'TEST' database. It appears to be a staging query that extracts raw data from the source table without any transformations.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_spam_report
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
ip_address | integer | None |
user_agent | integer | None |
This SQL query performs data type casting and column renaming for the Hubspot email event status change data. It starts with a base CTE that selects all columns from a temporary table, then defines a macro CTE with null values and specific data types for each column. Finally, it casts and renames the columns in the fields CTE before selecting all columns from it.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__email_event_status_change_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS BOOLEAN) AS bounced,
CAST(NULL AS TEXT) AS id,
CAST(NULL AS TEXT) AS portal_subscription_status,
CAST(NULL AS TEXT) AS requested_by,
CAST(NULL AS TEXT) AS source,
CAST(NULL AS TEXT) AS subscriptions
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
bounced AS is_bounced,
id AS event_id,
portal_subscription_status AS subscription_status,
requested_by AS requested_by_email,
source AS change_source,
subscriptions
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
change_source | text | The source of the subscription change. |
event_id | text | The ID of the event. |
is_bounced | integer | A HubSpot employee explicitly initiated the status change to block messages to the recipient. (Note this usage has been deprecated in favor of dropping messages with a 'dropReason' of BLOCKED_ADDRESS.) |
requested_by_email | integer | The email address of the person requesting the change on behalf of the recipient. If not applicable, this property is omitted. |
subscription_status | text | The recipient's portal subscription status. Note that if this is 'UNSUBSCRIBED', the property 'subscriptions' is not necessarily an empty array, nor are all subscriptions contained in it necessarily going to have their statuses set to 'UNSUBSCRIBED'.) |
subscriptions | text | An array of JSON objects representing the status of subscriptions for the recipient. Each JSON subscription object is comprised of the properties: 'id', 'status'. |
This SQL query selects all columns from the 'email_event_status_change' table in the 'hubspot' schema of the 'TEST' database. It appears to be a staging query that's part of a dbt (data build tool) model. The comment suggests that this query might be a placeholder or template, possibly used during compilation or for linting purposes with SQLFluff.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event_status_change
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | text | None |
bounced | integer | None |
portal_subscription_status | text | None |
requested_by | integer | None |
source | text | None |
subscriptions | text | None |
This SQL query is a simple SELECT statement that retrieves all columns from the TEST.hubspot.email_event table. The comment suggests that no columns were returned, possibly because the relation doesn't exist yet or all columns were excluded. The query appears to be a placeholder or template, potentially used for dbt compilation purposes or to satisfy SQLFluff requirements.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.email_event
Name | Type | Comment |
---|---|---|
id | text | None |
_fivetran_synced | timestamp without time zone | None |
app_id | integer | None |
caused_by_created | timestamp without time zone | None |
caused_by_id | integer | None |
created | timestamp without time zone | None |
email_campaign_id | integer | None |
obsoleted_by_created | timestamp without time zone | None |
obsoleted_by_id | integer | None |
portal_id | integer | None |
sent_by_created | timestamp without time zone | None |
sent_by_id | text | None |
type | text | None |
filtered_event | boolean | None |
recipient | text | None |
This SQL query performs type casting and column renaming on the 'stg_hubspot__engagement' model. It starts by selecting all columns from a temporary table, then defines a set of columns with specific data types using a CTE named 'macro'. Finally, it selects and renames specific columns from the 'macro' CTE, casting them to the appropriate data types.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS BOOLEAN) AS is_active,
CAST(NULL AS TIMESTAMP) AS created_timestamp,
CAST(NULL AS INT) AS id,
CAST(NULL AS INT) AS owner_id,
CAST(NULL AS INT) AS portal_id,
CAST(NULL AS TIMESTAMP) AS occurred_timestamp,
CAST(NULL AS TEXT) AS engagement_type
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
id AS engagement_id,
created_timestamp,
owner_id,
occurred_timestamp,
portal_id,
engagement_type,
is_active
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
engagement_id | bigint | The ID of the engagement. |
engagement_type | text | One of NOTE, EMAIL, TASK, MEETING, or CALL, the type of the engagement. |
is_active | boolean | Whether the engagement is currently being shown in the UI. PLEASE NOTE - This field will only be populated for pre HubSpot v3 API versions. This field is only included to allow for backwards compatibility between HubSpot API versions. This field will be deprecated in the near future. |
occurred_timestamp | timestamp without time zone | A timestamp in representing the time that the engagement should appear in the timeline. PLEASE NOTE - This field will only be populated for pre HubSpot v3 API versions. This field is only included to allow for backwards compatibility between HubSpot API versions. This field will be deprecated in the near future. |
created_timestamp | timestamp without time zone | This field marks the call's time of creation and determines where the call sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for pre HubSpot v3 API versions. This field is only included to allow for backwards compatibility between HubSpot API versions. This field will be deprecated in the near future. |
owner_id | integer | The ID of the engagement's owner. PLEASE NOTE - This field will only be populated for pre HubSpot v3 API versions. This field is only included to allow for backwards compatibility between HubSpot API versions. This field will be deprecated in the near future. |
portal_id | integer | The hub ID. |
This SQL query creates a staging table for Hubspot engagement call data. It starts by selecting all columns from a temporary table, then creates a new structure with specific data types for each column, casting all values to NULL. This serves as a template or schema definition for the staging table, ensuring consistent data types and structure.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_call_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS BOOLEAN) AS _fivetran_deleted,
CAST(NULL AS INT) AS engagement_id,
CAST(NULL AS TEXT) AS engagement_type,
CAST(NULL AS TIMESTAMP) AS created_timestamp,
CAST(NULL AS TIMESTAMP) AS occurred_timestamp,
CAST(NULL AS INT) AS owner_id,
CAST(NULL AS INT) AS team_id
FROM base
)
SELECT
*
FROM macro
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
engagement_id | bigint | The ID of the engagement. |
_fivetran_deleted | boolean | Boolean to mark rows that were deleted in the source database. |
engagement_type | text | The type of the engagement. |
created_timestamp | timestamp without time zone | This field marks the call's time of creation and determines where the call sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
occurred_timestamp | timestamp without time zone | This field marks the call's time of occurrence and determines where the call sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
owner_id | integer | The ID of the owner associated with the call. This field determines the user listed as the call creator on the record timeline. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
team_id | integer | The ID of the team associated with the call. This field determines the team listed as the call creator on the record timeline. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. |
This SQL query is a simple SELECT statement that retrieves all columns from the 'engagement_call' table in the 'hubspot' schema of the 'TEST' database. The query doesn't perform any specific data manipulation or filtering. The comment suggests that this might be a placeholder or template query, possibly used during compilation or to satisfy a linter (SQLFluff).
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.engagement_call
Name | Type | Comment |
---|---|---|
engagement_id | bigint | None |
_fivetran_deleted | boolean | None |
_fivetran_synced | timestamp without time zone | None |
property_hs_createdate | timestamp without time zone | None |
property_hs_timestamp | timestamp without time zone | None |
type | text | None |
This SQL query creates a template or skeleton for the 'stg_hubspot__engagement_company' model. It selects all columns from a temporary table and then creates a CTE named 'macro' that defines the structure of the final output with three nullable columns: _fivetran_synced (TIMESTAMP), company_id (INT), and engagement_id (INT). The final SELECT statement returns all columns from the 'macro' CTE.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_company_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS company_id,
CAST(NULL AS INT) AS engagement_id
FROM base
)
SELECT
*
FROM macro
Name | Type | Comment |
---|---|---|
_fivetran_synced | text | Timestamp of when Fivetran synced a record. |
company_id | bigint | The ID of the related company. |
engagement_id | bigint | The ID of the related engagement. |
engagement_type | text | None |
type_id | integer | None |
This SQL query selects all columns from the 'engagement_company' table in the 'hubspot' schema of the 'TEST' database. The query is designed to be a staging step, likely used in a dbt (data build tool) project. The comment suggests that the table might not exist yet or all columns were excluded, and the star (*) is used as a placeholder to keep SQLFluff (a SQL linter) happy during dbt compilation.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.engagement_company
Name | Type | Comment |
---|---|---|
company_id | bigint | None |
engagement_id | bigint | None |
engagement_type | text | None |
type_id | integer | None |
_fivetran_synced | text | None |
This SQL query creates a template structure for the 'model.hubspot_source.stg_hubspot__engagement_contact' model. It selects all columns from a temporary table and then defines a macro that casts null values to specific data types for three columns: _fivetran_synced, contact_id, and engagement_id. The final output combines these two CTEs, effectively creating a structure with the desired column types, potentially to be used as a base for further data manipulation or as a placeholder for actual data.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_contact_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS contact_id,
CAST(NULL AS INT) AS engagement_id
FROM base
)
SELECT
*
FROM macro
Name | Type | Comment |
---|---|---|
_fivetran_synced | text | Timestamp of when Fivetran synced a record. |
contact_id | bigint | The ID of the related contact. |
engagement_id | bigint | The ID of the related engagement. |
engagement_type | text | None |
type_id | integer | None |
This SQL query selects all columns from the TEST.hubspot.engagement_contact table. The comment suggests that no columns were returned, possibly because the relation doesn't exist yet or all columns were excluded. The query is likely a placeholder or template for future use.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.engagement_contact
Name | Type | Comment |
---|---|---|
contact_id | bigint | None |
engagement_id | bigint | None |
engagement_type | text | None |
type_id | integer | None |
_fivetran_synced | text | None |
This SQL query creates a base structure for the 'model.hubspot_source.stg_hubspot__engagement_deal' model. It selects all columns from a temporary table and then creates a macro that defines the structure of the final output with three specific columns (_fivetran_synced, deal_id, and engagement_id) cast to their respective data types. The query then selects all columns from this macro.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_deal_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS deal_id,
CAST(NULL AS INT) AS engagement_id
FROM base
)
SELECT
*
FROM macro
Name | Type | Comment |
---|---|---|
_fivetran_synced | text | Timestamp of when Fivetran synced a record. |
deal_id | bigint | The ID of the related contact. |
engagement_id | bigint | The ID of the related engagement. |
engagement_type | text | None |
type_id | integer | None |
This SQL query selects all columns from the engagement_deal table in the TEST.hubspot schema. The comment suggests that this is a placeholder query, possibly used during dbt compilation, and that the actual table or columns might not exist yet.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.engagement_deal
Name | Type | Comment |
---|---|---|
deal_id | bigint | None |
engagement_id | bigint | None |
engagement_type | text | None |
type_id | integer | None |
_fivetran_synced | text | None |
This SQL query creates a temporary structure with null values for specified columns, casting them to appropriate data types. It appears to be setting up a schema or template for the 'stg_hubspot__engagement_email' model, potentially for testing or as a placeholder for future data.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_email_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS BOOLEAN) AS _fivetran_deleted,
CAST(NULL AS TEXT) AS engagement_type,
CAST(NULL AS INT) AS engagement_id,
CAST(NULL AS TIMESTAMP) AS created_timestamp,
CAST(NULL AS TIMESTAMP) AS occurred_timestamp,
CAST(NULL AS INT) AS owner_id,
CAST(NULL AS INT) AS team_id
FROM base
)
SELECT
*
FROM macro
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
_fivetran_deleted | boolean | Boolean to mark rows that were deleted in the source database. |
engagement_id | bigint | The ID of the engagement. |
engagement_type | text | The type of the engagement. |
created_timestamp | timestamp without time zone | This field marks the email's time of creation and determines where the email sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
occurred_timestamp | timestamp without time zone | This field marks the email's time of occurrence and determines where the email sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
owner_id | integer | The ID of the owner associated with the email. This field determines the user listed as the email creator on the record timeline. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
team_id | integer | The ID of the team associated with the email. This field determines the team listed as the email creator on the record timeline. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. |
all_owner_ids | integer | None |
all_team_ids | integer | None |
email_subject | text | None |
email_text | text | None |
lastmodifieddate | text | None |
modified_by | integer | None |
This SQL query selects all columns from the 'engagement_email' table in the 'hubspot' schema of the 'TEST' database. The query is designed as a staging step, likely to be used as an intermediate table in a larger data transformation process. The comment suggests that this query might be a placeholder or template, possibly used during compilation or linting processes.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.engagement_email
Name | Type | Comment |
---|---|---|
engagement_id | bigint | None |
_fivetran_deleted | boolean | None |
_fivetran_synced | timestamp without time zone | None |
property_hs_all_owner_ids | integer | None |
property_hs_all_team_ids | integer | None |
property_hs_createdate | timestamp without time zone | None |
property_hs_email_subject | text | None |
property_hs_email_text | text | None |
property_hs_lastmodifieddate | text | None |
property_hs_modified_by | integer | None |
property_hs_timestamp | timestamp without time zone | None |
property_hubspot_owner_id | integer | None |
property_hubspot_team_id | integer | None |
type | text | None |
This SQL query creates a CTE named 'base' that selects all columns from a temporary staging table. It then creates another CTE named 'macro' that defines a structure with null values for specific columns, casting them to appropriate data types. The final SELECT statement returns all columns from the 'macro' CTE. This query appears to be setting up a standardized structure for the 'stg_hubspot__engagement_meeting' model, possibly for further processing or as a template.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_meeting_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS BOOLEAN) AS _fivetran_deleted,
CAST(NULL AS TEXT) AS engagement_type,
CAST(NULL AS INT) AS engagement_id,
CAST(NULL AS TIMESTAMP) AS created_timestamp,
CAST(NULL AS TIMESTAMP) AS occurred_timestamp,
CAST(NULL AS INT) AS owner_id,
CAST(NULL AS INT) AS team_id
FROM base
)
SELECT
*
FROM macro
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
_fivetran_deleted | boolean | Boolean to mark rows that were deleted in the source database. |
engagement_id | bigint | The ID of the engagement. |
engagement_type | text | The type of the engagement. |
created_timestamp | timestamp without time zone | This field marks the meeting's time of creation and determines where the meeting sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
occurred_timestamp | timestamp without time zone | This field marks the meeting's time of occurrence and determines where the meeting sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
owner_id | integer | The ID of the owner associated with the meeting. This field determines the user listed as the meeting creator on the record timeline. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
team_id | integer | The ID of the team associated with the meeting. This field determines the team listed as the meeting creator on the record timeline. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. |
created_from_link_id | integer | None |
end_time | text | None |
pre_meeting_prospect_reminders | text | None |
source | text | None |
source_id | text | None |
start_time | text | None |
web_conference_meeting_id | integer | None |
meeting_outcome | integer | None |
body | text | None |
external_url | text | None |
title | text | None |
This query selects all columns from the 'engagement_meeting' table in the 'hubspot' schema of the 'TEST' database. It appears to be a staging query that retrieves raw data without any transformations or filtering.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.engagement_meeting
Name | Type | Comment |
---|---|---|
engagement_id | bigint | None |
_fivetran_synced | timestamp without time zone | None |
created_from_link_id | integer | None |
end_time | text | None |
pre_meeting_prospect_reminders | text | None |
source | text | None |
source_id | text | None |
start_time | text | None |
web_conference_meeting_id | integer | None |
meeting_outcome | integer | None |
body | text | None |
external_url | text | None |
title | text | None |
This SQL query creates a template structure for the 'stg_hubspot__engagement_note' model. It selects all columns from a temporary table and then defines a set of columns with specific data types but null values. The purpose seems to be to establish a consistent schema for the engagement note data, possibly for further processing or as a placeholder for actual data to be inserted later.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_note_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS BOOLEAN) AS _fivetran_deleted,
CAST(NULL AS TEXT) AS note,
CAST(NULL AS TEXT) AS engagement_type,
CAST(NULL AS INT) AS engagement_id,
CAST(NULL AS TIMESTAMP) AS created_timestamp,
CAST(NULL AS TIMESTAMP) AS occurred_timestamp,
CAST(NULL AS INT) AS owner_id,
CAST(NULL AS INT) AS team_id
FROM base
)
SELECT
*
FROM macro
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
_fivetran_deleted | boolean | Boolean to mark rows that were deleted in the source database. |
engagement_id | bigint | The ID of the engagement. |
engagement_type | text | The type of the engagement. |
note | text | The body of the note. The body has a limit of 65536 characters. |
created_timestamp | timestamp without time zone | This field marks the note's time of creation and determines where the note sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
occurred_timestamp | timestamp without time zone | This field marks the note's time of occurrence and determines where the note sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
owner_id | integer | The ID of the owner associated with the note. This field determines the user listed as the note creator on the record timeline. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
team_id | integer | The ID of the team associated with the note. This field determines the team listed as the note creator on the record timeline. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. |
body_preview | text | None |
lastmodifieddate | text | None |
note_body | text | None |
This SQL query selects all columns from the 'engagement_note' table in the 'hubspot' schema of the 'TEST' database. The query is designed as a staging step, likely to prepare data for further transformation or analysis in a data modeling process.
IntegrationSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.engagement_note
Name | Type | Comment |
---|---|---|
engagement_id | bigint | None |
_fivetran_deleted | boolean | None |
_fivetran_synced | timestamp without time zone | None |
property_hs_body_preview | text | None |
property_hs_createdate | timestamp without time zone | None |
property_hs_lastmodifieddate | text | None |
property_hs_note_body | text | None |
property_hs_timestamp | timestamp without time zone | None |
property_hubspot_owner_id | integer | None |
property_hubspot_team_id | integer | None |
type | text | None |
This SQL query creates a staging table for Hubspot engagement tasks. It selects all columns from a temporary table and then casts specific columns to defined data types, including setting some to NULL. This appears to be a data type standardization step in an ETL process.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__engagement_task_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS BOOLEAN) AS _fivetran_deleted,
CAST(NULL AS INT) AS engagement_id,
CAST(NULL AS TEXT) AS engagement_type,
CAST(NULL AS TIMESTAMP) AS created_timestamp,
CAST(NULL AS TIMESTAMP) AS occurred_timestamp,
CAST(NULL AS INT) AS owner_id,
CAST(NULL AS INT) AS team_id
FROM base
)
SELECT
*
FROM macro
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
_fivetran_deleted | boolean | Boolean to mark rows that were deleted in the source database. |
engagement_id | bigint | The ID of the engagement. |
engagement_type | text | The type of the engagement. |
created_timestamp | timestamp without time zone | This field marks the task's time of creation and determines where the task sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
occurred_timestamp | timestamp without time zone | This field marks the task's time of occurrence and determines where the task sits on the record timeline. You can use either a Unix timestamp in milliseconds or UTC format. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
owner_id | integer | The ID of the owner associated with the task. This field determines the user listed as the task creator on the record timeline. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. For the pre HubSpot v3 versions, this value may be found within the parent `engagement` table. |
team_id | integer | The ID of the team associated with the task. This field determines the team listed as the task creator on the record timeline. PLEASE NOTE: This field will only be populated for connectors utilizing the HubSpot v3 API version. |
task_type | text | None |
object_id | bigint | None |
engagement_source | text | None |
This SQL query selects all columns from the 'engagement_task' table in the 'hubspot' schema of the 'TEST' database. The query is designed as a staging step, likely part of a dbt (data build tool) project, to create a temporary table that mirrors the source data without any transformations.
IntegrationSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.engagement_task
Name | Type | Comment |
---|---|---|
engagement_id | bigint | None |
_fivetran_deleted | boolean | None |
_fivetran_synced | timestamp without time zone | None |
property_hs_createdate | timestamp without time zone | None |
property_hs_object_id | bigint | None |
property_hs_task_type | text | None |
property_hs_timestamp | timestamp without time zone | None |
property_hubspot_owner_id | integer | None |
property_hubspot_team_id | integer | None |
type | text | None |
task_type | text | None |
property_hs_engagement_source | text | None |
This SQL query is a simple select statement that retrieves all columns from the 'TEST.hubspot.engagement' table. The comment suggests that this is a placeholder query, possibly used during the dbt compile process, and that the actual table or columns may not exist yet.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.engagement
Name | Type | Comment |
---|---|---|
id | bigint | None |
type | text | None |
_fivetran_synced | text | None |
portal_id | integer | None |
This SQL query performs data cleaning and featurization on the 'stg_hubspot__owner' table. It casts several columns to specific data types, renames some columns, and creates a new 'full_name' column by concatenating and trimming the first and last names. The query also sets up a structure to handle potentially missing columns by using a CTE with NULL values.
CleaningFeaturizationWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__owner_tmp
), macro AS (
SELECT
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS TIMESTAMP) AS created_at,
CAST(NULL AS TEXT) AS email,
CAST(NULL AS TEXT) AS first_name,
CAST(NULL AS TEXT) AS last_name,
CAST(NULL AS INT) AS owner_id,
CAST(NULL AS INT) AS portal_id,
CAST(NULL AS TEXT) AS type,
CAST(NULL AS TIMESTAMP) AS updated_at
FROM base
), fields AS (
SELECT
CAST(_fivetran_synced AS TIMESTAMP) AS _fivetran_synced,
CAST(created_at AS TIMESTAMP) AS created_timestamp,
email AS email_address,
first_name,
last_name,
owner_id,
portal_id,
type AS owner_type,
CAST(updated_at AS TIMESTAMP) AS updated_timestamp,
TRIM(first_name || ' ' || last_name) AS full_name
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | timestamp without time zone | Timestamp of when Fivetran synced a record. |
created_timestamp | timestamp without time zone | A timestamp for when the owner was created. |
email_address | text | The email address of the owner. |
first_name | text | The first name of the owner. |
full_name | text | Full name of the owner. |
last_name | text | The last name of the owner. |
owner_id | bigint | The ID of the owner. |
portal_id | integer | The hub ID. |
owner_type | text | The type of owner. |
updated_timestamp | timestamp without time zone | A timestamp for when the owner was last updated. |
This SQL query selects all columns from the 'owner' table in the 'hubspot' schema of the 'TEST' database. The query is likely intended to be a staging step for further data processing or analysis of HubSpot owner data. The comment suggests that the table might not exist yet or all columns were excluded, implying this could be a placeholder or template query.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.owner
Name | Type | Comment |
---|---|---|
owner_id | bigint | None |
_fivetran_synced | text | None |
created_at | text | None |
portal_id | integer | None |
type | text | None |
updated_at | text | None |
text | None | |
first_name | text | None |
last_name | text | None |
This SQL query performs a series of transformations on the 'stg_hubspot__property_tmp' table. It first creates a base CTE with all columns from the source table. Then, it defines a macro CTE that casts all columns to specific data types, effectively creating a schema. Finally, it selects and renames certain columns in the fields CTE. The query primarily focuses on data type standardization and column renaming.
CleaningWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__property_tmp
), macro AS (
SELECT
CAST(NULL AS TEXT) AS _fivetran_id,
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS BOOLEAN) AS calculated,
CAST(NULL AS TIMESTAMP) AS created_at,
CAST(NULL AS TEXT) AS description,
CAST(NULL AS TEXT) AS field_type,
CAST(NULL AS TEXT) AS group_name,
CAST(NULL AS BOOLEAN) AS hubspot_defined,
CAST(NULL AS TEXT) AS hubspot_object,
CAST(NULL AS TEXT) AS label,
CAST(NULL AS TEXT) AS name,
CAST(NULL AS BOOLEAN) AS show_currency_symbol,
CAST(NULL AS TEXT) AS type,
CAST(NULL AS TIMESTAMP) AS updated_at
FROM base
), fields AS (
SELECT
_fivetran_id,
_fivetran_synced,
calculated,
created_at,
description,
field_type,
group_name,
hubspot_defined,
hubspot_object,
label AS property_label,
name AS property_name,
type AS property_type,
updated_at
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_id | text | Fivetran generated id. Joins to `property_id` in the `property_option` table. |
_fivetran_synced | text | Timestamp of when Fivetran synced a record. |
calculated | boolean | Indicates if the property is calculated by a HubSpot process |
created_at | text | Timestamp representing when the property was created. |
description | text | A description of the property. |
field_type | text | One of textarea, text, date, file, number, select, radio, checkbox, or booleancheckbox. |
group_name | text | The name of the property group that the property belongs to. |
hubspot_defined | boolean | This will be true for default properties that are built into HubSpot. |
hubspot_object | text | If this property is related to other objects, the object will be listed here. |
property_label | text | A human readable label for the property. |
property_name | text | The internal name of the property. |
property_type | text | One of string, number, date, datetime, or enumeration. |
updated_at | text | Timestamp representing when the property was last updated. |
This SQL query appears to be a staging query that prepares data from a source table for further use. It creates a CTE structure with three parts: 'base' which selects all data from a source table, 'macro' which defines a structure with NULL values for specific columns, and 'fields' which renames some columns. The final SELECT statement returns all columns from the 'fields' CTE.
CleaningOtherWITH base AS (
SELECT
*
FROM TEST.PUBLIC_stg_hubspot.stg_hubspot__property_option_tmp
), macro AS (
SELECT
CAST(NULL AS TEXT) AS label,
CAST(NULL AS TEXT) AS property_id,
CAST(NULL AS TIMESTAMP) AS _fivetran_synced,
CAST(NULL AS INT) AS display_order,
CAST(NULL AS BOOLEAN) AS hidden,
CAST(NULL AS TEXT) AS value
FROM base
), fields AS (
SELECT
label AS property_option_label,
property_id,
_fivetran_synced,
display_order,
hidden,
value AS property_option_value
FROM macro
)
SELECT
*
FROM fields
Name | Type | Comment |
---|---|---|
_fivetran_synced | text | Timestamp of when Fivetran synced a record. |
property_option_label | text | The label of the option displayed inside the HubSpot app. |
property_id | text | The ID of the related property. |
display_order | integer | Order of options displayed in Hubspot, starting with the lowest positive integer value. Values of -1 will cause the option to be displayed after any positive values. |
hidden | boolean | Boolean if the option will be displayed in HubSpot |
property_option_value | text | The internal value of the option. |
This SQL query selects all columns from the 'property_option' table in the 'hubspot' schema of the 'TEST' database. The query is designed to be a staging step, likely part of a dbt (data build tool) project, to prepare data for further transformation or analysis. The comment suggests that this query might be used as a placeholder or template, especially during the compilation phase of dbt, and it's structured to be compatible with SQLFluff, a SQL linter.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.property_option
Name | Type | Comment |
---|---|---|
label | text | None |
property_id | text | None |
_fivetran_synced | text | None |
display_order | integer | None |
hidden | boolean | None |
value | text | None |
This SQL query is designed to select all columns from the 'property' table in the 'hubspot' schema of the 'TEST' database. However, the comment suggests that no columns were returned, possibly because the relation doesn't exist yet or all columns were excluded. The query appears to be a placeholder or template, potentially used in a dbt (data build tool) project, to maintain structure and satisfy SQLFluff linting requirements during compilation.
OtherSELECT
*
/* No columns were returned. Maybe the relation doesn't exist yet
or all columns were excluded. This star is only output during
dbt compile, and exists to keep SQLFluff happy. */
FROM TEST.hubspot.property
Name | Type | Comment |
---|---|---|
_fivetran_id | text | None |
_fivetran_synced | text | None |
calculated | boolean | None |
created_at | text | None |
description | text | None |
field_type | text | None |
group_name | text | None |
hubspot_defined | boolean | None |
hubspot_object | text | None |
label | text | None |
name | text | None |
show_currency_symbol | boolean | None |
type | text | None |
updated_at | text | None |