Skip to content

Conversation

@nikhilsinhaparseable
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Jan 28, 2026

  1. list type fields
  2. text with empty value
  3. boolean fields

Summary by CodeRabbit

  • New Features

    • Added an optional per-condition column type to improve handling of list vs scalar columns.
  • Refactor

    • Centralized per-condition expression generation for alerts, improving NULL/operator handling and preserving AND semantics.
    • Enhanced value typing and escaping for string patterns and booleans/numbers for more accurate filter expressions.

✏️ Tip: You can customize this high-level summary in your review settings.

1. list type fields
2. text with empty value
3. boolean fields
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2026

Walkthrough

Adds an optional column_type field to ConditionConfig and refactors alert filter construction by extracting per-condition expression builders (condition_to_expr, list_condition_expr, scalar_condition_expr), centralizing value-type parsing/formatting and LIKE escaping for SQL fragment generation. (32 words)

Changes

Cohort / File(s) Summary
Schema extension
src/alerts/alert_structs.rs
Added column_type: Option<String> to ConditionConfig with #[serde(rename = "type")] and #[serde(default)].
Filter logic refactor
src/alerts/alerts_utils.rs
Imported ConditionConfig; replaced inline per-condition handling with condition_to_expr; added list_condition_expr, scalar_condition_expr, escape_like, and internal ValueType parsing/formatting; updated get_filter_string to delegate per-condition processing and preserve AND/IsNull semantics.

Sequence Diagram(s)

(Skipped — changes are internal refactor and do not introduce a multi-component sequential flow requiring visualization.)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 A tiny type hops into play,
I split lists from scalars today,
I format, escape, and bind each clause,
Nibble errors, applaud the laws,
Hooray — filters spring from my tray!

🚥 Pre-merge checks | ❌ 3
❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is incomplete. It lacks a proper issue reference, detailed goal description, explanation of solutions chosen, and testing/documentation checklist completion. Fill in the complete description template including: issue reference (Fixes #XXXX), detailed description of the goal and rationale, key changes made, and complete the testing and documentation checklist items.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix: counts api' is vague and does not clearly describe the specific changes made to handle list fields, empty text values, or boolean fields in the counts API. Consider making the title more descriptive, such as 'fix: add support for list, text, and boolean fields in counts API' to better reflect the actual changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 28, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@src/alerts/alerts_utils.rs`:
- Around line 474-479: The escape_like function must escape backslashes before
other characters so any '\' in user input becomes a literal backslash in the
LIKE pattern; update escape_like to first replace backslashes (replace('\\',
"\\\\")) and then perform the existing replacements for single-quote, '%' and
'_' so backslashes aren't interpreted as SQL escape markers when using ESCAPE
'\'; keep the function name escape_like and the same replacement semantics
otherwise.
- Around line 458-468: The branch that formats literals when column_type is
Some("bool"/"boolean"/"int"/"float"/"number") must validate and normalize the
input instead of inserting it verbatim; update the logic around the match on
column_type to attempt parsing the provided value (e.g., call
ValueType::from_string(value.to_owned()) or use explicit parsers for
bool/number) and then format based on the parsed ValueType (Number -> unquoted
numeric, Boolean -> unquoted boolean, String -> single-quoted escaped string);
if parsing fails return or propagate an error (or treat as a quoted string)
rather than emitting invalid SQL. Ensure you modify the same match block that
currently handles Some("bool") | Some("boolean") and Some("int") | Some("float")
| Some("number") so the behavior matches the None case that uses
ValueType::from_string().
- Around line 411-423: The list_condition_expr function interpolates the raw
value into the SQL ARRAY[...] literal which can break syntax or allow injection;
modify list_condition_expr to parse the incoming value into individual items
(split on commas or use the same parsing logic used by scalar_condition_expr),
apply the same escaping/quoting routine used for scalar values (reuse the
existing scalar escaping helper or function that scalar_condition_expr uses) for
each item, then join the escaped items into the ARRAY[...] expression used in
the WhereConfigOperator branches (Contains, DoesNotContain, Equal, NotEqual) so
the generated strings are properly quoted/escaped for SQL; preserve the existing
error branch for unsupported operators.
🧹 Nitpick comments (1)
src/alerts/alerts_utils.rs (1)

394-399: Make list-type detection case-insensitive.

starts_with("list") is case-sensitive and will misclassify types like List<...> or LIST<...>. Consider normalizing the type string first.

♻️ Suggested tweak
-    let is_list_type = condition
-        .column_type
-        .as_ref()
-        .is_some_and(|t| t.starts_with("list"));
+    let is_list_type = condition
+        .column_type
+        .as_ref()
+        .map(|t| t.to_ascii_lowercase())
+        .is_some_and(|t| t.starts_with("list"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant