Skip to content

Commit

Permalink
Merge pull request #134 from HTTPArchive/fix-timeseries-date-range-re…
Browse files Browse the repository at this point in the history
…prots

Fix bug in time series reports where date range was not used correctly
  • Loading branch information
tunetheweb authored Aug 29, 2021
2 parents b9cd7ca + e3b8865 commit 5a6c6f9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sql/generate_reports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,17 @@ else
fi

if [[ -n "${date_join}" ]]; then
result=$(sed -e "s/\(WHERE\)/\1 $date_join AND/" $query \
| sed -e "s/\(\`[^\`]*\`)*\)/\1 $lens_join/" \
| $BQ_CMD)
if [[ $(grep -i "WHERE" $query) ]]; then
# If WHERE clause already exists then add to it, before GROUP BY
result=$(sed -e "s/\(WHERE\)/\1 $date_join AND/" $query \
| sed -e "s/\(\`[^\`]*\`)*\)/\1 $lens_join/" \
| $BQ_CMD)
else
# If WHERE clause doesn't exists then add it, before GROUP BY
result=$(sed -e "s/\(GROUP BY\)/WHERE $date_join \1/" $query \
| sed -e "s/\(\`[^\`]*\`)*\)/\1 $lens_join/" \
| $BQ_CMD)
fi
else
result=$(sed -e "s/\(\`[^\`]*\`)*\)/\1 $lens_join/" $query \
| $BQ_CMD)
Expand Down

0 comments on commit 5a6c6f9

Please sign in to comment.