Skip to content

Instantly share code, notes, and snippets.

@buremba
Created May 5, 2020 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buremba/3d1db693755547925bb0ec0d1cc437df to your computer and use it in GitHub Desktop.
Save buremba/3d1db693755547925bb0ec0d1cc437df to your computer and use it in GitHub Desktop.
{
"type": "object",
"id": "http://docs.rakam.io/schema/model",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "The analytics model definition",
"required": [
"name"
],
"oneOf": [
{
"required": [
"target"
]
},
{
"required": [
"sql"
]
}
],
"definitions": {
"hidden": {
"type": "boolean",
"default": false
},
"label": {
"type": "string",
"title": "The label that will be visible in UI",
"minLength": 1
},
"description": {
"type": "string",
"title": "The description will be used in UI"
},
"stringOperators": {
"type": "string",
"enum": [
"equals",
"notEquals",
"in",
"contains",
"startsWith",
"endsWith",
"notContains"
]
},
"anyOperators": {
"type": "string",
"enum": [
"isSet",
"isNotSet"
]
},
"numberOperators": {
"type": "string",
"enum": [
"equals",
"lessThan",
"greaterThan"
]
},
"dateOperators": {
"type": "string",
"enum": [
"equals",
"lessThan",
"greaterThan"
]
},
"arrayOperators": {
"type": "string",
"enum": [
"includes",
"notIncludes"
]
},
"timeOperators": {
"type": "string",
"enum": [
"includes",
"notIncludes"
]
},
"booleanOperators": {
"type": "string",
"enum": [
"is"
]
},
"timestampOperators": {
"type": "string",
"enum": [
"equals",
"lessThan",
"greaterThan"
]
},
"type": {
"type": "string",
"enum": [
"string",
"integer",
"double",
"long",
"boolean",
"date",
"time",
"decimal",
"timestamp",
null
]
},
"reportOptions": {
"type": "object",
"title": "Defines how should we show the value of the metric in user interface",
"properties": {
"suffix": {
"type": "string",
"title": "The value will be added to the dimension value as suffix",
"default": "",
"examples": [
"USD"
]
},
"prefix": {
"type": "string",
"title": "The value will be added to the dimension value as prefix",
"default": "",
"examples": [
"$"
]
}
}
},
"sql": {
"type": "string",
"title": "The source SQL query of the model",
"examples": [
"select 1"
]
},
"persist": {
"type": "object",
"title": "Materialization config for SQL based models"
},
"target": {
"type": "object",
"title": "Defines the target table in the database",
"required": [
"table"
],
"properties": {
"database": {
"type": "string",
"title": "The database of the target table if applicable"
},
"schema": {
"type": "string",
"title": "The schema of the target table if applicable"
},
"table": {
"type": "string",
"title": "The source table of the model"
}
}
},
"filters": {
"type": "array",
"items": {
"type": "object",
"title": "The list of filters",
"required": [
"dimension",
"operator",
"valueType"
],
"allOf": [
{
"if": {
"properties": {
"valueType": {
"const": "string"
}
}
},
"then": {
"properties": {
"operator": {
"$ref": "#/definitions/stringOperators"
}
},
"required": [
"operator"
]
}
},
{
"if": {
"properties": {
"valueType": {
"enum": [
"integer",
"double",
"long"
]
}
}
},
"then": {
"properties": {
"operator": {
"$ref": "#/definitions/numberOperators"
}
},
"required": [
"operator"
]
}
},
{
"if": {
"properties": {
"valueType": {
"const": "timestamp"
}
}
},
"then": {
"properties": {
"operator": {
"$ref": "#/definitions/timestampOperators"
}
},
"required": [
"operator"
]
}
},
{
"if": {
"properties": {
"valueType": {
"const": "date"
}
}
},
"then": {
"properties": {
"operator": {
"$ref": "#/definitions/dateOperators"
}
},
"required": [
"operator"
]
}
},
{
"if": {
"properties": {
"valueType": {
"const": "boolean"
}
}
},
"then": {
"properties": {
"operator": {
"$ref": "#/definitions/booleanOperators"
}
},
"required": [
"operator"
]
}
},
{
"if": {
"properties": {
"valueType": {
"const": "time"
}
}
},
"then": {
"properties": {
"operator": {
"$ref": "#/definitions/timeOperators"
}
},
"required": [
"operator"
]
}
},
{
"if": {
"properties": {
"valueType": {
"pattern": "^array+"
}
}
},
"then": {
"properties": {
"operator": {
"$ref": "#/definitions/arrayOperators"
}
},
"required": [
"operator"
]
}
}
],
"properties": {
"dimension": {
"type": "string",
"examples": [
"campaign_name"
]
},
"valueType": {
"$ref": "#/definitions/type"
},
"value": {
"title": "The value that will be passed to the operator. Note that if operator is not isSet or isNotSet, this value is required."
}
}
}
}
},
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"target": {
"$ref": "#/definitions/target"
},
"persist": {
"$ref": "#/definitions/persist"
},
"sql": {
"$ref": "#/definitions/sql"
},
"label": {
"$ref": "#/definitions/label"
},
"description": {
"$ref": "#/definitions/description"
},
"hidden": {
"$ref": "#/definitions/hidden"
},
"category": {
"type": "string",
"minLength": 1
},
"relations": {
"type": "object",
"examples": [
{
"relationName": {
"model": "campaign",
"targetColumn": "id",
"sourceColumn": "campaign_id"
}
}
],
"additionalProperties": {
"type": "object",
"additionalProperties": false,
"oneOf": [
{
"required": [
"targetColumn",
"sourceColumn"
]
},
{
"required": [
"sql"
]
}
],
"properties": {
"label": {
"$ref": "#/definitions/label"
},
"description": {
"$ref": "#/definitions/description"
},
"hidden": {
"$ref": "#/definitions/hidden"
},
"model": {
"type": "string",
"title": "The target model of the relation",
"examples": [
"campaign"
]
},
"relationType": {
"type": "string",
"enum": [
"oneToOne",
"oneToMany",
"manyToOne",
"manyToMany"
],
"title": "The Relationtype Schema",
"default": "oneToOne"
},
"sql": {
"type": "string",
"title": "The SQL expression join relation to the target table",
"examples": [
"{{TABLE}}.campaign_id = {{TARGET}}.id"
]
},
"targetColumn": {
"type": "string",
"title": "The column of the target model",
"examples": [
"id"
]
},
"sourceColumn": {
"type": "string",
"title": "The column of the source model",
"examples": [
"campaign_id"
]
},
"joinType": {
"type": "string",
"enum": [
"leftJoin",
"innerJoin",
"rightJoin",
"fullJoin"
],
"title": "Defines how should we join to the target modeol",
"default": "leftJoin"
}
},
"required": [
"model"
]
}
},
"measures": {
"type": "object",
"examples": [
{
"measureName": {
"sql": "total_spent",
"aggregation": "sum",
"reportOptions": {
"prefix": "$"
}
}
}
],
"additionalProperties": {
"type": "object",
"additionalProperties": false,
"allOf": [
{
"if": {
"properties": {
"aggregation": {
"not": {
"const": "count"
}
}
}
},
"then": {
"oneOf": [
{
"required": [
"column"
]
},
{
"required": [
"sql"
]
}
]
}
}
],
"properties": {
"label": {
"$ref": "#/definitions/label"
},
"type": {
"$ref": "#/definitions/type"
},
"description": {
"$ref": "#/definitions/description"
},
"hidden": {
"$ref": "#/definitions/hidden"
},
"category": {
"type": "string",
"minLength": 1
},
"column": {
"type": "string",
"title": "The column of the measure",
"description": "The column must be present the the source table",
"examples": [
"total_spent"
]
},
"sql": {
"type": "string",
"title": "The SQL expression of the measure",
"description": "The SQL expression must evaulate to a number value",
"examples": [
"total_spent / 2"
]
},
"filters": {
"$ref": "#/definitions/filters"
},
"aggregation": {
"type": "string",
"title": "The aggregation function that will calculate the final value.",
"enum": [
"count",
"countUnique",
"sum",
"minimum",
"maximum",
"average",
"approximateUnique"
]
},
"reportOptions": {
"$ref": "#/definitions/reportOptions"
}
}
}
},
"mappings": {
"type": "object",
"examples": [
{
"eventTimestamp": "_time"
}
],
"properties": {
"eventTimestamp": {
"description": "The timestamp dimension for time-series data. It enforces the date filter in segmentation page and also being used by funnel and retention reports.",
"type": "string"
},
"userId": {
"description": "The dimension that points to user identifier for event models. Used by funnel and retention reports.",
"type": "string"
}
}
},
"dimensions": {
"type": "object",
"examples": [
{
"dimensionName": {
"column": "campaign_name"
}
}
],
"additionalProperties": {
"type": "object",
"dependencies": {
"timeframes": [
"type"
]
},
"oneOf": [
{
"required": [
"column"
]
},
{
"required": [
"sql"
]
}
],
"allOf": [
{
"if": {
"properties": {
"type": {
"const": "timestamp"
}
}
},
"then": {
"properties": {
"timeframes": {
"type": "array",
"uniqueItems": true,
"items": {
"enum": [
"hour",
"day",
"week",
"month",
"year",
"hourOfDay",
"dayOfMonth",
"weekOfYear",
"monthOfYear",
"quarterOfYear",
"dayOfWeek"
]
}
}
}
}
},
{
"if": {
"properties": {
"type": {
"const": "date"
}
}
},
"then": {
"properties": {
"timeframes": {
"type": "array",
"uniqueItems": true,
"items": {
"enum": [
"week",
"month",
"year",
"hourOfDay",
"dayOfMonth",
"weekOfYear",
"monthOfYear",
"quarterOfYear",
"dayOfWeek"
]
}
}
}
}
},
{
"if": {
"properties": {
"type": {
"not": {
"enum": ["timestamp", "date"]
}
}
}
},
"then": {
"properties": {
"timeframes": {
"type": "null"
}
}
}
}
],
"additionalProperties": false,
"required": ["type"],
"properties": {
"label": {
"$ref": "#/definitions/label"
},
"pivot": {
"type": "boolean"
},
"description": {
"$ref": "#/definitions/description"
},
"hidden": {
"$ref": "#/definitions/hidden"
},
"category": {
"type": "string",
"minLength": 1
},
"sql": {
"type": "string",
"title": "The SQL expression of the dimension",
"examples": [
"concat(campaign_start_date, '-', campaign_name)"
]
},
"column": {
"type": "string",
"title": "The column of the dimension",
"description": "The column must be present the the source table",
"examples": [
"campaign_name"
]
},
"pivotable": {
"type": "boolean",
"title": "If the dimension can used for pivoting",
"default": true
},
"type": {
"$ref": "#/definitions/type"
},
"timeframes": {
"type": "array"
},
"reportOptions": {
"$ref": "#/definitions/reportOptions"
}
}
}
}
},
"additionalProperties": false,
"errorMessage1": {
"required": "The model definition must be an object with required property `name` and either `target` or `sql` property that defines the data source"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment