fix: handle toFloat on numeric fields
This commit is contained in:
@@ -267,43 +267,22 @@ export function getChartSql({
|
|||||||
'COUNT(*)::float / COUNT(DISTINCT profile_id)::float as count';
|
'COUNT(*)::float / COUNT(DISTINCT profile_id)::float as count';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.segment === 'property_sum' && event.property) {
|
const mathFunction = {
|
||||||
if (event.property === 'revenue') {
|
property_sum: 'sum',
|
||||||
sb.select.count = 'sum(revenue) as count';
|
property_average: 'avg',
|
||||||
sb.where.property = 'revenue > 0';
|
property_max: 'max',
|
||||||
} else {
|
property_min: 'min',
|
||||||
sb.select.count = `sum(toFloat64(${getSelectPropertyKey(event.property)})) as count`;
|
}[event.segment as string];
|
||||||
sb.where.property = `${getSelectPropertyKey(event.property)} IS NOT NULL AND notEmpty(${getSelectPropertyKey(event.property)})`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.segment === 'property_average' && event.property) {
|
if (mathFunction && event.property) {
|
||||||
if (event.property === 'revenue') {
|
const propertyKey = getSelectPropertyKey(event.property);
|
||||||
sb.select.count = 'avg(revenue) as count';
|
|
||||||
sb.where.property = 'revenue > 0';
|
|
||||||
} else {
|
|
||||||
sb.select.count = `avg(toFloat64(${getSelectPropertyKey(event.property)})) as count`;
|
|
||||||
sb.where.property = `${getSelectPropertyKey(event.property)} IS NOT NULL AND notEmpty(${getSelectPropertyKey(event.property)})`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.segment === 'property_max' && event.property) {
|
if (isNumericColumn(event.property)) {
|
||||||
if (event.property === 'revenue') {
|
sb.select.count = `${mathFunction}(${propertyKey}) as count`;
|
||||||
sb.select.count = 'max(revenue) as count';
|
sb.where.property = `${propertyKey} IS NOT NULL`;
|
||||||
sb.where.property = 'revenue > 0';
|
|
||||||
} else {
|
} else {
|
||||||
sb.select.count = `max(toFloat64(${getSelectPropertyKey(event.property)})) as count`;
|
sb.select.count = `${mathFunction}(toFloat64OrNull(${propertyKey})) as count`;
|
||||||
sb.where.property = `${getSelectPropertyKey(event.property)} IS NOT NULL AND notEmpty(${getSelectPropertyKey(event.property)})`;
|
sb.where.property = `${propertyKey} IS NOT NULL AND notEmpty(${propertyKey})`;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.segment === 'property_min' && event.property) {
|
|
||||||
if (event.property === 'revenue') {
|
|
||||||
sb.select.count = 'min(revenue) as count';
|
|
||||||
sb.where.property = 'revenue > 0';
|
|
||||||
} else {
|
|
||||||
sb.select.count = `min(toFloat64(${getSelectPropertyKey(event.property)})) as count`;
|
|
||||||
sb.where.property = `${getSelectPropertyKey(event.property)} IS NOT NULL AND notEmpty(${getSelectPropertyKey(event.property)})`;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user