Skip to content

Instantly share code, notes, and snippets.

with stock as (
select id, symbol, date, to_json(data) as data_json from input_stage.stock
),
final as (
select
id,
symbol,
date,
CAST(json_extract_path_text(data_json, '1. open') as float) as open,
SELECT RUNAVG({fact/close}) ROWS BETWEEN 20 PRECEDING AND CURRENT ROW
predictions = predict_model(best, data=report_data)
print(predictions.head())
- name: revenue
label: Revenue
model: ref('revenue_all')
calculation_method: sum
expression: price * quantity
timestamp: date
time_grains: [day, week, month, quarter, year]
with customer_group as (
SELECT customer_id, sum(revenue) AS revenue_sum
FROM {{ metrics.calculate(
metric('revenue'),
grain='day',
dimensions=['customer_id']
) }}
GROUP BY customer_id
),
SELECT (SUM({fact/price} * {fact/quantity})) WHERE {label/order_status} = "Delivered"
SELECT {metric/gd_revenue} WHERE TOP(10%) OF ({metric/gd_revenue})
SELECT (
SELECT {metric/gd_revenue} WHERE (
SELECT {metric/revenue_top_10} BY {label/customers.customer_id} ALL OTHER
) > 0
) / {metric/gd_revenue}
name: Run extract and load
on:
push:
schedule:
- cron: "0 2 * * *"
workflow_dispatch:
jobs:
run_extract_load:
runs-on: ubuntu-latest
steps:
with deals as (select id, created_date, to_json("item") as item_json from input_stage.airtable_crm_deals),
final as (
select
id,
CAST(json_extract_path_text(item_json, 'Name') as VARCHAR) as name,
CAST(json_extract_path_text(item_json, 'Stage') as VARCHAR) as stage,
CAST(json_extract_path_text(item_json, 'Amount') as NUMERIC) as amount,
CAST(json_extract_path_text(item_json, 'Details') as VARCHAR) as details,
CAST(json_extract_path_text(item_json, 'Close Probability') as NUMERIC) as close_probability,