Skip to content
Snippets Groups Projects
Commit 2af6ca0a authored by Cam Saül's avatar Cam Saül
Browse files

Fix postgres filtering by weeks [ci drivers]

parent 9513f7e6
No related merge requests found
......@@ -8,6 +8,7 @@
"F**k all this d**k swinging contest. We all gon be dead in 100 Years. Let the kids have the music."
"Fur pillows are hard to actually sleep on."
"Here's something that's contrary to popular belief: I actually don't like thinking. I think people think I like to think a lot. And I don't. I do not like to think at all."
"Hi Grammys this is the most important living artist talking."
"How many m*****f***ers you done seen with a leather jogging pant?"
"I actually don't like thinking. I think people think I like to think a lot. And I don't. I do not like to think at all."
"I am God's vessel. But my greatest pain in life is that I will never be able to see myself perform live."
......@@ -47,6 +48,7 @@
"I'm a pop enigma. I live and breathe every element in life. I rock a bespoke suit and I go to Harold's for fried chicken. It's all these things at once, because, as a taste maker, I find the best of everything."
"I'm doing pretty good as far as geniuses go... I'm like a machine. I'm a robot. You cannot offend a robot."
"I'm going to be the Tupac of clothing."
"I'm not even gon lie to you. I love me so much right now."
"I'm pretty calculating. I take stuff that I know appeals to people's bad sides and match it up with stuff that appeals to their good sides."
"I'm the closest that hip-hop is getting to God. In some situations I'm like a ghetto Pope."
"If I was just a fan of music, I would think that I was the number one artist in the world."
......@@ -76,6 +78,7 @@
"Sometimes people write novels and they just be so wordy and so self-absorbed."
"The Bible had 20, 30, 40, 50 characters in it. You don't think that I would be one of the characters of today's modern Bible?"
"The concept of commercialism in the fashion and art world is looked down upon. You know, just to think, 'What amount of creativity does it take to make something that masses of people like?' And, 'How does creativity apply across the board?'"
"The world needs a guy like me. The world needs somebody to not be scared and tell his truth."
"There are some lame fake accounts trying to make Kanye-isms that are not Mark Twain level."
"There's nothing I really wanted to do in life that I wasn't able to get good at. That's my skill. I'm not really specifically talented at anything except for the ability to learn. That's what I do. That's what I'm here for."
"They say you can rap about anything except for Jesus, that means guns, sex, lies, video tapes, but if I talk about God my record won't get played Huh?"
......
......@@ -114,8 +114,8 @@
:seconds (hsql/call :to_timestamp expr)
:milliseconds (recur (hx// expr 1000) :seconds)))
(defn- date-trunc [unit expr] (hsql/call :date_trunc (hx/literal unit) (hx/cast :timestamp expr)))
(defn- extract [unit expr] (hsql/call :extract unit (hx/cast :timestamp expr)))
(defn- date-trunc [unit expr] (hsql/call :date_trunc (hx/literal unit) (hx/->timestamp expr)))
(defn- extract [unit expr] (hsql/call :extract unit (hx/->timestamp expr)))
(def ^:private extract-integer (comp hx/->integer extract))
......@@ -134,9 +134,9 @@
:day-of-month (extract-integer :day expr)
:day-of-year (extract-integer :doy expr)
;; Postgres weeks start on Monday, so shift this date into the proper bucket and then decrement the resulting day
:week (hx/- (date-trunc :week (hx/+ expr one-day))
:week (hx/- (date-trunc :week (hx/+ (hx/->timestamp expr) one-day))
one-day)
:week-of-year (extract-integer :week (hx/+ expr one-day))
:week-of-year (extract-integer :week (hx/+ (hx/->timestamp expr) one-day))
:month (date-trunc :month expr)
:month-of-year (extract-integer :month expr)
:quarter (date-trunc :quarter expr)
......
......@@ -215,139 +215,186 @@
;; TODO - maybe it makes sense to have a separate namespace to test the Query eXpander so we don't need to run all these extra queries?
;;; =
(expect-with-non-timeseries-dbs [99] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/= $id 1)))))))
(expect-with-non-timeseries-dbs
[99]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/= $id 1)))))))
;;; !=
(expect-with-non-timeseries-dbs [1] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/!= $id 1)))))))
(expect-with-non-timeseries-dbs
[1]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/!= $id 1)))))))
;;; <
(expect-with-non-timeseries-dbs [61] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/< $id 40)))))))
(expect-with-non-timeseries-dbs
[61]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/< $id 40)))))))
;;; >
(expect-with-non-timeseries-dbs [40] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/> $id 40)))))))
(expect-with-non-timeseries-dbs
[40]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/> $id 40)))))))
;;; <=
(expect-with-non-timeseries-dbs [60] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/<= $id 40)))))))
(expect-with-non-timeseries-dbs
[60]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/<= $id 40)))))))
;;; >=
(expect-with-non-timeseries-dbs [39] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/>= $id 40)))))))
(expect-with-non-timeseries-dbs
[39]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/>= $id 40)))))))
;;; is-null
(expect-with-non-timeseries-dbs [100] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/is-null $id)))))))
(expect-with-non-timeseries-dbs
[100]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/is-null $id)))))))
;;; between
(expect-with-non-timeseries-dbs [89] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/between $id 30 40)))))))
(expect-with-non-timeseries-dbs
[89]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/between $id 30 40)))))))
;;; inside
(expect-with-non-timeseries-dbs [39] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/inside $latitude $longitude 40 -120 30 -110)))))))
(expect-with-non-timeseries-dbs
[39]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/inside $latitude $longitude 40 -120 30 -110)))))))
;;; starts-with
(expect-with-non-timeseries-dbs [80] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/starts-with $name "T")))))))
(expect-with-non-timeseries-dbs
[80]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/starts-with $name "T")))))))
;;; contains
(expect-with-non-timeseries-dbs [97] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/contains $name "BBQ")))))))
(expect-with-non-timeseries-dbs
[97]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/contains $name "BBQ")))))))
;;; does-not-contain
;; This should literally be the exact same query as the one above by the time it leaves the Query eXpander, so this is more of a QX test than anything else
(expect-with-non-timeseries-dbs [97] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/does-not-contain $name "BBQ"))))))
(expect-with-non-timeseries-dbs
[97]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/does-not-contain $name "BBQ"))))))
;;; ends-with
(expect-with-non-timeseries-dbs [87] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/ends-with $name "a")))))))
(expect-with-non-timeseries-dbs
[87]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/ends-with $name "a")))))))
;;; and
(expect-with-non-timeseries-dbs [98] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/and (ql/> $id 32)
(ql/contains $name "BBQ"))))))))
(expect-with-non-timeseries-dbs
[98]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/and (ql/> $id 32)
(ql/contains $name "BBQ"))))))))
;;; or
(expect-with-non-timeseries-dbs [31] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/or (ql/> $id 32)
(ql/contains $name "BBQ"))))))))
(expect-with-non-timeseries-dbs
[31]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/or (ql/> $id 32)
(ql/contains $name "BBQ"))))))))
;;; nested and/or
(expect-with-non-timeseries-dbs [96] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/or (ql/and (ql/> $id 32)
(ql/< $id 35))
(ql/contains $name "BBQ"))))))))
(expect-with-non-timeseries-dbs
[96]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/or (ql/and (ql/> $id 32)
(ql/< $id 35))
(ql/contains $name "BBQ"))))))))
;;; nested not
(expect-with-non-timeseries-dbs [3] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/not (ql/contains $name "BBQ"))))))))
(expect-with-non-timeseries-dbs
[3]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/not (ql/not (ql/contains $name "BBQ"))))))))
;;; not nested inside and/or
(expect-with-non-timeseries-dbs [1] (first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/and (ql/not (ql/> $id 32))
(ql/contains $name "BBQ")))))))
(expect-with-non-timeseries-dbs
[1]
(first-row
(format-rows-by [int]
(data/run-query venues
(ql/aggregation (ql/count))
(ql/filter (ql/and (ql/not (ql/> $id 32))
(ql/contains $name "BBQ")))))))
;; make sure that filtering with dates truncating to minutes works (#4632)
(expect-with-non-timeseries-dbs [107] (first-row
(format-rows-by [int]
(data/run-query checkins
(ql/aggregation (ql/count))
(ql/filter (ql/between (ql/datetime-field $date :minute) "2015-01-01T12:30:00" "2015-05-31"))))))
(expect-with-non-timeseries-dbs
[107]
(first-row
(format-rows-by [int]
(data/run-query checkins
(ql/aggregation (ql/count))
(ql/filter (ql/between (ql/datetime-field $date :minute) "2015-01-01T12:30:00" "2015-05-31"))))))
;; make sure that filtering with dates bucketing by weeks works (#4956)
(expect-with-non-timeseries-dbs
[7]
(first-row
(format-rows-by [int]
(data/run-query checkins
(ql/aggregation (ql/count))
(ql/filter (ql/= (ql/datetime-field $date :week) "2015-06-21T07:00:00.000000000-00:00"))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment