3
0

Fix filter nesting for chart filters

This commit is contained in:
Tomaž Jerman
2020-05-27 13:40:27 +02:00
parent 2b3b2f1755
commit f69ffe01d3
2 changed files with 6 additions and 2 deletions
+5 -1
View File
@@ -150,7 +150,11 @@ func (b *recordReportBuilder) Build(metrics, dimensions, filters string) (sql st
return
}
b.report = b.report.Where(filter)
// We need to wrap this one level deeper, since additional filters should
// be evaluated as a whole.
// For example A AND B OR C =should be> (A AND B OR C)
// so the output becomes BASE AND (ADDITIONAL)
b.report = b.report.Where(ql.ASTNodes{filter})
}
return b.report.ToSql()
@@ -24,7 +24,7 @@ func TestRecordReportBuilder2(t *testing.T) {
"FROM compose_record AS r " +
"LEFT JOIN compose_record_value AS rv_single1 ON (rv_single1.record_id = r.id AND rv_single1.name = ? AND rv_single1.deleted_at IS NULL) " +
"LEFT JOIN compose_record_value AS rv_ref1 ON (rv_ref1.record_id = r.id AND rv_ref1.name = ? AND rv_ref1.deleted_at IS NULL) " +
"WHERE r.deleted_at IS NULL AND r.module_id = ? AND rv_ref1.value = 2 " +
"WHERE r.deleted_at IS NULL AND r.module_id = ? AND (rv_ref1.value = 2) " +
"GROUP BY dimension_0 " +
"ORDER BY dimension_0"