Skip to content

Commit

Permalink
Merge pull request #17 from avantifellows/minor-fixes
Browse files Browse the repository at this point in the history
FIX: completed the appropriate joins
  • Loading branch information
dalmia authored May 25, 2021
2 parents f4afdf7 + 6485941 commit f870bc1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
node_modules
/dist
dist/

# local env files
.env.local
Expand Down
23 changes: 20 additions & 3 deletions schema/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ cube(`GroupedSession`, {
sql: `
WITH summary AS (
SELECT
session.id,
session.id AS session_id,
session.plio_id,
session.user_id,
session.watch_time,
Expand All @@ -97,6 +97,11 @@ cube(`GroupedSession`, {
sql: `${CUBE}.user_id = ${User}.id`,
relationship: `belongsTo`,
},

Session: {
sql: `${CUBE}.session_id = ${Session}.id`,
relationship: `belongsTo`,
},
},

measures: {
Expand All @@ -111,7 +116,7 @@ cube(`GroupedSession`, {
},
dimensions: {
id: {
sql: `id`,
sql: `session_id`,
type: `number`,
primaryKey: true,
},
Expand All @@ -122,6 +127,7 @@ cube(`GroupedSessionRetention`, {
sql: `
SELECT
ROW_NUMBER() OVER (ORDER BY user_id, plio_id) as id,
session_id,
plio_id,
user_id,
SUM(retention_array) as postOneMinuteRetentionSum
Expand All @@ -131,6 +137,7 @@ cube(`GroupedSessionRetention`, {
*
FROM (
SELECT
session_id,
plio_id,
user_id,
UNNEST(string_to_array(retention, ','))::int AS retention_array
Expand All @@ -139,7 +146,7 @@ cube(`GroupedSessionRetention`, {
) AS B
) AS C
WHERE index >= 60
GROUP BY plio_id, user_id
GROUP BY plio_id, user_id, session_id
`,

joins: {
Expand All @@ -152,6 +159,16 @@ cube(`GroupedSessionRetention`, {
sql: `${CUBE}.user_id = ${User}.id`,
relationship: `belongsTo`,
},

Session: {
sql: `${CUBE}.session_id = ${Session}.id`,
relationship: `belongsTo`,
},

GroupedSession: {
sql: `${CUBE}.session_id = ${GroupedSession}.session_id`,
relationship: `belongsTo`,
},
},

measures: {
Expand Down
4 changes: 2 additions & 2 deletions schema/SessionAnswer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cube(`SessionAnswer`, {
cube(`GroupedSessionAnswer`, {
sql: `
SELECT
session.id AS session_id,
session.session_id,
session.plio_id,
session.user_id,
sessionAnswer.id,
Expand All @@ -61,7 +61,7 @@ cube(`GroupedSessionAnswer`, {
question.correct_answer AS question_correct_answer
FROM ${GroupedSession.sql()} AS session
INNER JOIN ${SessionAnswer.sql()} as sessionAnswer
ON session.id=sessionAnswer.session_id
ON session.session_id=sessionAnswer.session_id
INNER JOIN ${Item.sql()} as item
ON item.id=sessionAnswer.item_id
INNER JOIN ${Question.sql()} as question ON question.item_id = item.id`,
Expand Down

0 comments on commit f870bc1

Please sign in to comment.