update
This commit is contained in:
		
							parent
							
								
									c92bdc7cb4
								
							
						
					
					
						commit
						f6af10b64d
					
				
							
								
								
									
										2
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										2
									
								
								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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 | ||||
| 
 | ||||
|  | @ -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 | ||||
| 
 | ||||
|  | @ -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 | ||||
| 
 | ||||
|  | @ -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, | ||||
|  |  | |||
|  | @ -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 | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue