FrankChen021 / bithon

An observability platform mainly for Java
Apache License 2.0
14 stars 4 forks source link

Not able to use built-in expression as filter #710

Open FrankChen021 opened 5 months ago

FrankChen021 commented 5 months ago
jOOQ; bad SQL grammar [
SELECT UNIX_TIMESTAMP("timestamp")/ 10 * 10 AS "_timestamp",round(sum("totalCount") / 10, 2) AS "qps",
sum("okCount") / 10 AS "okQPS",
sum("totalCount") AS "totalCount" 
FROM "bithon_http_incoming_metrics" 
WHERE 
"timestamp" >= '2024-01-20T15:38:36.411+08:00' AND "timestamp" < '2024-01-20T15:43:36.411+08:00' 
AND ("bithon_http_incoming_metrics"."avgResponseTime" > 50 
AND "bithon_http_incoming_metrics"."instanceName" = '192.168.50.150:9897') 
GROUP BY "_timestamp" ORDER BY "_timestamp"
]; 
nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "bithon_http_incoming_metrics.avgResponseTime" not found; 

The reason is that the filter expression is not defined at the storage layer. We have to generate a virtual column in the SQL and add a HAVING clause to filter it.