Skip to content

Commit

Permalink
fix: substring correctly (#130)
Browse files Browse the repository at this point in the history
### TL;DR
Fixed incorrect string slicing in ClickHouse filter parameters for 'gte' and 'lte' conditions.

### What changed?
Modified the string slicing length in `addFilterParams` function from `-3` to `-4` for 'gte' and 'lte' suffixes to properly extract the base column name from filter parameters.

### How to test?
1. Execute queries using filters with 'gte' and 'lte' suffixes
2. Verify that the generated SQL queries contain the correct column names
3. Confirm that filter conditions are properly applied to the results

### Why make this change?
The previous implementation was incorrectly slicing the column names for 'gte' and 'lte' conditions, which could lead to malformed SQL queries. This fix ensures proper column name extraction and maintains consistency with the filter parameter naming convention.
  • Loading branch information
catalyst17 authored Dec 20, 2024
2 parents 996d70b + 1ab5a4e commit 0de561b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/storage/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ func addFilterParams(key, value, query string) string {
suffix := key[len(key)-3:]
switch suffix {
case "gte":
query += fmt.Sprintf(" AND %s >= '%s'", key[:len(key)-3], value)
query += fmt.Sprintf(" AND %s >= '%s'", key[:len(key)-4], value)
case "lte":
query += fmt.Sprintf(" AND %s <= '%s'", key[:len(key)-3], value)
query += fmt.Sprintf(" AND %s <= '%s'", key[:len(key)-4], value)
case "_lt":
query += fmt.Sprintf(" AND %s < '%s'", key[:len(key)-3], value)
case "_gt":
Expand Down

0 comments on commit 0de561b

Please sign in to comment.