@@ -79,6 +79,19 @@ describe('SQL Generation', () => {
7979 offset: 'start'
8080 }
8181 },
82+ countRollingUnbounded: {
83+ type: 'count',
84+ rollingWindow: {
85+ trailing: 'unbounded'
86+ }
87+ },
88+ countRollingWeekToDate: {
89+ type: 'count',
90+ rollingWindow: {
91+ type: 'to_date',
92+ granularity: 'week'
93+ }
94+ },
8295 revenue_qtd: {
8396 type: 'sum',
8497 sql: 'amount',
@@ -220,7 +233,14 @@ describe('SQL Generation', () => {
220233 },
221234 created_at: {
222235 type: 'time',
223- sql: 'created_at'
236+ sql: 'created_at',
237+ granularities: {
238+ three_days: {
239+ interval: '3 days',
240+ title: '3 days',
241+ origin: '2017-01-01'
242+ }
243+ }
224244 },
225245 updated_at: {
226246 type: 'time',
@@ -778,6 +798,163 @@ describe('SQL Generation', () => {
778798 }
779799 ] ) ) ;
780800
801+ it ( 'rolling window with two time dimension granularities' , async ( ) => runQueryTest ( {
802+ measures : [
803+ 'visitors.countRollingWeekToDate'
804+ ] ,
805+ timeDimensions : [
806+ {
807+ dimension : 'visitors.created_at' ,
808+ granularity : 'three_days' ,
809+ dateRange : [ '2017-01-01' , '2017-01-10' ]
810+ } ,
811+ {
812+ dimension : 'visitors.created_at' ,
813+ granularity : 'day' ,
814+ dateRange : [ '2017-01-01' , '2017-01-10' ]
815+ }
816+ ] ,
817+ order : [ {
818+ id : 'visitors.created_at'
819+ } ] ,
820+ timezone : 'America/Los_Angeles'
821+ } , [
822+ {
823+ visitors__count_rolling_week_to_date : null ,
824+ visitors__created_at_day : '2017-01-01T00:00:00.000Z' ,
825+ visitors__created_at_three_days : '2017-01-01T00:00:00.000Z' ,
826+ } ,
827+ {
828+ visitors__count_rolling_week_to_date : '1' ,
829+ visitors__created_at_day : '2017-01-02T00:00:00.000Z' ,
830+ visitors__created_at_three_days : '2017-01-01T00:00:00.000Z' ,
831+ } ,
832+ {
833+ visitors__count_rolling_week_to_date : '1' ,
834+ visitors__created_at_day : '2017-01-03T00:00:00.000Z' ,
835+ visitors__created_at_three_days : '2017-01-01T00:00:00.000Z' ,
836+ } ,
837+ {
838+ visitors__count_rolling_week_to_date : '2' ,
839+ visitors__created_at_day : '2017-01-04T00:00:00.000Z' ,
840+ visitors__created_at_three_days : '2017-01-04T00:00:00.000Z' ,
841+ } ,
842+ {
843+ visitors__count_rolling_week_to_date : '3' ,
844+ visitors__created_at_day : '2017-01-05T00:00:00.000Z' ,
845+ visitors__created_at_three_days : '2017-01-04T00:00:00.000Z' ,
846+ } ,
847+ {
848+ visitors__count_rolling_week_to_date : '5' ,
849+ visitors__created_at_day : '2017-01-06T00:00:00.000Z' ,
850+ visitors__created_at_three_days : '2017-01-04T00:00:00.000Z' ,
851+ } ,
852+ {
853+ visitors__count_rolling_week_to_date : '5' ,
854+ visitors__created_at_day : '2017-01-07T00:00:00.000Z' ,
855+ visitors__created_at_three_days : '2017-01-07T00:00:00.000Z' ,
856+ } ,
857+ {
858+ visitors__count_rolling_week_to_date : '5' ,
859+ visitors__created_at_day : '2017-01-08T00:00:00.000Z' ,
860+ visitors__created_at_three_days : '2017-01-07T00:00:00.000Z' ,
861+ } ,
862+ {
863+ visitors__count_rolling_week_to_date : null ,
864+ visitors__created_at_day : '2017-01-09T00:00:00.000Z' ,
865+ visitors__created_at_three_days : '2017-01-07T00:00:00.000Z' ,
866+ } ,
867+ {
868+ visitors__count_rolling_week_to_date : null ,
869+ visitors__created_at_day : '2017-01-10T00:00:00.000Z' ,
870+ visitors__created_at_three_days : '2017-01-10T00:00:00.000Z' ,
871+ }
872+ ] ) ) ;
873+
874+ it ( 'two rolling windows with two time dimension granularities' , async ( ) => runQueryTest ( {
875+ measures : [
876+ 'visitors.countRollingUnbounded' ,
877+ 'visitors.countRollingWeekToDate'
878+ ] ,
879+ timeDimensions : [
880+ {
881+ dimension : 'visitors.created_at' ,
882+ granularity : 'three_days' ,
883+ dateRange : [ '2017-01-01' , '2017-01-10' ]
884+ } ,
885+ {
886+ dimension : 'visitors.created_at' ,
887+ granularity : 'day' ,
888+ dateRange : [ '2017-01-01' , '2017-01-10' ]
889+ }
890+ ] ,
891+ order : [ {
892+ id : 'visitors.created_at'
893+ } ] ,
894+ timezone : 'America/Los_Angeles'
895+ } , [
896+ {
897+ visitors__count_rolling_unbounded : '1' ,
898+ visitors__count_rolling_week_to_date : null ,
899+ visitors__created_at_day : '2017-01-01T00:00:00.000Z' ,
900+ visitors__created_at_three_days : '2017-01-01T00:00:00.000Z' ,
901+ } ,
902+ {
903+ visitors__count_rolling_unbounded : '2' ,
904+ visitors__count_rolling_week_to_date : '1' ,
905+ visitors__created_at_day : '2017-01-03T00:00:00.000Z' ,
906+ visitors__created_at_three_days : '2017-01-01T00:00:00.000Z' ,
907+ } ,
908+ {
909+ visitors__count_rolling_unbounded : '2' ,
910+ visitors__count_rolling_week_to_date : '1' ,
911+ visitors__created_at_day : '2017-01-02T00:00:00.000Z' ,
912+ visitors__created_at_three_days : '2017-01-01T00:00:00.000Z' ,
913+ } ,
914+ {
915+ visitors__count_rolling_unbounded : '3' ,
916+ visitors__count_rolling_week_to_date : '2' ,
917+ visitors__created_at_day : '2017-01-04T00:00:00.000Z' ,
918+ visitors__created_at_three_days : '2017-01-04T00:00:00.000Z' ,
919+ } ,
920+ {
921+ visitors__count_rolling_unbounded : '4' ,
922+ visitors__count_rolling_week_to_date : '3' ,
923+ visitors__created_at_day : '2017-01-05T00:00:00.000Z' ,
924+ visitors__created_at_three_days : '2017-01-04T00:00:00.000Z' ,
925+ } ,
926+ {
927+ visitors__count_rolling_unbounded : '6' ,
928+ visitors__count_rolling_week_to_date : '5' ,
929+ visitors__created_at_day : '2017-01-06T00:00:00.000Z' ,
930+ visitors__created_at_three_days : '2017-01-04T00:00:00.000Z' ,
931+ } ,
932+ {
933+ visitors__count_rolling_unbounded : '6' ,
934+ visitors__count_rolling_week_to_date : '5' ,
935+ visitors__created_at_day : '2017-01-08T00:00:00.000Z' ,
936+ visitors__created_at_three_days : '2017-01-07T00:00:00.000Z' ,
937+ } ,
938+ {
939+ visitors__count_rolling_unbounded : '6' ,
940+ visitors__count_rolling_week_to_date : '5' ,
941+ visitors__created_at_day : '2017-01-07T00:00:00.000Z' ,
942+ visitors__created_at_three_days : '2017-01-07T00:00:00.000Z' ,
943+ } ,
944+ {
945+ visitors__count_rolling_unbounded : '6' ,
946+ visitors__count_rolling_week_to_date : null ,
947+ visitors__created_at_day : '2017-01-09T00:00:00.000Z' ,
948+ visitors__created_at_three_days : '2017-01-07T00:00:00.000Z' ,
949+ } ,
950+ {
951+ visitors__count_rolling_unbounded : '6' ,
952+ visitors__count_rolling_week_to_date : null ,
953+ visitors__created_at_day : '2017-01-10T00:00:00.000Z' ,
954+ visitors__created_at_three_days : '2017-01-10T00:00:00.000Z' ,
955+ }
956+ ] ) ) ;
957+
781958 it ( 'rolling month' , async ( ) => runQueryTest ( {
782959 measures : [
783960 'visitors.revenueRollingThreeDay'
0 commit comments