File tree Expand file tree Collapse file tree 3 files changed +561
-7
lines changed
cubejs-schema-compiler/src/adapter Expand file tree Collapse file tree 3 files changed +561
-7
lines changed Original file line number Diff line number Diff line change 1+ import { parseSqlInterval } from '@cubejs-backend/shared' ;
12import { BaseQuery } from './BaseQuery' ;
23import { BaseFilter } from './BaseFilter' ;
34
@@ -55,6 +56,30 @@ export class PrestodbQuery extends BaseQuery {
5556 field ;
5657 }
5758
59+ /**
60+ * Returns sql for source expression floored to timestamps aligned with
61+ * intervals relative to origin timestamp point.
62+ * Athena doesn't support INTERVALs directly — using date_diff/date_add
63+ */
64+ public dateBin ( interval : string , source : string , origin : string ) : string {
65+ const intervalParsed = parseSqlInterval ( interval ) ;
66+ const intervalParts = Object . entries ( intervalParsed ) ;
67+
68+ if ( intervalParts . length > 1 ) {
69+ throw new Error ( 'Athena/Presto supports only simple intervals with one date part' ) ;
70+ }
71+
72+ const [ unit , count ] = intervalParts [ 0 ] ;
73+ const originExpr = this . timeStampCast ( `'${ origin } '` ) ;
74+
75+ return `date_add('${ unit } ',
76+ floor(
77+ date_diff('${ unit } ', ${ originExpr } , ${ source } ) / ${ count }
78+ ) * ${ count } ,
79+ ${ originExpr }
80+ )` ;
81+ }
82+
5883 public timeGroupedColumn ( granularity , dimension ) {
5984 return `date_trunc('${ GRANULARITY_TO_INTERVAL [ granularity ] } ', ${ dimension } )` ;
6085 }
Original file line number Diff line number Diff line change 151151 " ---------------------------------------" ,
152152 " Custom Granularities " ,
153153 " ---------------------------------------" ,
154- " querying custom granularities ECommerce: count by half_year + no dimension" ,
155- " querying custom granularities ECommerce: count by half_year_by_1st_april + no dimension" ,
156154 " querying custom granularities ECommerce: count by three_months_by_march + no dimension" ,
157- " querying custom granularities ECommerce: count by half_year + dimension" ,
158- " querying custom granularities ECommerce: count by half_year_by_1st_april + dimension" ,
159155 " querying custom granularities ECommerce: count by three_months_by_march + dimension" ,
160- " querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByUnbounded" ,
161- " querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByTrailing" ,
162- " querying custom granularities ECommerce: count by two_mo_by_feb + no dimension + rollingCountByLeading" ,
163156
164157 " SKIPPED SQL API (Need work)" ,
165158 " ---------------------------------------" ,
You can’t perform that action at this time.
0 commit comments