I am trying to return data grouped roughly into months. The query I have specified I think should return data between Jan 1, 2018 and December 31, 2018 grouped roughly by month. Here is the query I am using:
SELECT sum(“main_dwh”)-sum(“solar_dwh”) FROM “btmonnew”.“autogen”.“energynew” WHERE time >= 1514782800000ms and time <= 1546318799000ms GROUP BY time(730h) fill(null)
What I don’t understand is why I am getting data returned from December of 2017. It doesn’t seem to make difference weather I group by minutes, hours or days.
The exact query I am using is in the original post, and there is no offset. If it helps I am in Eastern standard time (-5 GMT), but I am not sure how or why that would return data from December 19th. The timestamps in the query refer to local time (-5gmt), so I guess if anything I might be seeing 5 hours of data from Jan 2019.
@adamalli I see that. I didn’t realize that first date was in 2017. Your instinct to check the group_by was right. It seems related to this issue regarding group_by on GitHub.
First off …you query contains GROUP BY time(730h), which is like 30.41 days So maybe you want to have it 720h? …however even with that … But more importantly…influxdb does NOT natively support grouping by one month as per issue 3991 And even more importantly, you realize that not every month has 720 hours, right?
January (30 days) has indeed 720 hours
February (28/29 days) has 672/696 hours
April (31 days) month has 744 hours
And because of this fact, the data is being shifted back and forth and that’s why the output is so weird.
Therefore using “GROUP BY time(720h)” is NOT the same as you would group it by 1 month
Yes I know Influxdb can’t group by month, hence why I am doing it by 730h as that is the best we can do right now. And I know this won’t get me actual calendar months, but I don’t really have a better option. If you take 8760 hours and divide by 12 you get 730h, so it is a rough approximation.
That still doesn’t explain why I am getting data returned before my start date. The time interval I picked with the grouping should fit evenly. So with the math above I should get exactly 12 data points returned all within my selected time period. Instead I get 13 data points returned including the first point starting before my selected time period. And it isn’t off by just a little, it is almost 12 days, so not a timezone problem.