
#DEFINE NUM_FRAGMENTS_Q1 32
#DEFINE Q1_BUFFERSIZE 100000
#INTEROPERATORPARALLELIZATION TripCellCounter ${NUM_FRAGMENTS_Q1} ${Q1_BUFFERSIZE} GroupedAggregateMultithreadedTransformationStrategy

#ADDQUERY
query1_start = BUFFER({
                      name="Q1_BUFFER",
                      threaded = true,
                      drainatclose = false,
                      maxbuffersize = ${Q1_BUFFERSIZE}
                    },
                    taxi
                )


cell_reduction = MAP({
                      expressions = [
							'pickup_datetime','dropoff_datetime',				                      							                        
							['ceil(pickup_cell_x/2) * 
						 	      ${ID_LEFTSHIFT} + ceil(pickup_cell_y/2)', 'pickup_cell_id'],
                            ['ceil(dropoff_cell_x/2) * 
                                  ${ID_LEFTSHIFT} + ceil(dropoff_cell_y/2)', 'dropoff_cell_id']
                      ]                  
                    },
                    query1_start
                  )				

cell_id_calc = TIMEWINDOW({
                    size = [30, 'MINUTES']                                                                                                                                
                  },
                  cell_reduction
                )			
            
                                
num_trips_per_cellpair = AGGREGATE({
							  id = "TripCellCounter",
                              name = "TripCellCounter",
                              aggregations = [
                                ['LAST', 'pickup_datetime', 'pickup_datetime', 'Date'],
                                ['LAST', 'dropoff_datetime', 'dropoff_datetime', 'Date'],
                                ['COUNT', 'pickup_datetime', 'count']
                              ],
                              group_by = [
								'pickup_cell_id', 'dropoff_cell_id'                                                                                                                                            
                              ],
                              fastgrouping = false                                                                                                                            
                            },
                            cell_id_calc
                          )

                          
                          
                          