feat: add pattern column selector for event pattern matching on any column#2460
feat: add pattern column selector for event pattern matching on any column#2460knudtty wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: b20d0b4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
Greptile SummaryThis PR adds a column/expression selector to the Event Patterns view so users can run drain-based pattern matching against any SQL expression (not just
Confidence Score: 2/5Not safe to merge:
packages/app/src/components/Patterns/reconstructTemplate.ts — the regex constant Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User types expression\nin PatternColumnSelector] --> B[draftPatternColumn\nlocal state]
B --> C{User submits\nonSubmit}
C --> D[setPatternColumn\nURL query state]
D --> E[buildPatternColumnExpression\nwraps in toString]
E --> F[effectiveBodyValueExpression]
F --> G[useGroupedPatterns\nbodyValueExpression + queryKey]
G --> H[ClickHouse query\nfetches sample rows]
H --> I[mineEventPatterns\ndrain3 with all punctuation\nas extra delimiters]
I --> J[reconstructTemplate\nrestores separators]
J --> K[Pattern displayed\nin PatternTable]
style J fill:#f66,color:#fff
Reviews (2): Last reviewed commit: "Update packages/app/src/components/Patte..." | Re-trigger Greptile |
| if (!patternColumn) return fallback; | ||
| return `toString(${patternColumn})`; |
There was a problem hiding this comment.
buildPatternColumnExpression unconditionally wraps the user input in toString(…). If a user enters an expression that already returns a string (e.g. toString(Body)), the generated SQL becomes toString(toString(Body)). ClickHouse handles this gracefully for actual strings, but a simple guard prevents the redundant wrapping.
| if (!patternColumn) return fallback; | |
| return `toString(${patternColumn})`; | |
| if (!patternColumn) return fallback; | |
| const trimmed = patternColumn.trim(); | |
| if (/^toString\s*\(/i.test(trimmed)) return trimmed; | |
| return `toString(${trimmed})`; |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
E2E Test Results✅ All tests passed • 197 passed • 3 skipped • 1395s
Tests ran across 4 shards in parallel. |
| let tokenIdx = 0; | ||
| let match: RegExpExecArray | null; | ||
| while ((match = tokenOrSeparator.exec(normalized)) !== null) { |
There was a problem hiding this comment.
TOKEN_OR_SEPARATOR is used but never defined anywhere in this file or the codebase. The file has no imports and the grep confirms there is no definition anywhere in src/. TypeScript will refuse to compile this (Cannot find name 'TOKEN_OR_SEPARATOR') and calling .lastIndex on undefined will throw a TypeError at runtime, breaking all pattern matching. The regex /([A-Za-z0-9]+)|([^A-Za-z0-9]+)/g needs to be declared — either as a module-level constant or as a local variable inside the function before the loop.
Summary
Adds a selector to do event pattern matching on any column or expression, not just Body.
Also changes the drain tokenizer.
Drain collapses any token to a space character and then runs the drain algorithm. To make things look fine in the event patterns, I had to add some reconstruction logic.
Screenshots or video
How to test on Vercel preview
Preview routes:
Steps:
concatWithSeparator(' ', Body, LogAttributes)References