From f6af10b64d82fa267b2d4df24bd83c0b67404766 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 11 May 2022 16:47:34 +0700 Subject: [PATCH] update --- Makefile | 2 +- .../unibag/session_deliveries_ab1.sql | 31 +++++++++++++++++ .../unibag/session_deliveries_ab2.sql | 31 +++++++++++++++++ .../unibag/session_deliveries_ab3.sql | 31 +++++++++++++++++ .../airbyte_tables/unibag/product_sku.sql | 3 +- .../unibag/session_deliveries.sql | 34 +++++++++++++++++++ 6 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 models/generated/airbyte_ctes/unibag/session_deliveries_ab1.sql create mode 100644 models/generated/airbyte_ctes/unibag/session_deliveries_ab2.sql create mode 100644 models/generated/airbyte_ctes/unibag/session_deliveries_ab3.sql create mode 100644 models/generated/airbyte_tables/unibag/session_deliveries.sql diff --git a/Makefile b/Makefile index 613db74..737caa6 100644 --- a/Makefile +++ b/Makefile @@ -6,5 +6,5 @@ push: run: dbt deps --profiles-dir=. --project-dir=. #dbt run --profiles-dir=. --project-dir=. --full-refresh - dbt run --profiles-dir=. --project-dir=. --full-refresh --select session_deliveries + dbt run --profiles-dir=. --project-dir=. --full-refresh --select admin_tags diff --git a/models/generated/airbyte_ctes/unibag/session_deliveries_ab1.sql b/models/generated/airbyte_ctes/unibag/session_deliveries_ab1.sql new file mode 100644 index 0000000..9f16705 --- /dev/null +++ b/models/generated/airbyte_ctes/unibag/session_deliveries_ab1.sql @@ -0,0 +1,31 @@ +{{ 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_session_deliveries') }} +select + {{ json_extract_scalar('_airbyte_data', ['_id'], ['_id']) }} as _id, + {{ json_extract_scalar('_airbyte_data', ['cart'], ['cart']) }} as cart, + {{ json_extract_scalar('_airbyte_data', ['note'], ['note']) }} as note, + {{ json_extract_scalar('_airbyte_data', ['title'], ['title']) }} as title, + {{ json_extract('table_alias', '_airbyte_data', ['request'], ['request']) }} as request, + {{ json_extract_scalar('_airbyte_data', ['service'], ['service']) }} as service, + {{ json_extract_scalar('_airbyte_data', ['currency'], ['currency']) }} as currency, + {{ json_extract('table_alias', '_airbyte_data', ['customer'], ['customer']) }} as customer, + {{ json_extract('table_alias', '_airbyte_data', ['delivery'], ['delivery']) }} as delivery, + {{ json_extract('table_alias', '_airbyte_data', ['location'], ['location']) }} as {{ adapter.quote('location') }}, + {{ json_extract_scalar('_airbyte_data', ['createdAt'], ['createdAt']) }} as createdat, + {{ json_extract('table_alias', '_airbyte_data', ['promotion'], ['promotion']) }} as promotion, + {{ json_extract_scalar('_airbyte_data', ['sessionOrder'], ['sessionOrder']) }} as sessionorder, + {{ json_extract_scalar('_airbyte_data', ['paymentMethod'], ['paymentMethod']) }} as paymentmethod, + {{ json_extract_scalar('_airbyte_data', ['estimateTimeDelivery'], ['estimateTimeDelivery']) }} as estimatetimedelivery, + _airbyte_ab_id, + _airbyte_emitted_at, + {{ current_timestamp() }} as _airbyte_normalized_at +from {{ source('unibag', '_airbyte_raw_session_deliveries') }} as table_alias +-- session_deliveries +where 1 = 1 + diff --git a/models/generated/airbyte_ctes/unibag/session_deliveries_ab2.sql b/models/generated/airbyte_ctes/unibag/session_deliveries_ab2.sql new file mode 100644 index 0000000..32f8f98 --- /dev/null +++ b/models/generated/airbyte_ctes/unibag/session_deliveries_ab2.sql @@ -0,0 +1,31 @@ +{{ 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('session_deliveries_ab1') }} +select + cast(_id as {{ dbt_utils.type_string() }}) as _id, + cast(cart as {{ dbt_utils.type_string() }}) as cart, + cast(note as {{ dbt_utils.type_string() }}) as note, + cast(title as {{ dbt_utils.type_string() }}) as title, + cast(request as {{ type_json() }}) as request, + cast(service as {{ dbt_utils.type_string() }}) as service, + cast(currency as {{ dbt_utils.type_string() }}) as currency, + cast(customer as {{ type_json() }}) as customer, + cast(delivery as {{ type_json() }}) as delivery, + cast({{ adapter.quote('location') }} as {{ type_json() }}) as {{ adapter.quote('location') }}, + cast(createdat as {{ dbt_utils.type_string() }}) as createdat, + cast(promotion as {{ type_json() }}) as promotion, + cast(sessionorder as {{ dbt_utils.type_string() }}) as sessionorder, + cast(paymentmethod as {{ dbt_utils.type_string() }}) as paymentmethod, + cast(estimatetimedelivery as {{ dbt_utils.type_string() }}) as estimatetimedelivery, + _airbyte_ab_id, + _airbyte_emitted_at, + {{ current_timestamp() }} as _airbyte_normalized_at +from {{ ref('session_deliveries_ab1') }} +-- session_deliveries +where 1 = 1 + diff --git a/models/generated/airbyte_ctes/unibag/session_deliveries_ab3.sql b/models/generated/airbyte_ctes/unibag/session_deliveries_ab3.sql new file mode 100644 index 0000000..deda432 --- /dev/null +++ b/models/generated/airbyte_ctes/unibag/session_deliveries_ab3.sql @@ -0,0 +1,31 @@ +{{ 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('session_deliveries_ab2') }} +select + {{ dbt_utils.surrogate_key([ + '_id', + 'cart', + 'note', + 'title', + object_to_string('request'), + 'service', + 'currency', + object_to_string('customer'), + object_to_string('delivery'), + object_to_string(adapter.quote('location')), + 'createdat', + object_to_string('promotion'), + 'sessionorder', + 'paymentmethod', + 'estimatetimedelivery', + ]) }} as _airbyte_session_deliveries_hashid, + tmp.* +from {{ ref('session_deliveries_ab2') }} tmp +-- session_deliveries +where 1 = 1 + diff --git a/models/generated/airbyte_tables/unibag/product_sku.sql b/models/generated/airbyte_tables/unibag/product_sku.sql index b62ba82..6ae44f0 100644 --- a/models/generated/airbyte_tables/unibag/product_sku.sql +++ b/models/generated/airbyte_tables/unibag/product_sku.sql @@ -23,7 +23,8 @@ select {{ adapter.quote('info') }}::json->'supplier'->>'_id' AS supplier_id, {{ adapter.quote('info') }}::json->'supplier'->>'name' AS supplier_name, {{ adapter.quote('info') }}::json->>'dimension' AS info_dimension, - unitCode AS info_unit_code, + unitcode AS info_unit_code, + suppliersku AS supplier_sku, cast({{ adapter.quote('info') }}::json->>'weight' AS numeric) AS info_weight, cast({{ adapter.quote('statistic') }}::json->>'saleTotal' AS numeric) AS stats_sale_total, cast({{ adapter.quote('statistic') }}::json->>'salePending' AS numeric) AS stats_sale_pending, diff --git a/models/generated/airbyte_tables/unibag/session_deliveries.sql b/models/generated/airbyte_tables/unibag/session_deliveries.sql new file mode 100644 index 0000000..12eae50 --- /dev/null +++ b/models/generated/airbyte_tables/unibag/session_deliveries.sql @@ -0,0 +1,34 @@ +{{ 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('session_deliveries_ab3') }} +select + _id, + sessionorder AS session_order_id, + title, + service, + currency, + {{ adapter.quote('customer') }}::json->>'_id' AS customer_id, + {{ adapter.quote('customer') }}::json->>'name' AS customer_name, + {{ adapter.quote('customer') }}::json->>'phone' AS customer_phone, + {{ adapter.quote('delivery') }}::jsonb, + {{ adapter.quote('location') }}::jsonb, + {{ adapter.quote('promotion') }}::json->>'type' AS promotion_type, + {{ adapter.quote('promotion') }}::json->>'isApplied' AS promotion_is_applied, + {{ adapter.quote('promotion') }}::json->>'discount' AS promotion_discount, + {{ adapter.quote('promotion') }}::json->>'minOrderValue' AS promotion_min_order_value, + paymentmethod AS payment_method, + estimatetimedelivery AS estimate_time_delivery, + createdat::timestamp AS created_at, + _airbyte_ab_id, + _airbyte_emitted_at, + {{ current_timestamp() }} as _airbyte_normalized_at, + _airbyte_session_deliveries_hashid +from {{ ref('session_deliveries_ab3') }} +-- session_deliveries from {{ source('unibag', '_airbyte_raw_session_deliveries') }} +where 1 = 1 +