Skip to content

Commit

Permalink
Replace sessions with raw_sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Mar 20, 2024
1 parent c04516d commit 6fe657b
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,40 @@ def test_handles_select_with_eq(self):
inliner = SessionWhereClauseExtractor()
actual = f(inliner.get_inner_where(parse_select("SELECT * FROM sessions WHERE min_timestamp = '2021-01-01'")))
expected = f(
"((sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-01') AND ((sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01')"
"((raw_sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-01') AND ((raw_sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01')"
)
assert expected == actual

def test_handles_select_with_eq_flipped(self):
inliner = SessionWhereClauseExtractor()
actual = f(inliner.get_inner_where(parse_select("SELECT * FROM sessions WHERE '2021-01-01' = min_timestamp")))
expected = f(
"((sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-01') AND ((sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01')"
"((raw_sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-01') AND ((raw_sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01')"
)
assert expected == actual

def test_handles_select_with_simple_gt(self):
inliner = SessionWhereClauseExtractor()
actual = f(inliner.get_inner_where(parse_select("SELECT * FROM sessions WHERE min_timestamp > '2021-01-01'")))
expected = f("((sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01')")
expected = f("((raw_sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01')")
assert expected == actual

def test_handles_select_with_simple_gte(self):
inliner = SessionWhereClauseExtractor()
actual = f(inliner.get_inner_where(parse_select("SELECT * FROM sessions WHERE min_timestamp >= '2021-01-01'")))
expected = f("((sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01')")
expected = f("((raw_sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01')")
assert expected == actual

def test_handles_select_with_simple_lt(self):
inliner = SessionWhereClauseExtractor()
actual = f(inliner.get_inner_where(parse_select("SELECT * FROM sessions WHERE min_timestamp < '2021-01-01'")))
expected = f("((sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-01')")
expected = f("((raw_sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-01')")
assert expected == actual

def test_handles_select_with_simple_lte(self):
inliner = SessionWhereClauseExtractor()
actual = f(inliner.get_inner_where(parse_select("SELECT * FROM sessions WHERE min_timestamp <= '2021-01-01'")))
expected = f("((sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-01')")
expected = f("((raw_sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-01')")
assert expected == actual

def test_select_with_placeholder(self):
Expand All @@ -76,7 +76,7 @@ def test_select_with_placeholder(self):
)
)
)
expected = f("((sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01')")
expected = f("((raw_sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01')")
assert expected == actual

def test_unrelated_equals(self):
Expand All @@ -96,7 +96,7 @@ def test_timestamp_and(self):
)
)
expected = f(
"((sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01') AND ((sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-03')"
"((raw_sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-01') AND ((raw_sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-03')"
)
assert expected == actual

Expand All @@ -110,7 +110,7 @@ def test_timestamp_or(self):
)
)
expected = f(
"((sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-01') AND ((sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-03')"
"((raw_sessions.min_timestamp - toIntervalDay(3)) <= '2021-01-01') AND ((raw_sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-03')"
)
assert expected == actual

Expand Down Expand Up @@ -153,57 +153,57 @@ def test_ambiguous_and(self):
)
)
)
assert actual == f("(sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-03'")
assert actual == f("(raw_sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-03'")

def test_join(self):
inliner = SessionWhereClauseExtractor()
actual = f(
inliner.get_inner_where(
parse_select(
"SELECT * FROM events JOIN sessions ON events.session_id = sessions.session_id WHERE min_timestamp > '2021-01-03'"
"SELECT * FROM events JOIN sessions ON events.session_id = raw_sessions.session_id WHERE min_timestamp > '2021-01-03'"
)
)
)
expected = f("((sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-03')")
expected = f("((raw_sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-03')")
assert expected == actual

def test_join_using_events_timestamp_filter(self):
inliner = SessionWhereClauseExtractor()
actual = f(
inliner.get_inner_where(
parse_select(
"SELECT * FROM events JOIN sessions ON events.session_id = sessions.session_id WHERE timestamp > '2021-01-03'"
"SELECT * FROM events JOIN sessions ON events.session_id = raw_sessions.session_id WHERE timestamp > '2021-01-03'"
)
)
)
expected = f("((sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-03')")
expected = f("((raw_sessions.min_timestamp + toIntervalDay(3)) >= '2021-01-03')")
assert expected == actual

def test_minus(self):
inliner = SessionWhereClauseExtractor()
actual = f(inliner.get_inner_where(parse_select("SELECT * FROM sessions WHERE min_timestamp >= today() - 2")))
expected = f("((sessions.min_timestamp + toIntervalDay(3)) >= (today() - 2))")
expected = f("((raw_sessions.min_timestamp + toIntervalDay(3)) >= (today() - 2))")
assert expected == actual

def test_minus_function(self):
inliner = SessionWhereClauseExtractor()
actual = f(
inliner.get_inner_where(parse_select("SELECT * FROM sessions WHERE min_timestamp >= minus(today() , 2)"))
)
expected = f("((sessions.min_timestamp + toIntervalDay(3)) >= minus(today(), 2))")
expected = f("((raw_sessions.min_timestamp + toIntervalDay(3)) >= minus(today(), 2))")
assert expected == actual

def test_real_example(self):
inliner = SessionWhereClauseExtractor()
actual = f(
inliner.get_inner_where(
parse_select(
"SELECT * FROM events JOIN sessions ON events.session_id = sessions.session_id WHERE event = '$pageview' AND toTimeZone(timestamp, 'US/Pacific') >= toDateTime('2024-03-12 00:00:00', 'US/Pacific') AND toTimeZone(timestamp, 'US/Pacific') <= toDateTime('2024-03-19 23:59:59', 'US/Pacific')"
"SELECT * FROM events JOIN sessions ON events.session_id = raw_sessions.session_id WHERE event = '$pageview' AND toTimeZone(timestamp, 'US/Pacific') >= toDateTime('2024-03-12 00:00:00', 'US/Pacific') AND toTimeZone(timestamp, 'US/Pacific') <= toDateTime('2024-03-19 23:59:59', 'US/Pacific')"
)
)
)
expected = f(
"(toTimeZone(sessions.min_timestamp, 'US/Pacific') + toIntervalDay(3)) >= toDateTime('2024-03-12 00:00:00', 'US/Pacific') AND (toTimeZone(sessions.min_timestamp, 'US/Pacific') - toIntervalDay(3)) <= toDateTime('2024-03-19 23:59:59', 'US/Pacific') "
"(toTimeZone(raw_sessions.min_timestamp, 'US/Pacific') + toIntervalDay(3)) >= toDateTime('2024-03-12 00:00:00', 'US/Pacific') AND (toTimeZone(raw_sessions.min_timestamp, 'US/Pacific') - toIntervalDay(3)) <= toDateTime('2024-03-19 23:59:59', 'US/Pacific') "
)
assert expected == actual

Expand Down

0 comments on commit 6fe657b

Please sign in to comment.