{{ 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_orders') }} select {{ json_extract_scalar('_airbyte_data', ['_id'], ['_id']) }} as _id, {{ json_extract_scalar('_airbyte_data', ['code'], ['code']) }} as code, {{ json_extract_scalar('_airbyte_data', ['date'], ['date']) }} as {{ adapter.quote('date') }}, {{ json_extract_scalar('_airbyte_data', ['hour'], ['hour']) }} as {{ adapter.quote('hour') }}, {{ json_extract_scalar('_airbyte_data', ['note'], ['note']) }} as note, {{ json_extract_array('_airbyte_data', ['tags'], ['tags']) }} as tags, {{ json_extract_scalar('_airbyte_data', ['user'], ['user']) }} as {{ adapter.quote('user') }}, {{ json_extract_scalar('_airbyte_data', ['price'], ['price']) }} as price, {{ json_extract_scalar('_airbyte_data', ['banned'], ['banned']) }} as banned, {{ json_extract_scalar('_airbyte_data', ['reason'], ['reason']) }} as reason, {{ json_extract_scalar('_airbyte_data', ['source'], ['source']) }} as {{ adapter.quote('source') }}, {{ json_extract_scalar('_airbyte_data', ['status'], ['status']) }} as status, {{ json_extract_scalar('_airbyte_data', ['teamId'], ['teamId']) }} as teamid, {{ json_extract_scalar('_airbyte_data', ['payment'], ['payment']) }} as payment, {{ json_extract_scalar('_airbyte_data', ['remarks'], ['remarks']) }} as remarks, {{ json_extract_scalar('_airbyte_data', ['customer'], ['customer']) }} as customer, {{ json_extract_scalar('_airbyte_data', ['delivery'], ['delivery']) }} as delivery, {{ json_extract_scalar('_airbyte_data', ['isCalled'], ['isCalled']) }} as iscalled, {{ json_extract_scalar('_airbyte_data', ['merchant'], ['merchant']) }} as merchant, {{ json_extract_scalar('_airbyte_data', ['pickupAt'], ['pickupAt']) }} as pickupat, {{ json_extract_scalar('_airbyte_data', ['supplier'], ['supplier']) }} as supplier, {{ json_extract_scalar('_airbyte_data', ['createdAt'], ['createdAt']) }} as createdat, {{ json_extract_scalar('_airbyte_data', ['inventory'], ['inventory']) }} as inventory, {{ json_extract_scalar('_airbyte_data', ['invoiceId'], ['invoiceId']) }} as invoiceid, {{ json_extract_scalar('_airbyte_data', ['isDeleted'], ['isDeleted']) }} as isdeleted, {{ json_extract_scalar('_airbyte_data', ['promotion'], ['promotion']) }} as promotion, {{ json_extract_scalar('_airbyte_data', ['requestId'], ['requestId']) }} as requestid, {{ json_extract_scalar('_airbyte_data', ['restockAt'], ['restockAt']) }} as restockat, {{ json_extract_scalar('_airbyte_data', ['sendEmail'], ['sendEmail']) }} as sendemail, {{ json_extract_scalar('_airbyte_data', ['totalItem'], ['totalItem']) }} as totalitem, {{ json_extract_scalar('_airbyte_data', ['updatedAt'], ['updatedAt']) }} as updatedat, {{ json_extract_scalar('_airbyte_data', ['userAgent'], ['userAgent']) }} as useragent, {{ json_extract_scalar('_airbyte_data', ['wholesale'], ['wholesale']) }} as wholesale, {{ json_extract_scalar('_airbyte_data', ['approvedAt'], ['approvedAt']) }} as approvedat, {{ json_extract_scalar('_airbyte_data', ['cashbackAt'], ['cashbackAt']) }} as cashbackat, {{ json_extract_scalar('_airbyte_data', ['isPreorder'], ['isPreorder']) }} as ispreorder, {{ json_extract_scalar('_airbyte_data', ['isReviewed'], ['isReviewed']) }} as isreviewed, {{ json_extract_scalar('_airbyte_data', ['rejectedAt'], ['rejectedAt']) }} as rejectedat, {{ json_extract_scalar('_airbyte_data', ['deliveredAt'], ['deliveredAt']) }} as deliveredat, {{ json_extract_scalar('_airbyte_data', ['deliveringAt'], ['deliveringAt']) }} as deliveringat, {{ json_extract_scalar('_airbyte_data', ['deliveryCode'], ['deliveryCode']) }} as deliverycode, {{ json_extract_scalar('_airbyte_data', ['searchString'], ['searchString']) }} as searchstring, {{ json_extract_scalar('_airbyte_data', ['staffApprove'], ['staffApprove']) }} as staffapprove, {{ json_extract_scalar('_airbyte_data', ['teamMemberId'], ['teamMemberId']) }} as teammemberid, {{ json_extract_scalar('_airbyte_data', ['processStatus'], ['processStatus']) }} as processstatus, {{ json_extract_scalar('_airbyte_data', ['hookTimeLastAt'], ['hookTimeLastAt']) }} as hooktimelastat, {{ json_extract_scalar('_airbyte_data', ['isAssignCoupon'], ['isAssignCoupon']) }} as isassigncoupon, {{ json_extract_scalar('_airbyte_data', ['isAutoApproved'], ['isAutoApproved']) }} as isautoapproved, {{ json_extract_scalar('_airbyte_data', ['outboundRequest'], ['outboundRequest']) }} as outboundrequest, {{ json_extract_scalar('_airbyte_data', ['trackingCodeURL'], ['trackingCodeURL']) }} as trackingcodeurl, {{ json_extract_scalar('_airbyte_data', ['trackingCode'], ['trackingcode']) }} as trackingCode, {{ json_extract_scalar('_airbyte_data', ['waitingCancelBy'], ['waitingCancelBy']) }} as waitingcancelby, {{ json_extract_scalar('_airbyte_data', ['isChangeDelivery'], ['isChangeDelivery']) }} as ischangedelivery, {{ json_extract_scalar('_airbyte_data', ['estimateCashbackAt'], ['estimateCashbackAt']) }} as estimatecashbackat, {{ json_extract_scalar('_airbyte_data', ['fromNewActiveBuyer'], ['fromNewActiveBuyer']) }} as fromnewactivebuyer, {{ json_extract_scalar('_airbyte_data', ['isWaitingCancelled'], ['isWaitingCancelled']) }} as iswaitingcancelled, {{ json_extract_scalar('_airbyte_data', ['fromNewActiveSeller'], ['fromNewActiveSeller']) }} as fromnewactiveseller, {{ json_extract_scalar('_airbyte_data', ['waitingCancelReason'], ['waitingCancelReason']) }} as waitingcancelreason, _airbyte_ab_id, _airbyte_emitted_at, {{ current_timestamp() }} as _airbyte_normalized_at from {{ source('unibag', '_airbyte_raw_orders') }} as table_alias -- orders where 1 = 1