SELECT
date_trunc(year, CAST(contrib_date AS TIMESTAMP(0))) as key0,
AVG(amount) AS series_1
FROM contributions_donotmodify
WHERE
(CAST(contrib_date AS TIMESTAMP(0)) >= TIMESTAMP(0) '1996-11-05 17:47:30'
AND CAST(contrib_date AS TIMESTAMP(0)) <= TIMESTAMP(0) '2010-10-21 10:54:07')
AND amount IS NOT NULL
GROUP BY key0
ORDER BY key0
if one were to follow the specification "strictly"
{
"data": {"table": "contributions"},
"transform": [
{
"type": "formula",
"as": "key0",
"expr": "date_trunc(year, CAST(datum.contrib_date AS TIMESTAMP(0)))"
},
{
"type": "aggregate",
"groupby": ["key0"],
"fields": ["amount"],
"ops": ["average"],
"as": ["series_1"]
},
{
"type": "collect",
"sort": { "field": "key0" }
},
{
"type": "filter",
"field": "contrib_date",
"range": ["1996-11-05 17:47:30", "2010-10-21 10:54:07"]
},
{
"type": "filter",
"expr": "amount IS NOT NULL"
}
]
}
if one were to follow it in "spirit", but introduce new syntax for sql:
{
"data": {"table": "contributions"},
"transform": [
{
"type": "formula",
"field": "contrib_date",
"as": "key0",
"dateTrunc": "year",
"cast": "timestamp"
},
{
"type": "aggregate",
"groupby": ["key0"],
"fields": ["amount"],
"ops": ["average"],
"as": ["series_1"]
},
{
"type": "collect",
"sort": { "field": "key0" }
},
{
"type": "filter",
"field": "contrib_date",
"range": ["1996-11-05 17:47:30", "2010-10-21 10:54:07"]
},
{
"type": "filter",
"isNull": false
}
]
}