Model configuration
Download JSON Schema
Example
apiVersion: leapview.dev/v1
kind: Model
metadata:
id: model:cash_forecast
name: cash_forecast
displayName: 13-Week Cash Forecast Fact
description: Weekly cash-forecast fact at scenario and forecast-week grain.
spec:
fields:
- {name: cash_row_id, datatype: String, label: Cash row ID}
- {name: week_index, datatype: Integer, label: Week}
- {name: scenario, datatype: String, label: Scenario key}
- {name: collections, datatype: Decimal, label: Customer collections}
- {name: supplier_payments, datatype: Decimal, label: Supplier payments}
- {name: payroll, datatype: Decimal, label: Payroll}
- {name: operating_expenses, datatype: Decimal, label: Operating expenses}
- {name: taxes, datatype: Decimal, label: Taxes}
- {name: net_cash_flow, datatype: Decimal, label: Net cash flow}
- {name: base_collections, datatype: Decimal, label: Base collections}
- {name: base_supplier_payments, datatype: Decimal, label: Base supplier payments}
- {name: base_net_cash_flow, datatype: Decimal, label: Base net cash flow}
- {name: closing_cash, datatype: Decimal, label: Closing cash}
- {name: scenario_ending_cash, datatype: Decimal, label: Scenario ending cash}
- {name: scenario_headroom, datatype: Decimal, label: Scenario cash headroom}
- {name: current_cash, datatype: Decimal, label: Current cash}
- {name: base_ending_cash, datatype: Decimal, label: Base ending cash}
- {name: base_headroom, datatype: Decimal, label: Base cash headroom}
- {name: overdue_receivables, datatype: Decimal, label: Overdue receivables}
- {name: dso_days, datatype: Decimal, label: Days sales outstanding}
definition:
type: sql
sql: |
WITH revenue_scale AS (
SELECT SUM(net_sales) / 104.0 AS weekly_sales
FROM model.financial_performance
),
flows AS (
SELECT
w.week_index,
s.scenario,
r.weekly_sales * s.collection_factor * CASE WHEN w.week_index = 3 OR w.week_index = 8 THEN 1.12 ELSE 1.0 END AS collections,
-(r.weekly_sales * 0.66 * s.payment_factor * CASE WHEN w.week_index = 4 OR w.week_index = 9 THEN 1.08 ELSE 1.0 END) AS supplier_payments,
-(r.weekly_sales * 0.10) AS payroll,
-(r.weekly_sales * 0.12) AS operating_expenses,
-(r.weekly_sales * CASE WHEN w.week_index = 5 OR w.week_index = 12 THEN 0.06 ELSE 0.015 END) AS taxes,
r.weekly_sales * 10.0 AS opening_cash
FROM model.cash_weeks w
INNER JOIN model.cash_scenarios s ON true
INNER JOIN revenue_scale r ON true
),
projected AS (
SELECT
week_index,
scenario,
collections,
supplier_payments,
payroll,
operating_expenses,
taxes,
collections + supplier_payments + payroll + operating_expenses + taxes AS net_cash_flow,
opening_cash + SUM(collections + supplier_payments + payroll + operating_expenses + taxes)
OVER (PARTITION BY scenario ORDER BY week_index) AS closing_cash,
opening_cash
FROM flows
)
SELECT
scenario || '-' || printf('%02d', week_index) AS cash_row_id,
week_index,
scenario,
CAST(round(collections, 2) AS DECIMAL(38,2)) AS collections,
CAST(round(supplier_payments, 2) AS DECIMAL(38,2)) AS supplier_payments,
CAST(round(payroll, 2) AS DECIMAL(38,2)) AS payroll,
CAST(round(operating_expenses, 2) AS DECIMAL(38,2)) AS operating_expenses,
CAST(round(taxes, 2) AS DECIMAL(38,2)) AS taxes,
CAST(round(net_cash_flow, 2) AS DECIMAL(38,2)) AS net_cash_flow,
CASE WHEN scenario = 'Base' THEN CAST(round(collections, 2) AS DECIMAL(38,2)) ELSE NULL END AS base_collections,
CASE WHEN scenario = 'Base' THEN CAST(round(supplier_payments, 2) AS DECIMAL(38,2)) ELSE NULL END AS base_supplier_payments,
CASE WHEN scenario = 'Base' THEN CAST(round(net_cash_flow, 2) AS DECIMAL(38,2)) ELSE NULL END AS base_net_cash_flow,
CAST(round(closing_cash, 2) AS DECIMAL(38,2)) AS closing_cash,
CASE WHEN week_index = 12 THEN CAST(round(closing_cash, 2) AS DECIMAL(38,2)) ELSE NULL END AS scenario_ending_cash,
CASE WHEN week_index = 12 THEN CAST(round(closing_cash - opening_cash * 0.45, 2) AS DECIMAL(38,2)) ELSE NULL END AS scenario_headroom,
CASE WHEN scenario = 'Base' AND week_index = 0 THEN CAST(round(opening_cash, 2) AS DECIMAL(38,2)) ELSE NULL END AS current_cash,
CASE WHEN scenario = 'Base' AND week_index = 12 THEN CAST(round(closing_cash, 2) AS DECIMAL(38,2)) ELSE NULL END AS base_ending_cash,
CASE WHEN scenario = 'Base' AND week_index = 12 THEN CAST(round(closing_cash - opening_cash * 0.45, 2) AS DECIMAL(38,2)) ELSE NULL END AS base_headroom,
CASE WHEN scenario = 'Base' AND week_index = 0 THEN CAST(round(opening_cash * 0.31, 2) AS DECIMAL(38,2)) ELSE NULL END AS overdue_receivables,
CASE WHEN scenario = 'Base' AND week_index = 0 THEN CAST(47 AS DECIMAL(38,2)) ELSE NULL END AS dso_days
FROM projected
entities:
- name: cash_forecast_row
type: primary
fields: [cash_row_id]
- name: cash_week
type: foreign
fields: [week_index]
- name: cash_scenario
type: foreign
fields: [scenario]
grain:
entity: cash_forecast_row
Fields
| Field |
Type |
Required |
Rules |
aiContext |
AIContext |
No |
|
apiVersion |
string |
Yes |
one of leapview.dev/v1 |
kind |
Model |
Yes |
|
metadata |
ContractResourceMetadata |
Yes |
|
spec |
ModelSpec |
Yes |
|
Nested definitions
AIContext
| Field |
Type |
Required |
Rules |
examples |
array of string |
No |
|
instructions |
string |
No |
|
synonyms |
array of string |
No |
|
AcceptedValuesDatasetCheck
| Field |
Type |
Required |
Rules |
description |
string |
No |
|
field |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
id |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
severity |
string |
No |
one of warning, error |
tags |
array of string |
No |
|
type |
string |
Yes |
one of accepted_values |
values |
array of string |
Yes |
|
AuthoritativeDefinition
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of businessDefinition, transformationImplementation |
url |
string |
Yes |
pattern ^[A-Za-z][A-Za-z0-9+.-]*:[^\s]+$ |
AzureBlobConnection
| Field |
Type |
Required |
Rules |
access |
PublicAccess |
No |
|
defaults |
ReaderDefaults |
No |
|
type |
string |
Yes |
one of azure_blob |
BlobPathSourceLocation
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
one of blob |
CSVPathSourceLocation
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
one of csv |
options |
CSVReaderOptions |
No |
|
CSVReaderOptions
| Field |
Type |
Required |
Rules |
delimiter |
string |
No |
|
escape |
string |
No |
|
header |
boolean |
No |
|
nullString |
string |
No |
|
quote |
string |
No |
|
Connection
| Field |
Type |
Required |
Rules |
apiVersion |
string |
Yes |
one of leapview.dev/v1 |
kind |
string |
Yes |
one of Connection |
metadata |
ResourceMetadata |
Yes |
|
spec |
ConnectionSpec |
Yes |
|
ConnectionSpec
| Field |
Type |
Required |
Rules |
ConnectionSpecBase
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
|
| Field |
Type |
Required |
Rules |
compatibility |
string |
Yes |
one of backward |
version |
string |
Yes |
pattern `^(0 |
| Field |
Type |
Required |
Rules |
contract |
ContractMetadata |
No |
|
description |
string |
No |
|
displayName |
string |
No |
|
documentation |
string |
No |
|
domain |
string |
No |
|
id |
string |
Yes |
pattern ^[A-Za-z0-9][A-Za-z0-9_.:-]*$ |
name |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)*$ |
owner |
string |
No |
|
provenance |
ResourceProvenance |
No |
|
tags |
array of string |
No |
|
DatasetCheck
| Field |
Type |
Required |
Rules |
DatasetCheckAcceptedValuesVariant
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of accepted_values |
DatasetCheckFreshnessVariant
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of freshness |
DatasetCheckNonNullVariant
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of non_null |
DatasetCheckRelationshipVariant
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of relationship |
DatasetCheckRowCountVariant
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of row_count |
DatasetCheckUniqueVariant
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of unique |
DatasetField
| Field |
Type |
Required |
Rules |
aiContext |
AIContext |
No |
|
authoritativeDefinitions |
array of AuthoritativeDefinition |
No |
|
classification |
string |
No |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
criticalDataElement |
boolean |
No |
|
datatype |
string |
No |
one of String, Integer, Decimal, Float, Boolean, Date, Time, DateTime, DateTimeTz, Opaque |
deprecation |
FieldDeprecation |
No |
|
description |
string |
No |
|
label |
string |
No |
|
name |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
tags |
array of string |
No |
|
DatasetSchema
| Field |
Type |
Required |
Rules |
mode |
string |
Yes |
one of compatible, strict |
DeltaPathSourceLocation
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
one of delta |
options |
DeltaReaderOptions |
No |
|
DeltaReaderOptions
| Field |
Type |
Required |
Rules |
version |
string |
No |
pattern `^(0 |
DirectModelDefinition
| Field |
Type |
Required |
Rules |
source |
string |
Yes |
pattern ^[A-Za-z0-9][A-Za-z0-9_.:-]*$ |
type |
string |
Yes |
one of direct |
DuckLakeConnection
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of ducklake |
ExcelPathSourceLocation
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
one of excel |
options |
ExcelReaderOptions |
No |
|
ExcelReaderOptions
| Field |
Type |
Required |
Rules |
header |
boolean |
No |
|
sheet |
string |
No |
|
FieldDeprecation
| Field |
Type |
Required |
Rules |
reason |
string |
Yes |
|
replacement |
string |
No |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
since |
string |
Yes |
pattern `^(0 |
FreshnessDatasetCheck
| Field |
Type |
Required |
Rules |
basis |
string |
Yes |
one of field, revision |
description |
string |
No |
|
errorAfter |
FreshnessDuration |
No |
|
field |
string |
No |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
id |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
revision |
string |
No |
|
tags |
array of string |
No |
|
type |
string |
Yes |
one of freshness |
warningAfter |
FreshnessDuration |
No |
|
FreshnessDuration
| Field |
Type |
Required |
Rules |
amount |
integer |
Yes |
|
unit |
string |
Yes |
one of second, minute, hour, day |
GCSConnection
| Field |
Type |
Required |
Rules |
access |
PublicAccess |
No |
|
defaults |
ReaderDefaults |
No |
|
type |
string |
Yes |
one of gcs |
HTTPConnection
| Field |
Type |
Required |
Rules |
access |
PublicAccess |
No |
|
defaults |
ReaderDefaults |
No |
|
type |
string |
Yes |
one of http |
IcebergPathSourceLocation
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
one of iceberg |
options |
IcebergReaderOptions |
No |
|
IcebergReaderOptions
| Field |
Type |
Required |
Rules |
snapshot |
string |
No |
pattern `^(0 |
JSONPathSourceLocation
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
one of json |
options |
JSONReaderOptions |
No |
|
JSONReaderOptions
| Field |
Type |
Required |
Rules |
format |
string |
No |
one of auto, array, newline_delimited |
maximumDepth |
integer |
No |
|
LancePathSourceLocation
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
one of lance |
ManagedConnection
| Field |
Type |
Required |
Rules |
access |
PublicAccess |
No |
|
defaults |
ReaderDefaults |
No |
|
type |
string |
Yes |
one of managed |
Model
| Field |
Type |
Required |
Rules |
aiContext |
AIContext |
No |
|
apiVersion |
string |
Yes |
one of leapview.dev/v1 |
kind |
Model |
Yes |
|
metadata |
ContractResourceMetadata |
Yes |
|
spec |
ModelSpec |
Yes |
|
ModelDefinition
| Field |
Type |
Required |
Rules |
ModelDefinitionBase
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
|
ModelEntity
| Field |
Type |
Required |
Rules |
aiContext |
AIContext |
No |
|
description |
string |
No |
|
fields |
array of string |
Yes |
|
name |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
type |
string |
Yes |
one of primary, unique, foreign, natural |
ModelGrain
| Field |
Type |
Required |
Rules |
entity |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
ModelSpec
| Field |
Type |
Required |
Rules |
checks |
array of DatasetCheck |
No |
|
definition |
ModelDefinition |
Yes |
|
entities |
array of ModelEntity |
Yes |
|
fields |
array of DatasetField |
No |
|
grain |
ModelGrain |
Yes |
|
schema |
DatasetSchema |
No |
|
MySQLConnection
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of mysql |
NonNullDatasetCheck
| Field |
Type |
Required |
Rules |
description |
string |
No |
|
field |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
id |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
severity |
string |
No |
one of warning, error |
tags |
array of string |
No |
|
type |
string |
Yes |
one of non_null |
ParquetPathSourceLocation
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
one of parquet |
options |
ParquetReaderOptions |
No |
|
ParquetReaderOptions
| Field |
Type |
Required |
Rules |
hivePartitioning |
boolean |
No |
|
unionByName |
boolean |
No |
|
PathSourceLocation
| Field |
Type |
Required |
Rules |
PathSourceLocationBase
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
|
path |
string |
Yes |
|
type |
string |
Yes |
one of path |
PostgresConnection
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of postgres |
PublicAccess
| Field |
Type |
Required |
Rules |
QuackConnection
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of quack |
R2Connection
| Field |
Type |
Required |
Rules |
access |
PublicAccess |
No |
|
defaults |
ReaderDefaults |
No |
|
type |
string |
Yes |
one of r2 |
ReaderDefaults
| Field |
Type |
Required |
Rules |
csv |
CSVReaderOptions |
No |
|
delta |
DeltaReaderOptions |
No |
|
excel |
ExcelReaderOptions |
No |
|
iceberg |
IcebergReaderOptions |
No |
|
json |
JSONReaderOptions |
No |
|
parquet |
ParquetReaderOptions |
No |
|
RelationSourceLocation
| Field |
Type |
Required |
Rules |
catalog |
string |
No |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
name |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
schema |
string |
No |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
type |
string |
Yes |
one of relation |
RelationshipDatasetCheck
| Field |
Type |
Required |
Rules |
description |
string |
No |
|
field |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
id |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
severity |
string |
No |
one of warning, error |
tags |
array of string |
No |
|
to |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)*\.[A-Za-z_][A-Za-z0-9_]*$ |
type |
string |
Yes |
one of relationship |
| Field |
Type |
Required |
Rules |
description |
string |
No |
|
displayName |
string |
No |
|
documentation |
string |
No |
|
domain |
string |
No |
|
id |
string |
Yes |
pattern ^[A-Za-z0-9][A-Za-z0-9_.:-]*$ |
name |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)*$ |
owner |
string |
No |
|
provenance |
ResourceProvenance |
No |
|
tags |
array of string |
No |
|
ResourceProvenance
| Field |
Type |
Required |
Rules |
origin |
string |
No |
|
path |
string |
No |
|
source |
string |
No |
|
RowCountDatasetCheck
| Field |
Type |
Required |
Rules |
description |
string |
No |
|
id |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
maximum |
integer |
No |
|
minimum |
integer |
No |
|
severity |
string |
No |
one of warning, error |
tags |
array of string |
No |
|
type |
string |
Yes |
one of row_count |
S3Connection
| Field |
Type |
Required |
Rules |
access |
PublicAccess |
No |
|
defaults |
ReaderDefaults |
No |
|
type |
string |
Yes |
one of s3 |
SQLModelDefinition
| Field |
Type |
Required |
Rules |
sql |
string |
Yes |
|
type |
string |
Yes |
one of sql |
SQLiteConnection
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of sqlite |
Source
| Field |
Type |
Required |
Rules |
apiVersion |
string |
Yes |
one of leapview.dev/v1 |
kind |
string |
Yes |
one of Source |
metadata |
ContractResourceMetadata |
Yes |
|
spec |
SourceSpec |
Yes |
|
SourceLocation
| Field |
Type |
Required |
Rules |
SourceLocationPathVariant
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of path |
SourceLocationRelationVariant
| Field |
Type |
Required |
Rules |
type |
string |
Yes |
one of relation |
SourceSpec
| Field |
Type |
Required |
Rules |
checks |
array of DatasetCheck |
No |
|
connection |
string |
Yes |
pattern ^[A-Za-z0-9][A-Za-z0-9_.:-]*$ |
fields |
array of DatasetField |
No |
|
location |
SourceLocation |
Yes |
|
schema |
DatasetSchema |
No |
|
TextPathSourceLocation
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
one of text |
UniqueDatasetCheck
| Field |
Type |
Required |
Rules |
description |
string |
No |
|
fields |
array of string |
Yes |
|
id |
string |
Yes |
pattern ^[A-Za-z_][A-Za-z0-9_]*$ |
severity |
string |
No |
one of warning, error |
tags |
array of string |
No |
|
type |
string |
Yes |
one of unique |
VortexPathSourceLocation
| Field |
Type |
Required |
Rules |
format |
string |
Yes |
one of vortex |