-
Notifications
You must be signed in to change notification settings - Fork 7
FivetranAI: Unified RAG working branch #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
levonkorganyan
wants to merge
28
commits into
main
Choose a base branch
from
add-hubspot-company-document2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
46ff35b
beginning to add new company object
levonkorganyan 0ae873d
added working company document
levonkorganyan cd24a99
remove unnecessary changes
levonkorganyan f08fa62
Merge branch 'main' into add-hubspot-company-document2
levonkorganyan 3686c1d
make it a left join for Deal
levonkorganyan 17e782b
fix bug and add owners to Deal
levonkorganyan ad59523
enable on flag
abhijeethp 886e9a1
add company ids to deal documents
levonkorganyan 4cbff83
more iteration
levonkorganyan 6514a72
fix json macro bug
levonkorganyan ab87a84
concat into json list
levonkorganyan 121163d
try to fix json macro
levonkorganyan 4128792
remove comment
levonkorganyan 919f7a1
add companies to deals
levonkorganyan 999f9c0
add company name
levonkorganyan 400f24d
fix query
levonkorganyan fe957ad
Add team to hubspot model
abhijeethp 2c7d8cb
Update stg_rag_hubspot__team.sql
abhijeethp 2cecd02
Add Issue Key to Jira model
abhijeethp ab53cac
add engagement model
levonkorganyan 7771b7e
add(hubspot): Ticket object
levonkorganyan 9d57d16
stuff
abhijeethp 8e0f0c9
remove double negative
abhijeethp 0a11784
make deal data option in company interm object.
abhijeethp 4a6db31
disable rag__unified_document
abhijeethp 1a543f4
nit fix
abhijeethp 78a0fb7
Merge pull request #27 from fivetran/hubspot_exclude_deals
abhijeethp 2ed9541
make ticket objects optional
abhijeethp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
macros/staging/hubspot/get_hubspot_deal_company_columns.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| {% macro get_hubspot_deal_company_columns() %} | ||
|
|
||
| {% set columns = [ | ||
| {"name": "_fivetran_synced", "datatype": dbt.type_timestamp()}, | ||
| {"name": "deal_id", "datatype": dbt.type_int()}, | ||
| {"name": "company_id", "datatype": dbt.type_int()} | ||
| ] %} | ||
|
|
||
| {{ return(columns) }} | ||
|
|
||
| {% endmacro %} |
78 changes: 78 additions & 0 deletions
78
models/intermediate/hubspot/int_rag_hubspot__company_document.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| WITH owners AS ( | ||
| SELECT | ||
| *, | ||
| COALESCE( | ||
| owner_email, | ||
| 'UNKNOWN' | ||
| ) AS safe_email, | ||
| COALESCE( | ||
| first_name, | ||
| '' | ||
| ) AS safe_first_name, | ||
| COALESCE( | ||
| last_name, | ||
| '' | ||
| ) AS safe_last_name | ||
| FROM | ||
| {{ ref('stg_rag_hubspot__owner') }} | ||
| ), | ||
| deals AS ( | ||
| SELECT | ||
| *, | ||
| COALESCE({{ cast('closed_date', dbt.type_string()) }}, 'not closed yet') AS safe_close_date | ||
| FROM | ||
| {{ ref('stg_rag_hubspot__deal') }} | ||
| ), | ||
| company AS ( | ||
| SELECT | ||
| * | ||
| FROM | ||
| {{ ref('stg_rag_hubspot__company') }} | ||
| ), | ||
| deal_company AS ( | ||
| SELECT | ||
| * | ||
| FROM | ||
| {{ ref('stg_rag_hubspot__deal_company') }} | ||
| ), | ||
| deal_descriptions AS ( | ||
| SELECT | ||
| DISTINCT deals.deal_id, | ||
| deals.source_relation, | ||
| {{ dbt.concat([ "' - {'", "'deal_name: '", "deals.title", "' // '", "'deal_owner_name: '", "owners.safe_first_name", "' '", "owners.safe_last_name", "' // '", "'deal_owner_email: '", "owners.safe_email", "' // '", "'deal_closed_date: '", "deals.safe_close_date", "'}'" ]) }} AS deal_description, | ||
| deals.closed_date | ||
| FROM | ||
| deals | ||
| JOIN owners | ||
| ON owners.owner_id = deals.owner_id | ||
| AND owners.source_relation = deals.source_relation | ||
| ), | ||
| company_with_deal_description AS ( | ||
| SELECT | ||
| company.company_id AS company_id, | ||
| company.source_relation AS source_relation, | ||
| {{ dbt.listagg( | ||
| measure = "dd.deal_description", | ||
| delimiter_text = "'\\n'", | ||
| order_by_clause = "order by dd.closed_date" | ||
| ) }} AS deal_descriptions | ||
| FROM | ||
| company | ||
| LEFT JOIN deal_company dc | ||
| ON dc.company_id = company.company_id | ||
| AND dc.source_relation = company.source_relation | ||
| LEFT JOIN deal_descriptions dd | ||
| ON dd.deal_id = dc.deal_id | ||
| AND dc.source_relation = dd.source_relation | ||
| GROUP BY | ||
| 1, | ||
| 2 | ||
| ) | ||
| SELECT | ||
| cdd.deal_descriptions AS deals, | ||
| company.* | ||
| FROM | ||
| company | ||
| JOIN company_with_deal_description cdd | ||
| ON cdd.company_id = company.company_id | ||
| AND cdd.source_relation = company.source_relation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 29 additions & 59 deletions
88
models/staging/hubspot_staging/stg_rag_hubspot__company.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,29 @@ | ||
| {{ config(enabled=var('rag__using_hubspot', True)) }} | ||
|
|
||
| with base as ( | ||
|
|
||
| {{ | ||
| fivetran_utils.union_data( | ||
| table_identifier='company', | ||
| database_variable='rag_hubspot_database', | ||
| schema_variable='rag_hubspot_schema', | ||
| default_database=target.database, | ||
| default_schema='rag_hubspot', | ||
| default_variable='hubspot_company', | ||
| union_schema_variable='rag_hubspot_union_schemas', | ||
| union_database_variable='rag_hubspot_union_databases' | ||
| ) | ||
| }} | ||
| ), | ||
|
|
||
| fields as ( | ||
|
|
||
| select | ||
| {{ | ||
| fivetran_utils.fill_staging_columns( | ||
| source_columns=adapter.get_columns_in_relation(source('rag_hubspot','company')), | ||
| staging_columns=get_hubspot_company_columns() | ||
| ) | ||
| }} | ||
|
|
||
| {{ fivetran_utils.source_relation( | ||
| union_schema_variable='rag_hubspot_union_schemas', | ||
| union_database_variable='rag_hubspot_union_databases') | ||
| }} | ||
| from base | ||
| ), | ||
|
|
||
| final as ( | ||
|
|
||
| select | ||
| company_id, | ||
| source_relation, | ||
| is_company_deleted, | ||
| cast(_fivetran_synced as {{ dbt.type_timestamp() }}) as _fivetran_synced, | ||
| company_name, | ||
| description, | ||
| created_date, | ||
| industry, | ||
| street_address, | ||
| street_address_2, | ||
| city, | ||
| state, | ||
| country, | ||
| company_annual_revenue | ||
|
|
||
| from fields | ||
|
|
||
| ) | ||
|
|
||
| select * | ||
| from final | ||
| {{ config(enabled = var('rag__using_hubspot', True)) }} | ||
|
|
||
| WITH FINAL AS ( | ||
|
|
||
| SELECT | ||
| {{ dbt_utils.star( | ||
| from = ref('stg_rag_hubspot__company_fields'), | ||
| except = ['id', '_fivetran_synced', 'is_deleted', 'property_name', 'property_description', 'property_createdate', 'property_industry', 'property_address', 'property_address_2', 'property_city', 'property_state', 'property_country', 'property_annualrevenue' ] | ||
| ) }}, | ||
| id AS company_id, | ||
| CAST(_fivetran_synced AS {{ dbt.type_timestamp() }}) AS _fivetran_synced, | ||
| is_deleted AS is_company_deleted, | ||
| property_name AS company_name, | ||
| property_description AS description, | ||
| property_createdate AS created_date, | ||
| property_industry AS industry, | ||
| property_address AS street_address, | ||
| property_address_2 AS street_address_2, | ||
| property_city AS city, | ||
| property_state AS state, | ||
| property_country AS country, | ||
| property_annualrevenue AS company_annual_revenue | ||
| FROM | ||
| {{ ref('stg_rag_hubspot__company_fields') }} | ||
| ) | ||
| SELECT | ||
| * | ||
| FROM | ||
| FINAL |
30 changes: 30 additions & 0 deletions
30
models/staging/hubspot_staging/stg_rag_hubspot__company_fields.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| {{ config(enabled=var('rag__using_hubspot', True)) }} | ||
|
|
||
| with base as ( | ||
|
|
||
| {{ | ||
| fivetran_utils.union_data( | ||
| table_identifier='company', | ||
| database_variable='rag_hubspot_database', | ||
| schema_variable='rag_hubspot_schema', | ||
| default_database=target.database, | ||
| default_schema='rag_hubspot', | ||
| default_variable='hubspot_company', | ||
| union_schema_variable='rag_hubspot_union_schemas', | ||
| union_database_variable='rag_hubspot_union_databases' | ||
| ) | ||
| }} | ||
| ), | ||
|
|
||
| fields as ( | ||
|
|
||
| select | ||
| * | ||
| {{ fivetran_utils.source_relation( | ||
| union_schema_variable='rag_hubspot_union_schemas', | ||
| union_database_variable='rag_hubspot_union_databases') | ||
| }} | ||
| from base | ||
| ) | ||
|
|
||
| select * from fields |
46 changes: 46 additions & 0 deletions
46
models/staging/hubspot_staging/stg_rag_hubspot__deal_company.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| {{ config(enabled=var('rag__using_hubspot', True)) }} | ||
|
|
||
| with base as ( | ||
|
|
||
| {{ | ||
| fivetran_utils.union_data( | ||
| table_identifier='deal_company', | ||
| database_variable='rag_hubspot_database', | ||
| schema_variable='rag_hubspot_schema', | ||
| default_database=target.database, | ||
| default_schema='rag_hubspot', | ||
| default_variable='hubspot_deal_company', | ||
| union_schema_variable='rag_hubspot_union_schemas', | ||
| union_database_variable='rag_hubspot_union_databases' | ||
| ) | ||
| }} | ||
| ), | ||
|
|
||
| fields as ( | ||
|
|
||
| select | ||
| {{ | ||
| fivetran_utils.fill_staging_columns( | ||
| source_columns=adapter.get_columns_in_relation(source('rag_hubspot','deal_company')), | ||
| staging_columns=get_hubspot_deal_company_columns() | ||
| ) | ||
| }} | ||
|
|
||
| {{ fivetran_utils.source_relation( | ||
| union_schema_variable='rag_hubspot_union_schemas', | ||
| union_database_variable='rag_hubspot_union_databases') | ||
| }} | ||
| from base | ||
| ), | ||
|
|
||
| final as ( | ||
|
|
||
| select | ||
| deal_id, | ||
| company_id, | ||
| source_relation | ||
| from fields | ||
| ) | ||
|
|
||
| select * | ||
| from final |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an apparent bug fix. Submitted a separate PR for this as well.