fix clickhouse date timezone issues

This commit is contained in:
Francis Cao 2022-08-08 22:09:18 -07:00
parent fc3c39be3c
commit 55ba7d95ab
7 changed files with 7647 additions and 4840 deletions

View file

@ -1,6 +1,7 @@
import { PrismaClient } from '@prisma/client';
import { ClickHouse } from 'clickhouse';
import { Kafka } from 'kafkajs';
import dateFormat from 'dateformat';
import chalk from 'chalk';
import {
MYSQL,
@ -164,13 +165,13 @@ export function getDateQuery(field, unit, timezone) {
export function getDateQueryClickhouse(field, unit, timezone) {
if (timezone) {
return `date_trunc('${unit}', ${field},'${timezone}')`;
return `date_trunc('${unit}', ${field}, '${timezone}')`;
}
return `date_trunc('${unit}', ${field})`;
}
export function getDateFormatClickhouse(date) {
return `parseDateTimeBestEffort('${date.toUTCString()}')`;
return `'${dateFormat(date, 'UTC:yyyy-mm-dd HH:MM:ss')}'`;
}
export function getBetweenDatesClickhouse(field, start_at, end_at) {
@ -357,3 +358,7 @@ export async function kafkaProducer(params, topic) {
],
});
}
export function getDateFormatKafka(date) {
return dateFormat(date, 'UTC:yyyy-mm-dd HH:MM:ss');
}