update CH rawquery and type

This commit is contained in:
Francis Cao 2023-09-29 11:00:06 -07:00
parent d13f0bc5fe
commit e2bb2defd4
17 changed files with 169 additions and 52 deletions

View file

@ -47,7 +47,11 @@ async function relationalQuery(websiteId: string, column: string, filters: Query
);
}
async function clickhouseQuery(websiteId: string, column: string, filters: QueryFilters) {
async function clickhouseQuery(
websiteId: string,
column: string,
filters: QueryFilters,
): Promise<{ x: string; y: number }[]> {
const { parseFilters, rawQuery } = clickhouse;
const { filterQuery, params } = await parseFilters(websiteId, {
...filters,
@ -63,7 +67,6 @@ async function clickhouseQuery(websiteId: string, column: string, filters: Query
${includeCountry ? ', country' : ''}
from website_event
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime} and {endDate:DateTime}
and event_type = {eventType:UInt32}
${filterQuery}
group by x
@ -72,5 +75,9 @@ async function clickhouseQuery(websiteId: string, column: string, filters: Query
limit 100
`,
params,
);
).then(a => {
return Object.values(a).map(a => {
return { x: a.x, y: Number(a.y) };
});
});
}

View file

@ -36,7 +36,10 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
);
}
async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
async function clickhouseQuery(
websiteId: string,
filters: QueryFilters,
): Promise<{ x: string; y: number }[]> {
const { timezone = 'UTC', unit = 'day' } = filters;
const { parseFilters, rawQuery, getDateStringQuery, getDateQuery } = clickhouse;
const { filterQuery, params } = await parseFilters(websiteId, {
@ -55,7 +58,7 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
count(distinct session_id) as y
from website_event
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime} and {endDate:DateTime}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
and event_type = {eventType:UInt32}
${filterQuery}
group by t
@ -63,5 +66,9 @@ async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
order by t
`,
params,
);
).then(a => {
return Object.values(a).map(a => {
return { x: a.x, y: Number(a.y) };
});
});
}

View file

@ -42,7 +42,7 @@ async function clickhouseQuery(websiteId: string, startDate: Date) {
city
from website_event
where website_id = {websiteId:UUID}
and created_at >= {startDate:DateTime}
and created_at >= {startDate:DateTime64}
`,
{
websiteId,