2022-03-22 04:03:52 +00:00
|
|
|
{{ 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('orders_ab1') }}
|
|
|
|
select
|
|
|
|
cast(_id as {{ dbt_utils.type_string() }}) as _id,
|
|
|
|
cast(code as {{ dbt_utils.type_string() }}) as code,
|
|
|
|
cast({{ adapter.quote('date') }} as {{ dbt_utils.type_string() }}) as {{ adapter.quote('date') }},
|
|
|
|
cast({{ adapter.quote('hour') }} as {{ dbt_utils.type_float() }}) as {{ adapter.quote('hour') }},
|
|
|
|
cast(note as {{ dbt_utils.type_string() }}) as note,
|
2022-05-10 14:30:53 +00:00
|
|
|
skus,
|
2022-03-22 04:03:52 +00:00
|
|
|
tags,
|
|
|
|
cast({{ adapter.quote('user') }} as {{ dbt_utils.type_string() }}) as {{ adapter.quote('user') }},
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(price as {{ type_json() }}) as price,
|
2022-03-22 04:03:52 +00:00
|
|
|
{{ cast_to_boolean('banned') }} as banned,
|
|
|
|
cast(reason as {{ dbt_utils.type_string() }}) as reason,
|
|
|
|
cast({{ adapter.quote('source') }} as {{ dbt_utils.type_string() }}) as {{ adapter.quote('source') }},
|
|
|
|
cast(status as {{ dbt_utils.type_string() }}) as status,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast({{ adapter.quote('update') }} as {{ dbt_utils.type_string() }}) as {{ adapter.quote('update') }},
|
|
|
|
cast(payment as {{ type_json() }}) as payment,
|
2022-03-22 04:03:52 +00:00
|
|
|
cast(remarks as {{ dbt_utils.type_string() }}) as remarks,
|
|
|
|
cast(customer as {{ dbt_utils.type_string() }}) as customer,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(delivery as {{ type_json() }}) as delivery,
|
2022-03-22 04:03:52 +00:00
|
|
|
cast(pickupat as {{ dbt_utils.type_string() }}) as pickupat,
|
2022-05-10 14:30:53 +00:00
|
|
|
products,
|
|
|
|
cast(supplier as {{ type_json() }}) as supplier,
|
|
|
|
cast(approveat as {{ dbt_utils.type_string() }}) as approveat,
|
2022-03-22 04:03:52 +00:00
|
|
|
cast(createdat as {{ dbt_utils.type_string() }}) as createdat,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(inventory as {{ type_json() }}) as inventory,
|
2022-03-22 04:03:52 +00:00
|
|
|
{{ cast_to_boolean('isdeleted') }} as isdeleted,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(promotion as {{ type_json() }}) as promotion,
|
2022-03-22 04:03:52 +00:00
|
|
|
cast(requestid as {{ dbt_utils.type_string() }}) as requestid,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(sendemail as {{ type_json() }}) as sendemail,
|
2022-03-22 04:03:52 +00:00
|
|
|
cast(totalitem as {{ dbt_utils.type_float() }}) as totalitem,
|
|
|
|
cast(updatedat as {{ dbt_utils.type_string() }}) as updatedat,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(useragent as {{ type_json() }}) as useragent,
|
2022-03-22 04:03:52 +00:00
|
|
|
{{ cast_to_boolean('wholesale') }} as wholesale,
|
|
|
|
cast(approvedat as {{ dbt_utils.type_string() }}) as approvedat,
|
|
|
|
cast(cashbackat as {{ dbt_utils.type_string() }}) as cashbackat,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(codeosiris as {{ dbt_utils.type_string() }}) as codeosiris,
|
2022-03-22 04:03:52 +00:00
|
|
|
{{ cast_to_boolean('ispreorder') }} as ispreorder,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(membership as {{ dbt_utils.type_string() }}) as membership,
|
2022-03-22 04:03:52 +00:00
|
|
|
cast(rejectedat as {{ dbt_utils.type_string() }}) as rejectedat,
|
|
|
|
cast(deliveredat as {{ dbt_utils.type_string() }}) as deliveredat,
|
|
|
|
cast(deliveringat as {{ dbt_utils.type_string() }}) as deliveringat,
|
|
|
|
cast(deliverycode as {{ dbt_utils.type_string() }}) as deliverycode,
|
|
|
|
cast(searchstring as {{ dbt_utils.type_string() }}) as searchstring,
|
|
|
|
cast(staffapprove as {{ dbt_utils.type_string() }}) as staffapprove,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(trackingcode as {{ dbt_utils.type_string() }}) as trackingcode,
|
2022-03-22 04:03:52 +00:00
|
|
|
cast(processstatus as {{ dbt_utils.type_string() }}) as processstatus,
|
|
|
|
cast(hooktimelastat as {{ dbt_utils.type_string() }}) as hooktimelastat,
|
|
|
|
cast(trackingcodeurl as {{ dbt_utils.type_string() }}) as trackingcodeurl,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(approvepaymentat as {{ dbt_utils.type_string() }}) as approvepaymentat,
|
2022-03-22 04:03:52 +00:00
|
|
|
{{ cast_to_boolean('ischangedelivery') }} as ischangedelivery,
|
2022-05-10 14:30:53 +00:00
|
|
|
cast(trackingordercode as {{ dbt_utils.type_string() }}) as trackingordercode,
|
2022-03-22 04:03:52 +00:00
|
|
|
cast(estimatecashbackat as {{ dbt_utils.type_string() }}) as estimatecashbackat,
|
|
|
|
{{ cast_to_boolean('iswaitingcancelled') }} as iswaitingcancelled,
|
|
|
|
{{ cast_to_boolean('fromnewactiveseller') }} as fromnewactiveseller,
|
|
|
|
_airbyte_ab_id,
|
|
|
|
_airbyte_emitted_at,
|
|
|
|
{{ current_timestamp() }} as _airbyte_normalized_at
|
|
|
|
from {{ ref('orders_ab1') }}
|
|
|
|
-- orders
|
|
|
|
where 1 = 1
|
|
|
|
|