add sync b rands

This commit is contained in:
Ubuntu 2022-05-27 21:47:46 +07:00
parent 25bf52e4c0
commit c5c4d4cfcc
8 changed files with 117 additions and 3 deletions

View File

@ -6,5 +6,5 @@ push:
run: run:
dbt deps --profiles-dir=. --project-dir=. dbt deps --profiles-dir=. --project-dir=.
#dbt run --profiles-dir=. --project-dir=. --full-refresh #dbt run --profiles-dir=. --project-dir=. --full-refresh
dbt run --profiles-dir=. --project-dir=. --full-refresh --select product_sku dbt run --profiles-dir=. --project-dir=. --full-refresh --select brands

View File

@ -53,6 +53,10 @@ vars:
admin_tags_ab2: unibag._airbyte_raw_admin_tags admin_tags_ab2: unibag._airbyte_raw_admin_tags
admin_tags_ab3: unibag._airbyte_raw_admin_tags admin_tags_ab3: unibag._airbyte_raw_admin_tags
admin_tags: unibag._airbyte_raw_admin_tags admin_tags: unibag._airbyte_raw_admin_tags
brands_ab1: unibag._airbyte_raw_brands
brands_ab2: unibag._airbyte_raw_brands
brands_ab3: unibag._airbyte_raw_brands
brands: unibag._airbyte_raw_brands
cash_flows_ab1: unibag._airbyte_raw_cash_flows cash_flows_ab1: unibag._airbyte_raw_cash_flows
cash_flows_ab2: unibag._airbyte_raw_cash_flows cash_flows_ab2: unibag._airbyte_raw_cash_flows
cash_flows_ab3: unibag._airbyte_raw_cash_flows cash_flows_ab3: unibag._airbyte_raw_cash_flows
@ -192,4 +196,4 @@ vars:
wards_ab1: unibag._airbyte_raw_wards wards_ab1: unibag._airbyte_raw_wards
wards_ab2: unibag._airbyte_raw_wards wards_ab2: unibag._airbyte_raw_wards
wards_ab3: unibag._airbyte_raw_wards wards_ab3: unibag._airbyte_raw_wards
wards: unibag._airbyte_raw_wards wards: unibag._airbyte_raw_wards

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,28 @@
{{ config(
indexes = [{'columns':['_airbyte_emitted_at'],'type':'btree'}],
unique_key = '_airbyte_ab_id',
schema = "_airbyte_unibag",
tags = [ "top-level-intermediate" ]
) }}
-- SQL model to parse JSON blob stored in a single column and extract into separated field columns as described by the JSON Schema
-- depends_on: {{ source('unibag', '_airbyte_raw_brands') }}
select
{{ json_extract_scalar('_airbyte_data', ['_id'], ['_id']) }} as _id,
{{ json_extract_scalar('_airbyte_data', ['desc'], ['desc']) }} as {{ adapter.quote('desc') }},
{{ json_extract_scalar('_airbyte_data', ['logo'], ['logo']) }} as logo,
{{ json_extract_scalar('_airbyte_data', ['name'], ['name']) }} as {{ adapter.quote('name') }},
{{ json_extract_scalar('_airbyte_data', ['slug'], ['slug']) }} as slug,
{{ json_extract_scalar('_airbyte_data', ['active'], ['active']) }} as active,
{{ json_extract_array('_airbyte_data', ['photos'], ['photos']) }} as photos,
{{ json_extract_scalar('_airbyte_data', ['country'], ['country']) }} as country,
{{ json_extract_scalar('_airbyte_data', ['createdAt'], ['createdAt']) }} as createdat,
{{ json_extract_scalar('_airbyte_data', ['updatedAt'], ['updatedAt']) }} as updatedat,
{{ json_extract_scalar('_airbyte_data', ['searchString'], ['searchString']) }} as searchstring,
{{ json_extract_scalar('_airbyte_data', ['totalProduct'], ['totalProduct']) }} as totalproduct,
_airbyte_ab_id,
_airbyte_emitted_at,
{{ current_timestamp() }} as _airbyte_normalized_at
from {{ source('unibag', '_airbyte_raw_brands') }} as table_alias
-- brands
where 1 = 1

View File

@ -0,0 +1,28 @@
{{ config(
indexes = [{'columns':['_airbyte_emitted_at'],'type':'btree'}],
unique_key = '_airbyte_ab_id',
schema = "_airbyte_unibag",
tags = [ "top-level-intermediate" ]
) }}
-- SQL model to cast each column to its adequate SQL type converted from the JSON schema type
-- depends_on: {{ ref('brands_ab1') }}
select
cast(_id as {{ dbt_utils.type_string() }}) as _id,
cast({{ adapter.quote('desc') }} as {{ dbt_utils.type_string() }}) as {{ adapter.quote('desc') }},
cast(logo as {{ dbt_utils.type_string() }}) as logo,
cast({{ adapter.quote('name') }} as {{ dbt_utils.type_string() }}) as {{ adapter.quote('name') }},
cast(slug as {{ dbt_utils.type_string() }}) as slug,
{{ cast_to_boolean('active') }} as active,
photos,
cast(country as {{ dbt_utils.type_string() }}) as country,
cast(createdat as {{ dbt_utils.type_string() }}) as createdat,
cast(updatedat as {{ dbt_utils.type_string() }}) as updatedat,
cast(searchstring as {{ dbt_utils.type_string() }}) as searchstring,
cast(totalproduct as {{ dbt_utils.type_float() }}) as totalproduct,
_airbyte_ab_id,
_airbyte_emitted_at,
{{ current_timestamp() }} as _airbyte_normalized_at
from {{ ref('brands_ab1') }}
-- brands
where 1 = 1

View File

@ -0,0 +1,28 @@
{{ config(
indexes = [{'columns':['_airbyte_emitted_at'],'type':'btree'}],
unique_key = '_airbyte_ab_id',
schema = "_airbyte_unibag",
tags = [ "top-level-intermediate" ]
) }}
-- SQL model to build a hash column based on the values of this record
-- depends_on: {{ ref('brands_ab2') }}
select
{{ dbt_utils.surrogate_key([
'_id',
adapter.quote('desc'),
'logo',
adapter.quote('name'),
'slug',
boolean_to_string('active'),
array_to_string('photos'),
'country',
'createdat',
'updatedat',
'searchstring',
'totalproduct',
]) }} as _airbyte_brands_hashid,
tmp.*
from {{ ref('brands_ab2') }} tmp
-- brands
where 1 = 1

View File

@ -0,0 +1,25 @@
{{ config(
indexes = [{'columns':['_airbyte_emitted_at'],'type':'btree'}],
unique_key = '_airbyte_ab_id',
schema = "unibag",
tags = [ "top-level" ]
) }}
-- Final base SQL model
-- depends_on: {{ ref('brands_ab3') }}
select
_id,
{{ adapter.quote('name') }},
active,
{{ adapter.quote('country') }}::json->>'name' AS country_name,
{{ adapter.quote('country') }}::json->>'code' AS country_code,
createdat::timestamp AS created_at,
updatedat::timestamp AS updated_at,
COALESCE(cast(totalproduct AS integer), 0) AS total_product,
_airbyte_ab_id,
_airbyte_emitted_at,
{{ current_timestamp() }} as _airbyte_normalized_at,
_airbyte_brands_hashid
from {{ ref('brands_ab3') }}
-- brands from {{ source('unibag', '_airbyte_raw_brands') }}
where 1 = 1

View File

@ -7,6 +7,7 @@ sources:
identifier: false identifier: false
tables: tables:
- name: _airbyte_raw_admin_tags - name: _airbyte_raw_admin_tags
- name: _airbyte_raw_brands
- name: _airbyte_raw_cash_flows - name: _airbyte_raw_cash_flows
- name: _airbyte_raw_cities - name: _airbyte_raw_cities
- name: _airbyte_raw_customers - name: _airbyte_raw_customers