From 1c26581cd1172874aa07655e517d322e9ae06016 Mon Sep 17 00:00:00 2001 From: Brian Cao Date: Fri, 22 Jul 2022 19:50:43 -0700 Subject: [PATCH] fix parseFilters --- .../analytics/pageview/getPageviewParams.js | 25 +++++++++++-------- .../analytics/pageview/getPageviewStats.js | 1 + .../analytics/session/getSessionMetrics.js | 1 + queries/analytics/stats/getWebsiteStats.js | 1 + 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/queries/analytics/pageview/getPageviewParams.js b/queries/analytics/pageview/getPageviewParams.js index 827141b9..fd25c77e 100644 --- a/queries/analytics/pageview/getPageviewParams.js +++ b/queries/analytics/pageview/getPageviewParams.js @@ -1,15 +1,14 @@ -import { getDatabase, parseFilters, rawQuery } from 'lib/db'; -import { MYSQL, POSTGRESQL } from 'lib/constants'; +import { getDatabase, parseFilters, rawQuery, runAnalyticsQuery } from 'lib/db'; +import { MYSQL, POSTGRESQL, CLICKHOUSE, RELATIONAL } from 'lib/constants'; -export function getPageviewParams( - param, - website_id, - start_at, - end_at, - column, - table, - filters = {}, -) { +export async function getPageviewParams(...args) { + return runAnalyticsQuery({ + [`${RELATIONAL}`]: () => relationalQuery(...args), + [`${CLICKHOUSE}`]: () => clickhouseQuery(...args), + }); +} + +function relationalQuery(param, website_id, start_at, end_at, column, table, filters = {}) { const params = [param, website_id, start_at, end_at]; const { pageviewQuery, sessionQuery, eventQuery, joinSession } = parseFilters( table, @@ -43,3 +42,7 @@ export function getPageviewParams( params, ); } + +function clickhouseQuery() { + return Promise.reject(new Error('Not implemented.')); +} diff --git a/queries/analytics/pageview/getPageviewStats.js b/queries/analytics/pageview/getPageviewStats.js index 1591e5d2..1cca2fca 100644 --- a/queries/analytics/pageview/getPageviewStats.js +++ b/queries/analytics/pageview/getPageviewStats.js @@ -64,6 +64,7 @@ async function clickhouseQuery( const params = [website_id]; const { pageviewQuery, sessionQuery, joinSession } = parseFilters( 'pageview', + null, filters, params, sessionKey, diff --git a/queries/analytics/session/getSessionMetrics.js b/queries/analytics/session/getSessionMetrics.js index 5defb207..b9bbc708 100644 --- a/queries/analytics/session/getSessionMetrics.js +++ b/queries/analytics/session/getSessionMetrics.js @@ -47,6 +47,7 @@ async function clickhouseQuery(website_id, start_at, end_at, field, filters = {} const params = [website_id]; const { pageviewQuery, sessionQuery, joinSession } = parseFilters( 'pageview', + null, filters, params, 'session_uuid', diff --git a/queries/analytics/stats/getWebsiteStats.js b/queries/analytics/stats/getWebsiteStats.js index 815bacdd..53e90b51 100644 --- a/queries/analytics/stats/getWebsiteStats.js +++ b/queries/analytics/stats/getWebsiteStats.js @@ -59,6 +59,7 @@ async function clickhouseQuery(website_id, start_at, end_at, filters = {}) { const params = [website_id]; const { pageviewQuery, sessionQuery, joinSession } = parseFilters( 'pageview', + null, filters, params, 'session_uuid',